Jump to content

bad argument of player


Recommended Posts

I need to trigger ever for client, and then trigger event back for server, and I am having problems with players that triggered, keep saying on console bad argument :x

Client side:

  
bar1 = guiCreateProgressBar ( 0.4, 0.5, 0.3, 0.1, true ) 
guiSetVisible(bar1,false) 
  
addEvent("mostraBar",true) 
function progressBar1() 
  
guiSetVisible(bar1,true) 
guiProgressBarSetProgress(bar1, 0) 
setTimer(function() if(guiProgressBarGetProgress(bar1)==100) then hide() return end guiProgressBarSetProgress(bar1, guiProgressBarGetProgress(bar1)+2.5) end, 50, 60) 
  
  
end 
addEventHandler("mostraBar", getRootElement(), progressBar1) 
  
function hide() 
outputChatBox("estou aqui2") 
guiSetVisible(bar1, false) 
triggerServerEvent("teleportar", getLocalPlayer()) 
end 
  

server side:

  
if(isElementWithinMarker(keyPresser, passagem1)) then 
    triggerClientEvent(keyPresser, "mostraBar", keyPresser) 
end 
  
  
addEvent("teleportar",true) 
function makeTeleport() 
            outputChatBox("estou aqui") 
            setTimer(function() if(isElementWithinMarker(source,passagem1)) then setElementPosition(source,x2,y2,z2 +1) end end, 50,1) 
            local tabElm = getAttachedElements(source) 
            setTimer(function() 
            for i, v in ipairs (tabElm) do 
                if (getElementType(v)  == 'blip') then 
                    if(getPlayerTeam(source) == team_immigrantsSP) then 
                        setElementVisibleTo ( v, getRootElement(), true ) 
                    end 
                end 
            end 
            end, 3000,1) 
  
end 
addEventHandler("teleportar", getRootElement(), makeTeleport) 
  

Can someone clarify me? I read on wiki, about event handlers, the source and the client variables, also tryed with client, but didnt work :S

Keep saying bad argument on isElementWithinMarker(source,passagem1), on the function makeTeleport, I guess is the source variable.

Thanks in advance :/

This is killing me :x

Link to comment
You have set a timer. Provide source within calling it, so player element won't be lost
setTimer(function(source) if(isElementWithinMarker(source,passagem1)) then setElementPosition(source,x2,y2,z2 +1) end end, 50,1,source) 

what do u mean ? I should make, something like

local source = source ? before enter the timer ?

thanks for ur reply

Link to comment

Your player element is described in this function as source, and therefore the function you attached to setTimer will read it as nil as it is different function, so you have to provide 'source' argument for setTimer. Just try to replace that setTimer line with yours, it should work.

Another example:

setTimer(function(player) if(isElementWithinMarker(player,passagem1)) then setElementPosition(player,x2,y2,z2 +1) end end, 50,1,source)--we provide source as argument 

Link to comment
Your player element is described in this function as source, and therefore the function you attached to setTimer will read it as nil as it is different function, so you have to provide 'source' argument for setTimer. Just try to replace that setTimer line with yours, it should work.

Another example:

setTimer(function(player) if(isElementWithinMarker(player,passagem1)) then setElementPosition(player,x2,y2,z2 +1) end end, 50,1,source)--we provide source as argument 

It worked!! Thanks alot buffalo!!

Btw just one more question, its possible to stop a timer inside that timer?

Something like:

  
local barFill= setTimer(function() if(guiProgressBarGetProgress(bar1)==100) then killTimer(barFill) hide() return end guiProgressBarSetProgress(bar1, guiProgressBarGetProgress(bar1)+2.5) end, 50, 60) 
  

Didnt worked, the timer still continues after my bar was filled..

Thanks in advance!!

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