Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Diamond Casino Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

      1. Frontier Pursuits
      2. Find Lobbies & Outlaws
      3. Help & Support
    3. Crews

      1. Events
    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA 6

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

lgrahl

[V|REL] Script Hook V Python 3k

Recommended Posts

lgrahl

Script Hook V Py3k
This is an ASI plugin for Grand Theft Auto V that allows you to execute Python 3 scripts in game by using the Script Hook V from Alexander Blade.

Features

Download
Prebuilt binaries can be found on the releases page.

Installation

Writing Scripts
To get started on writing scripts, head over to this wiki page.

Contributing
All contributions are warmly welcomed. Below are a few hints to the entry points of the code and a link to our to do list.

Entry Points

  • Py3kWrapperStart in wrapper.cpp is the entry point for the C++ part of the plugin
  • _init in the gta module is the entry point for the Python part of the plugin

Todo
See TODO.md.

Building
If you want to build the ASI plugin yourself, you'll need:

  • Visual Studio 2013
  • The Script Hook V SDK which has to be extracted into /sdk after downloading
  • SWIG Version >= 3.0.5 which has to be extracted into /swig after downloading
  • Python 3.5.0 for AMD64/EM64T/x64. Using the x86 version will not work!
  • Open the project file and build the solution in Release configuration
Edited by lgrahl
  • Like 5

Share this post


Link to post
Share on other sites
Zeynohh

Sounds quite exciting ^^

Share this post


Link to post
Share on other sites
NoShotz

hehe, just happens that i am learning python, lol

Share this post


Link to post
Share on other sites
Scrumilation

Good, i like lua but i love python.

Share this post


Link to post
Share on other sites
NeatSquid

Hey,

Great work. 2 questions though.

1. Where is the ASI plugin? I can't find it in my folder that I downloaded.

2. Would this work?

 

EDIT: I know know how to compile the ASI, and I will try out my code

Edited by NeatSquid

Share this post


Link to post
Share on other sites
NeatSquid

When I launch the game, I get a ScriptHookV error saying that it couldn't load the asi.

Share this post


Link to post
Share on other sites
lgrahl

Hey,

Great work. 2 questions though.

1. Where is the ASI plugin? I can't find it in my folder that I downloaded.

2. Would this work?

 

EDIT: I know know how to compile the ASI, and I will try out my code

 

We will provide the ASI plugin as soon as the keyboard coroutine has been written.

 

When I launch the game, I get a ScriptHookV error saying that it couldn't load the asi.

 

At the moment, the required files need to be assembled by hand. You need to copy everything from the /python folder and the compiled scripthookvpy3k.asi into your GTA V directory. There will be a log file in the GTA V directory called scripthookvpy3k.log when the script loader has been initialised.

Share this post


Link to post
Share on other sites
NeatSquid

 

Hey,

Great work. 2 questions though.

1. Where is the ASI plugin? I can't find it in my folder that I downloaded.

2. Would this work?

 

EDIT: I know know how to compile the ASI, and I will try out my code

 

We will provide the ASI plugin as soon as the keyboard coroutine has been written.

 

When I launch the game, I get a ScriptHookV error saying that it couldn't load the asi.

 

At the moment, the required files need to be assembled by hand. You need to copy everything from the /python folder and the compiled scripthookvpy3k.asi into your GTA V directory. There will be a log file in the GTA V directory called scripthookvpy3k.log when the script loader has been initialised.

OK, thank you. Please @ me when you've released the final version, I've been waiting for this ever since the LUA plugin came out :) Nice work, carry it on :D Even if it's just for me :p

Share this post


Link to post
Share on other sites
lgrahl

I believe, the huge advantage we have with Python is that we can utilise all the fancy modules out there. Synchronising the current time and weather? Serving a website where other people can click on the map and spawn vehicles on top of your head? Yeah, possible. I'm sure you have even better and much more creative ideas!

 

But we don't want all the hassle of installing dependencies on the command line from readme instructions that script writers provide, right? That's why we've implemented automatic dependency installation. Script writers just need to provide some metadata in their scripts and that's it. The dependencies will be downloaded and installed automatically (using pip and pypi).

 

There are still some show stoppers we need to resolve until we're going to release the hook.

Share this post


Link to post
Share on other sites
NoShotz

this is going to be awesome when it comes out

Share this post


Link to post
Share on other sites
NeatSquid

I think I'm using an older version of the mod, but I keep getting this error

sOjZj3r.jpg?1

Share this post


Link to post
Share on other sites
lgrahl

I think I'm using an older version of the mod, but I keep getting this error [...]

 

 

We've done a lot of changes today. Now, there will be two separate logs. One for the wrapper (scripthookvpy3k.wrapper.log) and one for the Python module (scripthookvpy3k.log). Please, rebuild the plugin and paste the content of the logs here if it still doesn't work. Make sure that you delete all old Python scripts from the GTA V folder (Folders: __pycache__, gta, scripts, Files: gta_native.py). In the future, Python scripts will have their own sub folder so they don't create a mess in the GTA V folder.

Edited by lgrahl

Share this post


Link to post
Share on other sites
NeatSquid

 

I think I'm using an older version of the mod, but I keep getting this error [...]

 

We've done a lot of changes today. Now, there will be two separate logs. One for the wrapper (scripthookvpy3k.wrapper.log) and one for the Python module (scripthookvpy3k.log). Please, rebuild the plugin and paste the content of the logs here if it still doesn't work. Make sure that you delete all old Python scripts from the GTA V folder (Folders: __pycache__, gta, scripts, Files: gta_native.py). In the future, Python scripts will have their own sub folder so they don't create a mess in the GTA V folder.

OK, I'll do that tonight and report back. Does the Python folder go into the directory of GTAV or into the scripts folder btw?

Share this post


Link to post
Share on other sites
lgrahl

 

 

I think I'm using an older version of the mod, but I keep getting this error [...]

We've done a lot of changes today. Now, there will be two separate logs. One for the wrapper (scripthookvpy3k.wrapper.log) and one for the Python module (scripthookvpy3k.log). Please, rebuild the plugin and paste the content of the logs here if it still doesn't work. Make sure that you delete all old Python scripts from the GTA V folder (Folders: __pycache__, gta, scripts, Files: gta_native.py). In the future, Python scripts will have their own sub folder so they don't create a mess in the GTA V folder.

OK, I'll do that tonight and report back. Does the Python folder go into the directory of GTAV or into the scripts folder btw?

 

 

Currently, all content from the python folder goes into the directory of GTA V. Otherwise, you'll get an error in the log.

Share this post


Link to post
Share on other sites
CryptXor

Oh snap. Now this is something that I am going to get into. Is there a TODO list?

Share this post


Link to post
Share on other sites
NeatSquid

Compiling the latest version :) I now have a copy of this at school so I can script at school when I'm bored :p

Edited by NeatSquid

Share this post


Link to post
Share on other sites
NeatSquid

I still can't get it working. Maybe I'm scripting it wrong. The plugin works, but I can't script for my life :p

 

 

import asyncioimport gta_nativeimport [email protected] main():    wanted_level = gta_native.player.get_player_wanted_level(player)    if wanted_level > 2:        gta_native.player.set_player_wanted_level(player, 0, True)

Share this post


Link to post
Share on other sites
lgrahl

 

I still can't get it working. Maybe I'm scripting it wrong. The plugin works, but I can't script for my life :p

import asyncioimport gta_nativeimport [email protected] main():    wanted_level = gta_native.player.get_player_wanted_level(player)    if wanted_level > 2:        gta_native.player.set_player_wanted_level(player, 0, True)

 

You, sir, just found a bug. ;) Exceptions from scripts have not been logged until now.

 

But when you rebuild the ASI plugin and run the game with the script you've posted, check out the exceptions in the scripthookvpy3k.log for troubleshooting. It will tell you that player is not defined.

2015-05-16 00:21:12 gta                    ERROR              Script "neatsquid" returned with an exceptionTraceback (most recent call last):  File "C:\Python34\Lib\asyncio\tasks.py", line 238, in _step    result = next(coro)  File "C:\Python34\Lib\asyncio\coroutines.py", line 141, in coro    res = func(*args, **kw)  File "D:\Games\GTA V\scripts\neatsquid.py", line 7, in main    wanted_level = gta_native.player.get_player_wanted_level(player)NameError: name 'player' is not definedThe above exception was the direct cause of the following exception:Traceback (most recent call last):  File "D:\Games\GTA V\gta\__init__.py", line 268, in _script_done    raise ScriptExecutionError(name) from exc

Also, as a side note: @asyncio.coroutine is a decorator for the main function and there should be no blank line between them. I highly recommend using PyCharm for coding which will tell you these kinds of things (and much more).

 

Please, note that the ASI plugin currently cannot be reloaded at runtime. So, press F12 if you want to reload your script(s) without having to close GTA V.

Share this post


Link to post
Share on other sites
NeatSquid

 

I still can't get it working. Maybe I'm scripting it wrong. The plugin works, but I can't script for my life :p

import asyncioimport gta_nativeimport [email protected] main():    wanted_level = gta_native.player.get_player_wanted_level(player)    if wanted_level > 2:        gta_native.player.set_player_wanted_level(player, 0, True)

You, sir, just found a bug. ;) Exceptions from scripts have not been logged until now.

 

But when you rebuild the ASI plugin and run the game with the script you've posted, check out the exceptions in the scripthookvpy3k.log for troubleshooting. It will tell you that player is not defined.

 

2015-05-16 00:21:12 gta                    ERROR              Script "neatsquid" returned with an exceptionTraceback (most recent call last):  File "C:\Python34\Lib\asyncio\tasks.py", line 238, in _step    result = next(coro)  File "C:\Python34\Lib\asyncio\coroutines.py", line 141, in coro    res = func(*args, **kw)  File "D:\Games\GTA V\scripts\neatsquid.py", line 7, in main    wanted_level = gta_native.player.get_player_wanted_level(player)NameError: name 'player' is not definedThe above exception was the direct cause of the following exception:Traceback (most recent call last):  File "D:\Games\GTA V\gta\__init__.py", line 268, in _script_done    raise ScriptExecutionError(name) from exc
Also, as a side note: @asyncio.coroutine is a decorator for the main function and there should be no blank line between them. I highly recommend using PyCharm for coding which will tell you these kinds of things (and much more).

 

Please, note that the ASI plugin currently cannot be reloaded at runtime. So, press F12 if you want to reload your script(s) without having to close GTA V.

Thank you terribly :D For some reason, F12 crashses the game for me, so I'll probably just remove the Rockstar intro for quicker access.

Edited by NeatSquid

Share this post


Link to post
Share on other sites
lgrahl
It took a while to clean up the C++ part and to make sure that all potential errors are being catched and logged. There should be no crashes anymore. If you experience a crash, please post both log files (scripthookvpy3k.log, scripthookvpy3k.wrapper.log) here.


There are still two big show stoppers (see issue #4 and #6). We really could use some help here to research whats going wrong. For now, the game executable will not stop after exiting and you'll need to kill the process in the task manager. The mentioned two issues need to be resolved and the keyboard co-routine still needs to be written until we are ready to release.


Changes:

  • All Python scripts now reside in a "python" sub folder
  • You can use DEL to stop Python (F12 will restart Python)
  • Logging has been massively improved
  • Bug fixes... lots of 'em

Also, there is a new script example that applies the current weather of Los Angeles to the game.

Edited by lgrahl

Share this post


Link to post
Share on other sites
NeatSquid

Updated. Thanks bro :)

Share this post


Link to post
Share on other sites
headscript

will this be continued or is abandoned?(i wanna make my hands dirty)

Share this post


Link to post
Share on other sites
Szabo

will this be continued or is abandoned?(i wanna make my hands dirty)

headscript you traitor! :lol:

 

A python 3 plugin for scripthook would be awesome since python has the batteries included and the performance is just enough. Perhaps you guys could use pypy for even better performance though.

 

I wish I had the time to mod the hell outta V.

Share this post


Link to post
Share on other sites
headscript

 

will this be continued or is abandoned?(i wanna make my hands dirty)

headscript you traitor! :lol:

 

A python 3 plugin for scripthook would be awesome since python has the batteries included and the performance is just enough. Perhaps you guys could use pypy for even better performance though.

 

I wish I had the time to mod the hell outta V.

 

not being a traitor i just want to integrate it in mine^^(pacman)

Share this post


Link to post
Share on other sites
lgrahl

will this be continued or is abandoned?(i wanna make my hands dirty)

 

Definitely not abandoned. After all, we are students and just tend to be (more) busy from time to time. ;) If you want to make your hands dirty, feel free to join us and make a few pull requests. We have a to do list and some open issues.

 

 

will this be continued or is abandoned?(i wanna make my hands dirty)

headscript you traitor! :lol:

 

A python 3 plugin for scripthook would be awesome since python has the batteries included and the performance is just enough. Perhaps you guys could use pypy for even better performance though.

 

I wish I had the time to mod the hell outta V.

 

 

Well, it already works fine and you can go ahead and do some scripting (after you've compiled the plugin). All native functions are available. We just need some higher level modules.

 

I doubt that performance will be a problem. Still, you are correct that PyPy could probably be used as an alternative (as soon as it ships with Python 3.4 support).

 

If you want to get started, just let me know and I'll post a sort-of-alpha version of the plugin.

Edited by lgrahl

Share this post


Link to post
Share on other sites
headscript

 

will this be continued or is abandoned?(i wanna make my hands dirty)

 

Definitely not abandoned. After all, we are students and just tend to be (more) busy from time to time. ;) If you want to make your hands dirty, feel free to join us and make a few pull requests. We have a to do list and some open issues.

 

i kinda wanted to rewrite it from scratch using boost python, a AST parser and Python 2.7 with Cython

Share this post


Link to post
Share on other sites
Szabo

 

will this be continued or is abandoned?(i wanna make my hands dirty)

 

Definitely not abandoned. After all, we are students and just tend to be (more) busy from time to time. ;) If you want to make your hands dirty, feel free to join us and make a few pull requests. We have a to do list and some open issues.

 

 

will this be continued or is abandoned?(i wanna make my hands dirty)

headscript you traitor! :lol:

 

A python 3 plugin for scripthook would be awesome since python has the batteries included and the performance is just enough. Perhaps you guys could use pypy for even better performance though.

 

I wish I had the time to mod the hell outta V.

 

 

Well, it already works fine and you can go ahead and do some scripting (after you've compiled the plugin). All native functions are available. We just need some higher level modules.

 

I doubt that performance will be a problem. Still, you are correct that PyPy could probably be used as an alternative (as soon as it ships with Python 3.4 support).

 

If you want to get started, just let me know and I'll post a sort-of-alpha version of the plugin.

 

At the moment I'm still struggling to find the time for the mod I'm programming in Lua atm, I'm hitting a thick wall of engine limitations though. The hardest part is workarounding them.

 

 

 

will this be continued or is abandoned?(i wanna make my hands dirty)

 

Definitely not abandoned. After all, we are students and just tend to be (more) busy from time to time. ;) If you want to make your hands dirty, feel free to join us and make a few pull requests. We have a to do list and some open issues.

 

i kinda wanted to rewrite it from scratch using boost python, a AST parser and Python 2.7 with Cython

 

Good ole Cython... I still consider it the bestest language ever, you can use pretty much pure python most of the time and when you really need the extra performance you can just define some c types and BOOM! C-like performance :). It lacks some good performance tools though and surely it lacks the popularity. It's the biggest aberration I've ever seen in terms of something not getting the popularity it deserves. People complain a lot that python doesn't compile the code nor obfuscates it somehow, but I've managed to compile an entire PyQt4 program with Cython and it worked outta the box. The performance of course was a little bit worse than Cpython because I didn't change a single line of code, but the level of 'obfuscation' is pretty good I'd say. Surely no one is going to be able to retrieve something that resembles the python source without sh*tloads of work. Personally I don't care about obfuscation, but according to google that's one of the most discussed topics. If you have an enterprise-level program and need some top secret stuff obfuscated, the only thing you can do to protect it (although not 100%) is running that on your own server.

Share this post


Link to post
Share on other sites
iFarbod

Sounds awesome, I'll be using this for sure.

Share this post


Link to post
Share on other sites
lgrahl

i kinda wanted to rewrite it from scratch using boost python, a AST parser and Python 2.7 with Cython

 

I respect your enthusiasm, but what would we gain from this approach?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.