Jump to content

[V|REL|HOOK] LUA Plugin for Script Hook V


headscript

Recommended Posts

Chumillas

Could someone help me with this code? I am a total noob and trying to create a simple script to save and load the player position.

Other LUA scripts work but this just doesnt do anything.

Is there a log file?

 

 

Move "local player_position = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player, 0.0, 0.0, 1.0)" inside .tick function

Replace your "elseif save_pressed then" with "else" and "elseif load_pressed then" with "else"

Link to comment
Share on other sites

 


Could someone help me with this code? I am a total noob and trying to create a simple script to save and load the player position.

Other LUA scripts work but this just doesnt do anything.

Is there a log file?

 

 

Move "local player_position = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player, 0.0, 0.0, 1.0)" inside .tick function

Replace your "elseif save_pressed then" with "else" and "elseif load_pressed then" with "else"

 

Thank you. I am not sure if i get this right.. wouldnt that save the position with every tick? it should only save if i press a key and then teleport me to that position if i press an other key.

 

Could someone help me with this code? I am a total noob and trying to create a simple script to save and load the player position.

Other LUA scripts work but this just doesnt do anything.

Is there a log file?

 

 

no logfile but errors come up in the console

also you should get the playersposition every tick / or before you save it as i just see

 

Thank you. I can see that a console opens, but it gets closed immediately. Is that a bug?

Link to comment
Share on other sites

headscript

 

 


Could someone help me with this code? I am a total noob and trying to create a simple script to save and load the player position.

Other LUA scripts work but this just doesnt do anything.

Is there a log file?

 

 

Move "local player_position = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player, 0.0, 0.0, 1.0)" inside .tick function

Replace your "elseif save_pressed then" with "else" and "elseif load_pressed then" with "else"

 

Thank you. I am not sure if i get this right.. wouldnt that save the position with every tick? it should only save if i press a key and then teleport me to that position if i press an other key.

 

Could someone help me with this code? I am a total noob and trying to create a simple script to save and load the player position.

Other LUA scripts work but this just doesnt do anything.

Is there a log file?

 

 

no logfile but errors come up in the console

also you should get the playersposition every tick / or before you save it as i just see

 

Thank you. I can see that a console opens, but it gets closed immediately. Is that a bug?

 

then u have installed LUA.asi you have to install LUA SDK.asi instead

Link to comment
Share on other sites

Thanks!

 

Now everything works. :)

local tele_key = {}local save_pressed=falselocal load_pressed=falsefunction tele_key.unload()endfunction tele_key.init()endfunction tele_key.tick()local player = PLAYER.PLAYER_PED_ID()local player_position = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player, 0, 0, 1)	if(get_key_pressed(Keys.B))then		save_pressed = true	elseif save_pressed then		save_pressed=false		saved_position = player_position	end	if(get_key_pressed(Keys.N))then		load_pressed = true	elseif load_pressed then		load_pressed=false		ENTITY.SET_ENTITY_COORDS_NO_OFFSET(player, saved_position.x, saved_position.y, saved_position.z, false, false, true);	end	endreturn tele_key
Link to comment
Share on other sites

headscript

 

Thanks!

 

Now everything works. :)

local tele_key = {}local save_pressed=falselocal load_pressed=falsefunction tele_key.unload()endfunction tele_key.init()endfunction tele_key.tick()local player = PLAYER.PLAYER_PED_ID()local player_position = ENTITY.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player, 0, 0, 1)	if(get_key_pressed(Keys.B))then		save_pressed = true	elseif save_pressed then		save_pressed=false		saved_position = player_position	end	if(get_key_pressed(Keys.N))then		load_pressed = true	elseif load_pressed then		load_pressed=false		ENTITY.SET_ENTITY_COORDS_NO_OFFSET(player, saved_position.x, saved_position.y, saved_position.z, false, false, true);	end	endreturn tele_key

saved_position

you should declare it as local else its global accesible and can cause bugs

Link to comment
Share on other sites

saved_position

you should declare it as local else its global accesible and can cause bugs

I took some time to understand scoping in lua. That's too bad design imho. Implicit globals, along with first '1' indexes, are by far some of the worst design decisions I've ever seen. And I though I'd never hate a language more than Java :p.

 

They say someday Javascript will surpass Lua as an 'easily integrable, high-performance scripting language'. I'm really looking forward to it.

Link to comment
Share on other sites

headscript

 

saved_position

you should declare it as local else its global accesible and can cause bugs

I took some time to understand scoping in lua. That's too bad design imho. Implicit globals, along with first '1' indexes, are by far some of the worst design decisions I've ever seen. And I though I'd never hate a language more than Java :p.

 

They say someday Javascript will surpass Lua as an 'easily integrable, high-performance scripting language'. I'm really looking forward to it.

 

and i hate javascript ^^ but still Javascript is one of the main languages i develop in

edit: javascript is also global without var so its almost the same

Edited by headscript
Link to comment
Share on other sites

 

 

saved_position

you should declare it as local else its global accesible and can cause bugs

I took some time to understand scoping in lua. That's too bad design imho. Implicit globals, along with first '1' indexes, are by far some of the worst design decisions I've ever seen. And I though I'd never hate a language more than Java :p.

 

They say someday Javascript will surpass Lua as an 'easily integrable, high-performance scripting language'. I'm really looking forward to it.

 

and i hate javascript ^^ but still Javascript is one of the main languages i develop in

edit: javascript is also global without var so its almost the same

 

Yeah, I've developed a lot of games in Unityscript (which is a kinda javascript) and I don't love it too, but 'var' never annoyed me as much as 'local' :). Still, it's surely a painful language. To tell the truth, the only languages I really enjoyed were python(/cython) and c# (and qbasic back in childhood days :p ).

 

The question is which one you hate less... I hate when lua pops an error because I closed a function with a curly brace lol. Or when I spend a lot of time figuring out what's wrong only to discover it was the 1=0 index nonsense.

 

I think part of the problem is that I've never used lua (I used to mod the lua files from Far Cry 1 and made some simple mods for Cortex Command, but that's all, I've never really used it extensively)

 

ON_TOPIC:

Hey guys, is VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX working for you? I couldn't get it working here. No error and no effect.

Edited by Szabo
Link to comment
Share on other sites

headscript

Gonna test it when I'm home

 

yep cant work with the current version of my lua plugin the native is f*cked up -.-

Edited by headscript
Link to comment
Share on other sites

Are there any wikis? I have a tutorial (Tiny) I would like to share (It could come in very handy).

 

LUA developers, well, any developer knows the struggle of putting everything in one file, and prefer multiple-file setups supporting variable declarations per-file. After a little bit of puzzling I found a solution (Needs to expand to Linux and Mac, please someone cover that. It has to do getting the GTA V directory). Anyway, to load a file you can either make the whole file a table (Like the plugin loader does), or you can execute the function in your file. That will load all the functions in the lua enviroment. In order to do that we can use:

dofile( string path )

The path is located in the computer, meaning we need to put a path to the Grand Theft Auto library. Fortunately we can do that by running a command in the command prompt enviroment using this function:

gta_dir = io.popen("cd"):read('*l')

It will get the root folder of Grand Theft Auto V. Fortunately the lua plugin runs the enviroment at the root folder, which is why this works. Lastly, we need to make ourselves a folder in the GTA V folder. Preferably in the scripts folder, but not in the addins or libs folder. Why? Because the LUA plugin loader will try to load the folder/file and register the part of your plugin/mod as a real mod, which is the last thing we want.

 

End-result:

local GTA_V_dir = io.popen("cd"):read('*l') -- Get the GTA V working directorylocal plugin_name = "Example" -- We use this to select what folder to look inlocal function load_plugin_file( file )    dofile( GTA_V_dir .. '/scripts/'..plugin_name..'/'..file..'.lua')end-- Load all files from the folderload_plugin_file( "Config" ) -- Will load: "C:/-GTAV-/scripts/Example/Config.lua" including its metatables, functions, global vars, et cetra!

Hope this helps you!

 

Kind regards,

Techdaan.

Link to comment
Share on other sites

Royalgamer06

 

I got an error at this line:

for mod in io.popen([[dir "scripts/libs/" /b ]]):lines() do

in main.lua

 

Do you know why?

 

Any suggestion?

 

Im desperate!

Since launch I was never able to play or use lua scripts :(

Do you need any more information? Ask me!

Link to comment
Share on other sites

When I start the game I get a prompt system window with LUA plugins. Is normally?

Link to comment
Share on other sites

I have been using

 

float VEHICLE:GET_VEHICLE_DIRT_LEVEL(v) -- value 0..15

 

and

 

VEHICLE:SET_VEHICLE_DIRT_LEVEL(v, float)

 

in a script recently and they were working fine.

Now VEHICLE:GET_VEHICLE_DIRT_LEVEL seems to have stopped returning a float and returns a large integer.

 

I have reverted to the previous working version of my script and it still doesn't return a float.

 

example

platetxt = VEHICLE.GET_VEHICLE_NUMBER_PLATE_TEXT(v)dirtlevel = VEHICLE.GET_VEHICLE_DIRT_LEVEL(v)print("Vehicle " .. platetxt .. " Dirt Level " .. VEHICLE.GET_VEHICLE_DIRT_LEVEL(v) .. " - " .. dirtlevel)

produces..

Vehicle 07VIA999 Dirt Level 1088421888 - 1088421888

I did update both scripthookv and the lua plugin the other day, but I can't remember if it worked since I updated them?

 

@headscript / @szabo

 

Does VEHICLE:GET_VEHICLE_DIRT_LEVEL(v) return a float for you? As I say I definitely had this working in my script, but it no longer returns the expected value. Not sure if I'm being an idiot or if something changed.

Link to comment
Share on other sites

kakashi07

Doesnt work for me.

 

The LUA console, lua plugins dont load.

 

Yes, I have put everything in its place.

Link to comment
Share on other sites

Doesnt work for me.

 

The LUA console, lua plugins dont load.

 

Yes, I have put everything in its place.

Have you installed the redis pack for 2013?

Link to comment
Share on other sites

BloodyThunderX

Can't get LUA to work despite everything being in the correct locations.

I use the SDK build.

Would really like to get it working so I can use the Train Driver mod.

Link to comment
Share on other sites

headscript

Im desperate!

 

 

I got an error at this line:

for mod in io.popen([[dir "scripts/libs/" /b ]]):lines() do

in main.lua

 

Do you know why?

 

 

 

Since launch I was never able to play or use lua scripts :(

Do you need any more information? Ask me!

 

contact me via pm with skypename

 

 

 

 

 

@headscript / @szabo

 

Does VEHICLE:GET_VEHICLE_DIRT_LEVEL(v) return a float for you? As I say I definitely had this working in my script, but it no longer returns the expected value. Not sure if I'm being an idiot or if something changed.

 

i derped will be fixed in next version sorry

Edited by headscript
Link to comment
Share on other sites

kakashi07

 

Doesnt work for me.

 

The LUA console, lua plugins dont load.

 

Yes, I have put everything in its place.

Have you installed the redis pack for 2013?

 

 

That fixed it.

THANKS DUDE !

Link to comment
Share on other sites

headscript

 

 

Doesnt work for me.

 

The LUA console, lua plugins dont load.

 

Yes, I have put everything in its place.

Have you installed the redis pack for 2013?

 

 

That fixed it.

THANKS DUDE !

 

u know it has a reason why i write it in the first post

Link to comment
Share on other sites

I assume no audio navies work yet ? I'm trying to use "AUDIO._PLAY_AMBIENT_SPEECH1" and "AUDIO.REQUEST_SCRIPT_AUDIO_BANK" but it doesn't accept char values.

Link to comment
Share on other sites

headscript

I assume no audio navies work yet ? I'm trying to use "AUDIO._PLAY_AMBIENT_SPEECH1" and "AUDIO.REQUEST_SCRIPT_AUDIO_BANK" but it doesn't accept char values.

It was not a char in the sdk natives. H gonna add it to the list of changes for next version

Is there a way to fix the damn minimizing?

yes it's fixed in the next version which I got in my private build
Link to comment
Share on other sites

headscript

I have https://www.microsoft.com/en-us/download/details.aspx?id=40784installed.

 

When I launch the game, the prompt loads up on the loading screen. It shows everything loaded fine. But in game the scripts aren't in effect?

which scripts? did u follow the readme of the scripts?

 

also make a screenshot of the console when u try to do something from the mod

Link to comment
Share on other sites

ProdigyXZY

 

I have https://www.microsoft.com/en-us/download/details.aspx?id=40784installed.

 

When I launch the game, the prompt loads up on the loading screen. It shows everything loaded fine. But in game the scripts aren't in effect?

which scripts? did u follow the readme of the scripts?

 

also make a screenshot of the console when u try to do something from the mod

 

Szabo's Persistance Mod (Set up according to read me)

Realistic Train

IV Style Exit Vehicle (I actually had LUA working at one point and this mod used to work, LUA just randomly stopped working when I launched GTA earlier)

Fuel Script V 0.6

 

Followed the readme's when there were readme's

 

 

[Edit] Nothing happens when I try to do something from the mod. Just stays the same, still want a screenshot?

Edited by ProdigyXZY
Link to comment
Share on other sites

headscript

 

 

I have https://www.microsoft.com/en-us/download/details.aspx?id=40784installed.

 

When I launch the game, the prompt loads up on the loading screen. It shows everything loaded fine. But in game the scripts aren't in effect?

which scripts? did u follow the readme of the scripts?

 

also make a screenshot of the console when u try to do something from the mod

 

Szabo's Persistance Mod (Set up according to read me)

Realistic Train

IV Style Exit Vehicle (I actually had LUA working at one point and this mod used to work, LUA just randomly stopped working when I launched GTA earlier)

Fuel Script V 0.6

 

Followed the readme's when there were readme's

 

 

[Edit] Nothing happens when I try to do something from the mod. Just stays the same, still want a screenshot?

 

yep console show errors

Link to comment
Share on other sites

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