Jump to content

Auto Respawn


CodX

Recommended Posts

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 by CodX
Link to comment
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 by CodX
Link to comment

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

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 by CodX
Link to comment

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

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...