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 Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

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

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

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

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

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    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. Design Your Own Mission
      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
    1. Announcements

    2. Support

    3. Suggestions

LUA script crashing game (Info inside)


Supacure
 Share

Recommended Posts

Hey, just having some issues with a particular LUA script I'm working with. I never used LUA before and have no idea how to setup the mod environment in C++ because if I did I'd be using that instead however no time right now.

 

That being said here is my problem

--[[Crashes on load / reload, only changing the eval to 'not' in the first while loop.]]local supaTools = {}enabled = falsefunction supaTools.tick()	        while(--[[>>>not<<<]] enabled) do 		if(get_key_pressed(Keys.F5) and get_key_pressed(Keys.LControlKey)) then		enabled = true		end				local playerPed = PLAYER.PLAYER_PED_ID()		local player = PLAYER.GET_PLAYER_PED(playerPed)				PLAYER.SET_POLICE_IGNORE_PLAYER(player, false)		PLAYER.SET_EVERYONE_IGNORE_PLAYER(player, false)			end		while(enabled) do		if(get_key_pressed(Keys.F5) and get_key_pressed(Keys.LControlKey)) then		enabled = false		end				local playerPed = PLAYER.PLAYER_PED_ID()		local player = PLAYER.GET_PLAYER_PED(playerPed)				PLAYER.SET_POLICE_IGNORE_PLAYER(player, true)		PLAYER.SET_EVERYONE_IGNORE_PLAYER(player, true)	end	end return supaTools

Is anyone able to give me a hand? As I mentioned, first time LUA user and just going from what I can get from the documentation I found online / examples provided. Thanks!

Edit: Also if anyone is curious it seems that the SET_POLICE_IGNORE_PLAYER only applies to ground units. Helicopters and wounded officers (last breath) will shoot you regardless. The second one probably applies to red necks and people in impoverished neighborhoods but I have not tested that yet. Any workaround would be awesome. Trying to find a way to make it so aiming at people doesn't scare them as well.

Edited by Supacure
Link to comment
Share on other sites

If you are new to lua, why not just use c++ (you just have to consider the entire script is in a while true loop so it is a matter of organizing your code differently). if you only use c# then there is hope for you, just be patient...

 

http://ragepluginhook.net/ComingSoon.aspx

 

here is an example of coding a toggle for code you want to only run once in a while true... (you are setting some values in gta repetitively and it is uneccessary although I dont see the harm in it, i would just do it the way below)

while (true){    if (EnableKeyPressed())    {        enabled = !enabled;         if (!enabled)        {            PoliceAndPedsIgnorePlayer(false);//i made up my own method for simplicity        }        else        {            PoliceAndPedsIgnorePlayer(true);        }    }    Wait(0);//so gta can process other scripts when it reaches the end of your loop... MANDATORY}
Edited by c39687
Link to comment
Share on other sites

 

If you are new to lua, why not just use c++ (you just have to consider the entire script is in a while true loop so it is a matter of organizing your code differently). if you only use c# then there is hope for you, just be patient...

 

http://ragepluginhook.net/ComingSoon.aspx

 

here is an example of coding a toggle for code you want to only run once in a while true... (you are setting some values in gta repetitively and it is uneccessary although I dont see the harm in it, i would just do it the way below)

while (true){    if (EnableKeyPressed())    {        enabled = !enabled;         if (!enabled)        {            PoliceAndPedsIgnorePlayer(false);//i made up my own method for simplicity        }        else        {            PoliceAndPedsIgnorePlayer(true);        }    }    Wait(0);//so gta can process other scripts when it reaches the end of your loop... MANDATORY}

I would like to use C++ and would prefer it but I have no idea where to start with setting up the project for asi files.

I know a fairly extensive amount about C++ but not much on the side of compilers and environments (I mostly used 2012 / 2010 express which are terribly convoluted). If you could perhaps show me a reference wherein I could learn how to compile and setup files for this I would be very appreciative. I don't need help setting up much more than the basic file structure and project settings. I would much prefer C++ over Lua.

Link to comment
Share on other sites

Have you taken a look at the ScriptHookV SDK?
The included NativeTrainer sample is a Visual Studio project.

Regarding your signature, I'm pretty sure they meant "control the rain" :p

Link to comment
Share on other sites

 

 

If you are new to lua, why not just use c++ (you just have to consider the entire script is in a while true loop so it is a matter of organizing your code differently). if you only use c# then there is hope for you, just be patient...

 

http://ragepluginhook.net/ComingSoon.aspx

 

here is an example of coding a toggle for code you want to only run once in a while true... (you are setting some values in gta repetitively and it is uneccessary although I dont see the harm in it, i would just do it the way below)

while (true){    if (EnableKeyPressed())    {        enabled = !enabled;         if (!enabled)        {            PoliceAndPedsIgnorePlayer(false);//i made up my own method for simplicity        }        else        {            PoliceAndPedsIgnorePlayer(true);        }    }    Wait(0);//so gta can process other scripts when it reaches the end of your loop... MANDATORY}

I would like to use C++ and would prefer it but I have no idea where to start with setting up the project for asi files.

I know a fairly extensive amount about C++ but not much on the side of compilers and environments (I mostly used 2012 / 2010 express which are terribly convoluted). If you could perhaps show me a reference wherein I could learn how to compile and setup files for this I would be very appreciative. I don't need help setting up much more than the basic file structure and project settings. I would much prefer C++ over Lua.

 

1. make a cpp source file called main.cpp which has the APIEntry method (this is the code that gets injected. Just copy the one from the native trainer.)

 

 

BOOL APIENTRY DllMain(HMODULE hInstance, DWORD reason, LPVOID lpReserved){    switch (reason)    {    case DLL_PROCESS_ATTACH:        scriptRegister(hInstance, ScriptMain);//this function is declared in main.h, ScriptMain is your method from your script's cpp that has the while true        break;    }            return TRUE;}

 

2. make your script's source file, call it script.cpp and create this function in it's code...

 

 

void ScriptMain(){    while (true)    {        //your code         WAIT(0);//tells gta to come back on next loop of script thread, allows the game to process other script (without and game freezes in your script)    }}

 

then just get your headers and includes straight

Link to comment
Share on other sites

headscript

Hey, just having some issues with a particular LUA script I'm working with. I never used LUA before and have no idea how to setup the mod environment in C++ because if I did I'd be using that instead however no time right now.

 

That being said here is my problem

--[[Crashes on load / reload, only changing the eval to 'not' in the first while loop.]]local supaTools = {}enabled = falsefunction supaTools.tick()	        while(--[[>>>not<<<]] enabled) do 		if(get_key_pressed(Keys.F5) and get_key_pressed(Keys.LControlKey)) then		enabled = true		end				local playerPed = PLAYER.PLAYER_PED_ID()		local player = PLAYER.GET_PLAYER_PED(playerPed)				PLAYER.SET_POLICE_IGNORE_PLAYER(player, false)		PLAYER.SET_EVERYONE_IGNORE_PLAYER(player, false)			end		while(enabled) do		if(get_key_pressed(Keys.F5) and get_key_pressed(Keys.LControlKey)) then		enabled = false		end				local playerPed = PLAYER.PLAYER_PED_ID()		local player = PLAYER.GET_PLAYER_PED(playerPed)				PLAYER.SET_POLICE_IGNORE_PLAYER(player, true)		PLAYER.SET_EVERYONE_IGNORE_PLAYER(player, true)	end	end return supaTools

Is anyone able to give me a hand? As I mentioned, first time LUA user and just going from what I can get from the documentation I found online / examples provided. Thanks!

 

Edit: Also if anyone is curious it seems that the SET_POLICE_IGNORE_PLAYER only applies to ground units. Helicopters and wounded officers (last breath) will shoot you regardless. The second one probably applies to red necks and people in impoverished neighborhoods but I have not tested that yet. Any workaround would be awesome. Trying to find a way to make it so aiming at people doesn't scare them as well.

dont make a infite while loop inside the tick function

the tick is already getting called every some ms

Link to comment
Share on other sites

 

 

 

If you are new to lua, why not just use c++ (you just have to consider the entire script is in a while true loop so it is a matter of organizing your code differently). if you only use c# then there is hope for you, just be patient...

 

http://ragepluginhook.net/ComingSoon.aspx

 

here is an example of coding a toggle for code you want to only run once in a while true... (you are setting some values in gta repetitively and it is uneccessary although I dont see the harm in it, i would just do it the way below)

while (true){    if (EnableKeyPressed())    {        enabled = !enabled;         if (!enabled)        {            PoliceAndPedsIgnorePlayer(false);//i made up my own method for simplicity        }        else        {            PoliceAndPedsIgnorePlayer(true);        }    }    Wait(0);//so gta can process other scripts when it reaches the end of your loop... MANDATORY}

I would like to use C++ and would prefer it but I have no idea where to start with setting up the project for asi files.

I know a fairly extensive amount about C++ but not much on the side of compilers and environments (I mostly used 2012 / 2010 express which are terribly convoluted). If you could perhaps show me a reference wherein I could learn how to compile and setup files for this I would be very appreciative. I don't need help setting up much more than the basic file structure and project settings. I would much prefer C++ over Lua.

 

1. make a cpp source file called main.cpp which has the APIEntry method (this is the code that gets injected. Just copy the one from the native trainer.)

BOOL APIENTRY DllMain(HMODULE hInstance, DWORD reason, LPVOID lpReserved){    switch (reason)    {    case DLL_PROCESS_ATTACH:        scriptRegister(hInstance, ScriptMain);//this function is declared in main.h, ScriptMain is your method from your script's cpp that has the while true        break;    }            return TRUE;}

2. make your script's source file, call it script.cpp and create this function in it's code...

void ScriptMain(){    while (true)    {        //your code         WAIT(0);//tells gta to come back on next loop of script thread, allows the game to process other script (without and game freezes in your script)    }}

then just get your headers and includes straight

 

Wow, thanks a ton that really clarifies a lot. I recommend you post this somewhere in documentation to let newer players get started easier. I had a hard time figuring it out myself and that's not to say I'm great or anything, but more experienced than the average new guy.

 

 

Hey, just having some issues with a particular LUA script I'm working with. I never used LUA before and have no idea how to setup the mod environment in C++ because if I did I'd be using that instead however no time right now.

 

That being said here is my problem

--[[Crashes on load / reload, only changing the eval to 'not' in the first while loop.]]local supaTools = {}enabled = falsefunction supaTools.tick()	        while(--[[>>>not<<<]] enabled) do 		if(get_key_pressed(Keys.F5) and get_key_pressed(Keys.LControlKey)) then		enabled = true		end				local playerPed = PLAYER.PLAYER_PED_ID()		local player = PLAYER.GET_PLAYER_PED(playerPed)				PLAYER.SET_POLICE_IGNORE_PLAYER(player, false)		PLAYER.SET_EVERYONE_IGNORE_PLAYER(player, false)			end		while(enabled) do		if(get_key_pressed(Keys.F5) and get_key_pressed(Keys.LControlKey)) then		enabled = false		end				local playerPed = PLAYER.PLAYER_PED_ID()		local player = PLAYER.GET_PLAYER_PED(playerPed)				PLAYER.SET_POLICE_IGNORE_PLAYER(player, true)		PLAYER.SET_EVERYONE_IGNORE_PLAYER(player, true)	end	end return supaTools

Is anyone able to give me a hand? As I mentioned, first time LUA user and just going from what I can get from the documentation I found online / examples provided. Thanks!

 

Edit: Also if anyone is curious it seems that the SET_POLICE_IGNORE_PLAYER only applies to ground units. Helicopters and wounded officers (last breath) will shoot you regardless. The second one probably applies to red necks and people in impoverished neighborhoods but I have not tested that yet. Any workaround would be awesome. Trying to find a way to make it so aiming at people doesn't scare them as well.

dont make a infite while loop inside the tick function

the tick is already getting called every some ms

 

 

Oh, sorry. Didn't realized that's what tick meant. Thanks for the help. I just assumed it was a arbitrary function name. I don't Lua and only learned from some doc I found online. Thank you!

Edited by Supacure
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
 Share

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