• Need help making a simple script. What am I doing wrong?
    8 replies, posted
I'm trying to make a script where if a player is wanted, he/she is sent to jail when he/she is killed. Am I doing something wrong? [CODE]WantedDeathMessage = "You have been arrested upon death due to your wanted status." function GM:PlayerDeath( victim, inflictor, attacker ) if victim:isWanted() then victim:Arrest() victim:PrintMessage( HUD_PRINTCENTER, ..WantedDeathMessage.. ) end end[/CODE]
Get rid of the double dots you put next to the printmessage thing and it would probably work (Lua expects those dots when a string is meant to be conjoined, e.g. 'dog'..'ass' > 'dogass') [editline]26th February 2016[/editline] Also, you might want to put that in a hook so it doesn't override the core PlayerDeath function like so: [CODE] local WantedDeathMessage = "You have been arrested upon death due to your wanted status." hook.Add( 'PlayerDeath', 'ArrestDeadPlayers', function( victim, inflictor, attacker ) if victim:isWanted() then victim:Arrest() victim:PrintMessage( HUD_PRINTCENTER, WantedDeathMessage ) end end ) [/CODE] [editline]26th February 2016[/editline] I haven't tested that though, so it might not work
[QUOTE=MPan1;49816460]Get rid of the double dots you put next to the printmessage thing and it would probably work (Lua expects those dots when a string is meant to be conjoined, e.g. 'dog'..'ass' > 'dogass') [editline]26th February 2016[/editline] Also, you might want to put that in a hook so it doesn't override the core PlayerDeath function like so: [CODE] local WantedDeathMessage = "You have been arrested upon death due to your wanted status." hook.Add( 'PlayerDeath', 'ArrestDeadPlayers', function( victim, inflictor, attacker ) if victim:isWanted() then victim:Arrest() victim:PrintMessage( HUD_PRINTCENTER, WantedDeathMessage ) end end ) [/CODE] [editline]26th February 2016[/editline] I haven't tested that though, so it might not work[/QUOTE] Hmm, I tried putting that in and it still doesn't seem to work. Any other ideas on why it might not be working? Also, am I putting it in the right folder? garrysmod/lua/autorun
Are you sure victim:isWanted has a lower-case 'i'?
[QUOTE=MPan1;49816725]Are you sure victim:isWanted has a lower-case 'i'?[/QUOTE] I'm pretty sure it does. I used this, not sure if it was changed or anything. [URL="http://wiki.darkrp.com/index.php/Functions/Player/Shared/isWanted"]http://wiki.darkrp.com/index.php/Functions/Player/Shared/isWanted[/URL] Am I using the wrong one? Is it this one I am supposed to use? [URL="http://wiki.darkrp.com/index.php/Hooks/Server/playerWanted"]http://wiki.darkrp.com/index.php/Hooks/Server/playerWanted[/URL]
If you didn't get errors with that first piece of code you had then it's not running, post the exact file path
[QUOTE=Coffeee;49816955]If you didn't get errors with that first piece of code you had then it's not running, post the exact file path[/QUOTE] I tried putting in garrysmod/lua/autorun and garrysmod/lua/autorun/server. Both didn't work, where should I put it?
What is the file called?
[QUOTE=Coffeee;49817669]What is the file called?[/QUOTE] It is called arrest.lua and is a lua file.
Sorry, you need to Log In to post a reply to this thread.