DarkLink Posted July 5, 2011 Share Posted July 5, 2011 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 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 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 Link to comment
Buffalo Posted July 5, 2011 Share Posted July 5, 2011 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) Link to comment
DarkLink Posted July 5, 2011 Author Share Posted July 5, 2011 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
Buffalo Posted July 5, 2011 Share Posted July 5, 2011 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
DarkLink Posted July 5, 2011 Author Share Posted July 5, 2011 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
karlis Posted July 5, 2011 Share Posted July 5, 2011 you can call other func outside that will call killTimer Link to comment
DarkLink Posted July 5, 2011 Author Share Posted July 5, 2011 you can call other func outside that will call killTimer Ye thanks bro, I already figured out solution Thanks all!! 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