Jump to content

GTALua - Script Engine in Lua


Recommended Posts

Image.png

GTALua - A Powerful Scripting Engine for GTA V in Lua

Current Features

  • NEW Timers
  • NEW Events (OnPedCreated, OnVehicleCreated)
  • NEW Object-Oriented Wrappers for natives (+ Documentation & lots of examples)
  • NEW Flexible/Simple GUI-module
  • All 5300 Natives accessible in Lua
  • Console that contains error messages and has support for own commands
  • Good Documentation to get you started with GTALua (Wiki & Tutorials & Examples)
  • Load/Reload/Unload your scripts with a simple command in the console while ingame
  • Intro movie skipper

Planned Features

  • Automatic Refresh (instead of current manual method)
  • Script Database (maybe)

Scripting Documentation
Make sure to check out the examples, you can find them in GTALua/addons/
We also have a wiki, you can find a tutorial and other things there! Check it out

Not convinced?


Less code, same result
Both scripts do exactly the same, but the left one is way easier and cleaner.
not_convinced_1.png

Menus
simple_menu_example.png
Check out: gui.SimpleMenu



Changelog
NEW Current Version: 1.1.0 (Alpha)

  • Added Timers
  • Added Events (OnPedCreated, OnVehicleCreated)
  • Added ScriptThread:Tick
  • Added lots of more wrappers for Blips & ui.CreateBlip
  • Added gtalua.ini (contains configuration for console)
  • Improved gui.SimpleMenu
  • Improved error handling for ScriptThread:Run
  • Fixed print
  • Fixed Vector:Distance
  • Fixed Entity:GetOffsetVector, Entity:SetVelocity (with Vector as parameter)

 


Version: 1.1.0 (Alpha)

  • Added (more than 80) Object-Oriented Wrappers for the natives (+ Documentation with lots examples)
  • Added GUI module to easily create menus
  • Added support for OUT-parameters
  • Addons can now be loaded/unloaded at any time
  • Script-Threads now run on one main thread (without blocking each other, using coroutines)
  • Huge documentation with new tutorials & examples

Check out the updated Tutorials! Getting Started

Version: 1.0.1 (Alpha)

  • Updated to work with 1.0.350.1/2
  • Removed leftover debug messages
  • Updated native call layouts for animations (thanks gcWorld!)
  • Note: With this update you'll have to overwrite dinput8!

Version 1.0.0 (Alpha)

  • Initial Version
  • Supported Game Versions: Steam/Retail 1.0.335.2

 



Installation
Download
Click here if you need further help! Or take a look at the Spoiler below.

Support + Getting Started as Developer

Wiki
The wiki contains Tutorials and a useful Getting Started page!

Examples
You can find several examples in GTALua/addons/

IRC
If you have any questions, you can ask here or join the GTANet IRC!
Host: irc.gtanet.com
Port: 6667
Just send me a message (Freaky) or join #gtalua or #gtamodding

Here / PM
If you have any questions, feel free to ask them here or via PM.

 

Edited by TJGM
Link to comment
https://gtaforums.com/topic/790179-gtalua-script-engine-in-lua/
Share on other sites

Image.png

 

GTALua - A Powerful Scripting Engine for GTA V in Lua

 

Current Features

  • All 5300 Natives accessible in Lua
  • Console that contains error messages and has support for own commands
  • Good Documentation to get you started with GTALua (Wiki & Tutorials & Examples)
  • Reload your scripts with a simple command in the console while ingame

Planned Features

  • Automatic Refresh (instead of current manual method)
  • Helper functions & classes for the natives
  • Adding even more examples
  • Drawing functions & library
  • Script Database (maybe)

Scripting Documentation

Make sure to check out the examples, you can find them in GTALua/addons/

We also have a wiki, you can find a tutorial and other things there! Check it out

 

Changelog

Current Version: 1.0.0 (Alpha)

  • Initial Version
  • Supported Game Versions: Steam/Retail 1.0.335.2

Installation

Download

Click here if you need further help! Or take a look at the Spoiler below.

 

Support + Getting Started as Developer

 

Wiki

The wiki contains Tutorials and a useful Getting Started page!

 

Examples

You can find several examples in GTALua/addons/

 

IRC

If you have any questions, you can ask here or join the GTANet IRC!

Host: irc.gtanet.com

Port: 6667

Just send me a message (Freaky) or join #gtamodding

 

Here / PM

If you have any questions, feel free to ask them here or via PM.

 

 

where is the benefit from yours compared to mine?

where is the benefit from yours compared to mine?

 

I have proper documentation (wiki, tutorial, examples), a much easier addons-system, each script has its own script thread so people are free to do what they want, my code is well-structured, documented and optimized (that's why my files aren't nearly 3mb).

 

Also please do me a favour and remove the quote, it takes away loads of space.

Edited by Freakyy
  • Like 2

Excellent. Though dumb question where can i find the model hash of peds and vehicles, things like that ?

 

Reading through the example scripts, you call the models by hash, just wondering where i can find the said hash to spawn whatever i want. Thanks.

Edited by Drkz

Excellent. Though dumb question where can i find the model hash of peds and vehicles, things like that ?

 

Not a dumb question at all :)

 

They are everywhere around the internet.

I will add a list of them on the Wiki later.

Edited by Freakyy
SgtDirtyMike

I commend your work on this release, but you must agree it is redundant. The other solution is much simpler to use, and whilst it's true that it may not provide as much functionality, yours is more cluttered and less organized. No one cares about a few megabytes...

Why not contact headscript first and suggest ideas instead of using his idea to make a more complicated release?

I commend your work on this release, but you must agree it is redundant. The other solution is much simpler to use, and whilst it's true that it may not provide as much functionality, yours is more cluttered and less organized. No one cares about a few megabytes...

 

Why not contact headscript first and suggest ideas instead of using his idea to make a more complicated release?

 

More cluttered and less organized? I appreciate the feedback, i really do, but that's not true. What are you referring to?

I have a proper file structure with comments, an addon-system, in C++ I'm using classes and I also tried to port object-oriented-programming as good as possible over to Lua. The fact that you need to create your own script thread might be a complication, but it's 5-7 lines. It has the advantage that you are free to do what you want - you never conflict with other scripts, you don't block other scripts if you have an error, etc.

And the fact that it's smaller is not even an important fact, it's the optimization and performance.

By the way, if you want to be exact, the work on GTALua began before he released his - he was just the first to release :)

Edited by Freakyy
  • Like 2

 

And the fact that it's smaller is not even an important fact, it's the optimization and performance.

show me your performance against mine :)

im totally raw on the natives nothing blocking or changing everything is 100% direct

http://pastebin.com/6zkg8Had

 

 

And the fact that it's smaller is not even an important fact, it's the optimization and performance.

show me your performance against mine :)

im totally raw on the natives nothing blocking or changing everything is 100% direct

http://pastebin.com/6zkg8Had

 

 

We have a totally different approach of calling natives.

In my code, the arguments are pushed and the native called completely in Lua, whereas you registered a function for every native.

 

 

 

And the fact that it's smaller is not even an important fact, it's the optimization and performance.

show me your performance against mine :)

im totally raw on the natives nothing blocking or changing everything is 100% direct

http://pastebin.com/6zkg8Had

 

 

We have a totally different approach of calling natives.

In my code, the arguments are pushed and the native called completely in Lua, whereas you registered a function for every native.

 

which is faster? you cant tell me that calling 1 + n(each variable which u push to natives) functions from lua to c++ is faster than one lua to c+ +

OP, I have a question for ya.

 

I'd like to call GET_PED_NEARBY_PEDS, which takes an array pointer as a parameter. I tried passing a table, but it complained about wanting a "number" (pointer, of course).

 

Do you know how I can call that function from Lua properly?

which is faster? you cant tell me that calling 1 + n(each variable which u push to natives) functions from lua to c++ is faster than one lua to c+ +

It might not be faster than your approach, but it is definetly more clean. The reason I have that method in the first place is because of the natives/native_call_layout.ini file - people are able to change the parameters there, add undocumented natives. However, I'll do some benchmarking to find some actual numbers.

 

Edit: I just read through the last replies, people reported that they couldn't set the name plate correctly. In my case they would just have to edit the native_call_layou.ini, change the parameter type to string and then it would work. This is one of the main reasons why I chose this method. Maybe at a later point, when all natives have been analyzed, I will switch over.

 

 

OP, I have a question for ya.

 

I'd like to call GET_PED_NEARBY_PEDS, which takes an array pointer as a parameter. I tried passing a table, but it complained about wanting a "number" (pointer, of course).

 

Do you know how I can call that function from Lua properly?

It's not possible, I'll add this ASAP.

 

 

Nice. Looks like you put some effort, but i hope you plan on abstracting the natives 'cause if not i don't see the point. (might as well be using the C++ hook directly)

Thank you. You're absolutely right. It's exactly what I'm planning.

Although one advantage over the C version is that you don't have to restart your game :):D

Edited by Freakyy

More isn't always better, buuuuuuuut, people who wanna go "balls-deep" in messing about w/ Lua should definitely check this out. Otherwise, the version headscript released suffices just fine. Nonetheless, nice release OP, looks like a fair amount of effort was put forth into this, so... kudos there. :lol:

Edited by V7X3

More isn't always better, buuuuuuuut, people who wanna go "balls-deep" in messing about w/ Lua should definitely check this out. Otherwise, the version headscript released suffices just fine. Nonetheless, nice release OP, looks like a fair amount of effort was put forth into this, so... kudos there. :lol:

Thanks for the feedback!

But more means more possibilities ;)

The next version will include the following changes:

  • KEY_ constants (like KEY_F9 for example)
  • Support for OUT-values (like arrays)
  • Minor bug fixes and code cleanup

The most exciting new feature will be the wrappers, here is a quick example: (do not try to use this on the current version)

streaming.RequestAndWaitForModel("cs_priest")
local bodyguard = game.CreatePed("cs_priest", LocalPlayer():GetPosition())
bodyguard:AllowWeaponSwitching()
bodyguard:DelayedGiveWeapon("WEAPON_PISTOL")


Any suggestions or wishes for the next update?

Awesome updates there!

 

One other request I have is support for controller key constants and/or a wrapper for doing controller key presses. I know there's functionality for detecting gamepad presses in the natives, but the button codes aren't obvious.

Edited by n00854180t

Awesome updates there!

 

One other request I have is support for controller key constants and/or a wrapper for doing controller key presses. I know there's functionality for detecting gamepad presses in the natives, but the button codes aren't obvious.

Added to my To-Do List!

Thanks for the suggestion.

 

Awesome updates there!

 

One other request I have is support for controller key constants and/or a wrapper for doing controller key presses. I know there's functionality for detecting gamepad presses in the natives, but the button codes aren't obvious.

Added to my To-Do List!

Thanks for the suggestion.

 

 

My suggestion is to keep the names of warped methods similar to .NET or C++ framework as much as possible and with a readable form.

 

Regards,

Edited by alexslx

can you guys give me a good example?

example_addon = ScriptThread("example_addon_script_thread")example_addon:Register()function example_addon:Run()while self:IsRunning() do-- Set time-- 08:00:00natives.TIME.SET_CLOCK_TIME(8, 0, 0)-- Waitself:Wait(50)endend

this is what I understand from the example in the tutorial but I am not sure its 100% accurate?

ivy_bodyguard = ScriptThread("ivy_bodyguard") function ivy_bodyguard:Run()    print("test")	while self:IsRunning() do		if IsKeyDown(0x78) then            print("test2")        end		self:Wait(50)	endendfunction ivy_bodyguard:OnError()	print("Oh no! Example Thread caused an error!")	self:Reset()end ivy_bodyguard:Register()

Literally cannot get this to register the second "test2" in the console. I don't know if key presses are broken... it just does not work for me. Maybe you have some information on the subject.

ivy_bodyguard = ScriptThread("ivy_bodyguard") function ivy_bodyguard:Run()    print("test")	while self:IsRunning() do		if IsKeyDown(0x78) then            print("test2")        end		self:Wait(50)	endendfunction ivy_bodyguard:OnError()	print("Oh no! Example Thread caused an error!")	self:Reset()end ivy_bodyguard:Register()

Literally cannot get this to register the second "test2" in the console. I don't know if key presses are broken... it just does not work for me. Maybe you have some information on the subject.

 

I cannot get it register any keypresses either.

I've sent you a commit with my vehicle const list, just to save you a bit of work.

 

Also, as a suggestion, I think you should follow a standard documentation format such as javadoc (even it is made to use with java, I worked with a huge amount of project using it for other languages). In addition, don't let to document after (You'll never do it), and commenting the code will make easier to run a doc gen tool and generate a pretty api or docs page.

 

Regards,

Cylonsurfer

So I'm trying to create a script to move various parts of the HUD so they are usable in VR. I assume I need to use SET_HUD_COMPONENT_POSITION but all I get returned in the console window is:

 

SET_HUD_COMPONENT_POSITION(a nil value)

 

Could someone give me an example of where I'm going wrong? I want to start by moving the radar for example. This is what I tried - and it's clearly wrong.

 

example_addon = ScriptThread("example_addon_script_thread")

function example_addon:Run()

while self:IsRunning() do

SET_HUD_COMPONENT_POSITION(RADAR, 1.0, 1.0)

end

end

example_addon:Register()

can you guys give me a good example?

example_addon = ScriptThread("example_addon_script_thread")example_addon:Register()function example_addon:Run()while self:IsRunning() do-- Set time-- 08:00:00natives.TIME.SET_CLOCK_TIME(8, 0, 0)-- Waitself:Wait(50)endend

this is what I understand from the example in the tutorial but I am not sure its 100% accurate?

 

You forgot to register the thread.

Put example_addon:Register() at the end of the file.

 

 

ivy_bodyguard = ScriptThread("ivy_bodyguard") function ivy_bodyguard:Run()    print("test")	while self:IsRunning() do		if IsKeyDown(0x78) then            print("test2")        end		self:Wait(50)	endendfunction ivy_bodyguard:OnError()	print("Oh no! Example Thread caused an error!")	self:Reset()end ivy_bodyguard:Register()

Literally cannot get this to register the second "test2" in the console. I don't know if key presses are broken... it just does not work for me. Maybe you have some information on the subject.

 

I cannot get it register any keypresses either.

 

 

Okay, I will look into this.

Could you post your code too? Or join IRC / send me a PM?

 

I've sent you a commit with my vehicle const list, just to save you a bit of work.

 

Also, as a suggestion, I think you should follow a standard documentation format such as javadoc (even it is made to use with java, I worked with a huge amount of project using it for other languages). In addition, don't let to document after (You'll never do it), and commenting the code will make easier to run a doc gen tool and generate a pretty api or docs page.

 

Regards,

 

I already wrote it in the comment on Github, but thanks a lot men!

I really appreciate the help, I will merge the commit later today.

(I'm also glad you followed my "style" like with the KEY_ consts)

 

That's a good idea, you know any specific ones for Lua?

 

So I'm trying to create a script to move various parts of the HUD so they are usable in VR. I assume I need to use SET_HUD_COMPONENT_POSITION but all I get returned in the console window is:

 

SET_HUD_COMPONENT_POSITION(a nil value)

 

Could someone give me an example of where I'm going wrong? I want to start by moving the radar for example. This is what I tried - and it's clearly wrong.

 

example_addon = ScriptThread("example_addon_script_thread")

 

function example_addon:Run()

 

while self:IsRunning() do

 

SET_HUD_COMPONENT_POSITION(RADAR, 1.0, 1.0)

 

end

 

end

 

example_addon:Register()

 

I responded to your PM with the solution :)

SirGoodSmoke

Great work with this. Have an issue tho not sure if its me, I can't seem to execute scripts that are loaded after the first script. Example: Using bothing your example scripts, If both of them load I can only execute the one that loaded first. Hope this makes sense

 

In the console it will show that both scripts have registered but only the first registered script will allow me to execute it

Edited by SirGoodSmoke

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

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