Quantcast

Jump to content

» «
Photo

[V|REL] Script Hook V Python 3k

V Released
49 replies to this topic
lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#1

Posted 11 May 2015 - 12:49 AM Edited by lgrahl, 08 November 2015 - 02:40 PM.

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
  • indirivacua, Metalz, Zeynohh and 2 others like this

Zeynohh
  • Zeynohh

    Rat

  • Members
  • Joined: 16 Nov 2014
  • Canada

#2

Posted 11 May 2015 - 01:09 AM

Sounds quite exciting ^^


NoShotz
  • NoShotz

    Player Hater

  • Members
  • Joined: 25 Apr 2015
  • Canada

#3

Posted 11 May 2015 - 02:12 PM

hehe, just happens that i am learning python, lol


Scrumilation
  • Scrumilation

    Player Hater

  • New Members
  • Joined: 21 Feb 2015
  • Brazil

#4

Posted 12 May 2015 - 03:10 AM

Good, i like lua but i love python.


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#5

Posted 13 May 2015 - 07:43 PM Edited by NeatSquid, 13 May 2015 - 07:54 PM.

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


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#6

Posted 13 May 2015 - 07:55 PM

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


lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#7

Posted 14 May 2015 - 03:12 AM

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.


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#8

Posted 14 May 2015 - 06:37 AM

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

lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#9

Posted 14 May 2015 - 07:15 PM

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.


NoShotz
  • NoShotz

    Player Hater

  • Members
  • Joined: 25 Apr 2015
  • Canada

#10

Posted 14 May 2015 - 07:18 PM

this is going to be awesome when it comes out


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#11

Posted 14 May 2015 - 07:45 PM

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

sOjZj3r.jpg?1


lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#12

Posted 15 May 2015 - 02:32 AM Edited by lgrahl, 15 May 2015 - 02:33 AM.

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.


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#13

Posted 15 May 2015 - 06:33 AM

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?

lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#14

Posted 15 May 2015 - 02:30 PM

 

 

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.


CryptXor
  • CryptXor

    Player Hater

  • Members
  • Joined: 29 Apr 2015
  • Malta

#15

Posted 15 May 2015 - 03:07 PM

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


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#16

Posted 15 May 2015 - 04:54 PM

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

Indeed.

 

https://github.com/l.../master/TODO.md


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#17

Posted 15 May 2015 - 07:24 PM Edited by NeatSquid, 15 May 2015 - 07:25 PM.

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


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#18

Posted 15 May 2015 - 07:53 PM

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 asyncio
import gta_native
import gta.utils

@asyncio.coroutine

def 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)

lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#19

Posted 15 May 2015 - 10:31 PM

 

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 asyncio
import gta_native
import gta.utils

@asyncio.coroutine

def 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 exception
Traceback (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 defined

The 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.


NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#20

Posted 16 May 2015 - 06:45 AM Edited by NeatSquid, 16 May 2015 - 07:30 AM.

 

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 asyncio
import gta_native
import gta.utils

@asyncio.coroutine

def 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 exception
Traceback (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 defined

The 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.


lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#21

Posted 18 May 2015 - 10:25 AM Edited by lgrahl, 18 May 2015 - 10:26 AM.

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.

NeatSquid
  • NeatSquid

    Crackhead

  • Members
  • Joined: 09 Nov 2014
  • United-Kingdom

#22

Posted 18 May 2015 - 05:26 PM

Updated. Thanks bro :)


headscript
  • headscript

    Punk-ass Bitch

  • Members
  • Joined: 15 Apr 2015
  • Germany

#23

Posted 30 May 2015 - 08:31 PM

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


Szabo
  • Szabo

    Rat

  • Members
  • Joined: 22 Apr 2015
  • None

#24

Posted 31 May 2015 - 12:00 AM

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.


headscript
  • headscript

    Punk-ass Bitch

  • Members
  • Joined: 15 Apr 2015
  • Germany

#25

Posted 31 May 2015 - 12:41 AM

 

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) 


lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#26

Posted 31 May 2015 - 03:33 PM Edited by lgrahl, 31 May 2015 - 03:38 PM.

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.


headscript
  • headscript

    Punk-ass Bitch

  • Members
  • Joined: 15 Apr 2015
  • Germany

#27

Posted 31 May 2015 - 04:35 PM

 

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


Szabo
  • Szabo

    Rat

  • Members
  • Joined: 22 Apr 2015
  • None

#28

Posted 31 May 2015 - 04:53 PM

 

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.


iFarbod
  • iFarbod

    🍂™

  • Members
  • Joined: 17 Dec 2013
  • Unknown

#29

Posted 31 May 2015 - 07:27 PM

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


lgrahl
  • lgrahl

    Player Hater

  • Members
  • Joined: 11 May 2015
  • Germany

#30

Posted 31 May 2015 - 10:01 PM

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?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users