CodX Posted August 19, 2017 Share Posted August 19, 2017 (edited) Hello ! I've made a script, an AutoExec. I want to "/respawnall 10" after a time but didn't work, he got nil.. can you help me please ? Error: WARNING: AutoRespawnAll/respawn.lua:2: Bad argument @ 'executeCommandHandler' [Expected element at argument 2, got nil] Script: setTimer(function () executeCommandHandler("respawnall 10", thePlayer) end, 5000, 0) Sorry for my english, i'm from Romanian. Edited August 19, 2017 by CodX Link to comment
Dimos7 Posted August 19, 2017 Share Posted August 19, 2017 the player is not defind in that script so its nil Link to comment
CodX Posted August 19, 2017 Author Share Posted August 19, 2017 So what can i do to be executed that command ? Link to comment
_DrXenon Posted August 19, 2017 Share Posted August 19, 2017 Idk what is that. But if dimos is true then, just define thePlayer through using addCommandHandler. (first parameter is the player that commanded.) Link to comment
CodX Posted August 20, 2017 Author Share Posted August 20, 2017 (edited) setTimer(function () local player = {"Alvin_Michael"} if player then executeCommandHandler("respawnall 10", player) end end, 5000, 0) I set my character name but now he give an table. WARNING: AutoRespawnAll/respawn.lua:4: Bad argument @ 'executeCommandHandler' [Expected element at argument 2, got table] And on "addCommandHandler" is the same. WARNING: AutoRespawnAll/respawn.lua:4: Bad argument @ 'addCommandHandler' [Expected function at argument 2, got table] Edited August 20, 2017 by CodX Link to comment
SycroX Posted August 20, 2017 Share Posted August 20, 2017 you'v only put the player name in a table getPlayerFromName -- use this command to get the player from his name setTimer(function () local pTable = {"Alvin_Michael"} for _,player in ipairs(getElementsByType("player")) do if pTable[getPlayerName(player)] then executeCommandHandler("respawnall 10", player) end end end, 5000, 0) or another way setTimer(function () local players = {"Alvin_Michael"} for _,value in ipairs(players) do local player = getPlayerFromName(value) if player then executeCommandHandler("respawnall 10", player) end end end, 5000, 0) Link to comment
CodX Posted August 20, 2017 Author Share Posted August 20, 2017 5 minutes ago, #x1AhMeD,-09 said: you'v only put the player name in a table getPlayerFromName -- use this command to get the player from his name setTimer(function () local pTable = {"Alvin_Michael"} for _,player in ipairs(getElementsByType("player")) do if pTable[getPlayerName(player)] then executeCommandHandler("respawnall 10", player) end end end, 5000, 0) or another way setTimer(function () local players = {"Alvin_Michael"} for _,value in ipairs(players) do local player = getPlayerFromName(value) if player then executeCommandHandler("respawnall 10", player) end end end, 5000, 0) At first the command isn't executed and at second says: WARNING: AutoRespawnall/respawn.lua:6: Bad argument @ 'executeCommandHandler' [Expected string at argument 2, got player]. Is good if got player but why is not executed the command ? The command is from another script, he need to be exported ? P.S: Sorry if my english is bad. Link to comment
SycroX Posted August 20, 2017 Share Posted August 20, 2017 can u show me the args of your command ? Link to comment
CodX Posted August 20, 2017 Author Share Posted August 20, 2017 (edited) The command don't use arguments. If you type just /respawnall, in chat will see "All cars will be respawned in 30 seconds". If you type /respawnall 20 or 10, in chat will see "All cars will be respawned in 20 or 10 seconds." 25 minutes ago, #x1AhMeD,-09 said: can u show me the args of your command ? Edited August 20, 2017 by CodX Link to comment
_DrXenon Posted August 20, 2017 Share Posted August 20, 2017 Just don't use executeCommandHandler and use addCommandHandler to work on your respawn function. We can't give further help since we don't know what you asking for and how does your function work and if it even exists. According to your replys I am starting to believe that you think that the command 'respawnall' which you used somewhere else other than in your server is some sort of global MTA hardcoded function which is not. To use that command, you should have a function that actually respawns, connected to the command you wish. Link to comment
Mr.Loki Posted August 21, 2017 Share Posted August 21, 2017 Try something like this. This is a Server script. function RespawnStuff( ... ) -- Code to respawn stuff end addCommandHandler( "respawnall", function( plr, cmd, sec ) local time = sec and (sec * 1000) or 1000 setTimer( RespawnStuff, time, 1, ... ) outputChatBox( "Stuff will be respawned in "..sec.." seconds." ) end) Link to comment
CodX Posted August 21, 2017 Author Share Posted August 21, 2017 2 hours ago, Mr.Loki said: Try something like this. This is a Server script. function RespawnStuff( ... ) -- Code to respawn stuff end addCommandHandler( "respawnall", function( plr, cmd, sec ) local time = sec and (sec * 1000) or 1000 setTimer( RespawnStuff, time, 1, ... ) outputChatBox( "Stuff will be respawned in "..sec.." seconds." ) end) It work ! Thank you very much ! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now