Jump to content

some problem with timer


Tox

Recommended Posts

things afterline 44 does not work at all

local peds = {} 
local timers = {} 
  
function appearDknight (ped) 
setElementData (ped, "knightEnabled",true) 
timers [tostring (ped).."appear"] = setTimer (  
    function () 
        if getElementAlpha (ped) < 255 then 
            setElementAlpha (ped, getElementAlpha (ped)+1) 
            setElementData (ped, "appearwait", true) 
            setTimer (function () setElementData (ped, "appearwait", false) end, 10000,1) 
        else 
            killTimer (timers[tostring(ped).."appear"]) 
            timers [tostring (ped).."fade"] = setTimer ( 
                function () 
                    if not getElementData (ped, "appearwait") and getElementAlpha (ped) > 1 then 
                        setElementAlpha (ped, getElementAlpha (ped)-1) 
                    end 
                end, 50,0            
            ) 
        end 
    end, 50,0    
    ) 
end 
  
  
  
addEventHandler ("onPlayerTarget",root, 
    function (t_Element) 
        if t_Element then 
            if getElementType (t_Element) == "player" then 
                if getElementData (t_Element, "admin") and not peds[t_Element] then 
                    local x,y,z = getElementPosition (source) 
                    local rx,ry,rz = getElementRotation (source) 
                    setElementFrozen (source, true) 
                    peds [t_Element] = createPed (0,x,y+0.2,z,rz) 
                    setElementAlpha (peds[t_Element], 0) 
                    addPedClothes (peds[t_Element], "gimpleg", "gimpleg", 17) 
                    setPedAnimation (source, "ped", "IDLE_tired", 10000,true) 
                    setPedAnimation (peds[t_Element], "PAULNMAC", "Piss_loop",10000,true) 
                    setPedStat (peds[t_Element],23,1000)                     
                    appearDknight (peds[t_Element]) 
                    setElementData (t_Element, "knightEnabled",false)    
                    timers [tostring (t_Element).."finish"] = setTimer ( 
                        function (p) 
                            if isElement (p) and not getElementData (t_Element, "knightEnabled")    then 
                                setElementFrozen (p, false) 
                                if peds [t_Element] then 
                                    destroyElement (peds[t_Element]) ; peds[t_Element] = nil 
                                    if timers [tostring (t_Element).."appear"] or timers [tostring (t_Element).."fade"] then 
                                        killTimer (timers [tostring (t_Element).."appear"]) 
                                        killTimer (timers [tostring (t_Element).."fade"]) 
                                    end  
                                end      
                            else 
                                killTimer (timers [tostring (t_Element).."finish"]) 
                            end  
                        end,5000,0   
                    )            
                end 
            end  
        end 
    end 
) 

Link to comment

That's because you attempt to collect p from the function in the timer but never passed a value for it in setTimer (therefore, within the timer function, p is nil).

Line 58:

end,5000,0,t_Element 

Also, inside the timer function (lines 46-57 inclusive), you should change every peds[t_Element] and t_Element into p because neither (unless declared globally) exist in the timer-attached function.

Link to comment
That's because you attempt to collect p from the function in the timer but never passed a value for it in setTimer (therefore, within the timer function, p is nil).

Line 58:

end,5000,0,t_Element 

Also, inside the timer function (lines 46-57 inclusive), you should change every peds[t_Element] and t_Element into p because neither (unless declared globally) exist in the timer-attached function.

oh alright thanks. i don't know why this happens, i used not to need passing arguments in before

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