Jump to content

setTimer defining


Greenie0101

Recommended Posts

something that ive always wondered and im sure is posible and very easy but i cant work out, is how to define values in a timer

for example i can do this

x,y,z = getElementPosition(source) 

but i cant do this

setTimer(x,y,z = getElementPosition,100,0) 

how can i do something like this so i can use x,y,z later?

Link to comment
You will need to pass an argument because "source" is not defined here.

this was just an example, ive got a script which uses an event making the player the source

its server sided

 

oh and this script is using

getElementVelocity 

and not

getElementPosition 

and all im getting is 0 as my return

what if i went

setTimer(outputChatBox,100,0,getElementVelocity(object),source) 

is there a way to make that output the velocity in all 3 of its returns?

Link to comment
You will need to pass an argument because "source" is not defined here.

this was just an example, ive got a script which uses an event making the player the source

Anything come from outside the function that are inside the timer, and not global (local) or source from an event, you will need to pass it.

-- you sholud have event here 
  
setTimer(function(source) 
     local x, y, z = getElementVelocity(object) -- object is global? if not you need to pass it too. 
     outputChatBox(x..", "..y..", "..z, source) 
end,100,0,source) 

Link to comment

try this:

  
local object = createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 ) --creates an object 
setElementVelocity(object,1000,0,0) --sets the speed of the object 1000 going north 
--For onClientRender 
addEventHandler("onClientRender",root,function() 
     local x,y,z = getElementVelocity(object) --if the object isn't moving then the x,y,z would be zero 
     outputChatBox(x.. "," ..y..","..z) --Outputs the x,y,z speed of the object 
end) 
  
--timer 
setTimer(function() 
     local x,y,z = getElementVelocity(object) --if the object isn't moving then the x,y,z would be zero 
     outputChatBox(x.. "," ..y..","..z) --Outputs the x,y,z speed of the object 
end,1000,7) 

BTW, the setElementVelocity is only client-side only.

Link to comment
try this:
  
local object = createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 ) --creates an object 
setElementVelocity(object,1000,0,0) --sets the speed of the object 1000 going north 
--For onClientRender 
addEventHandler("onClientRender",root,function() 
     local x,y,z = getElementVelocity(object) --if the object isn't moving then the x,y,z would be zero 
     outputChatBox(x.. "," ..y..","..z) --Outputs the x,y,z speed of the object 
end) 
  
--timer 
setTimer(function() 
     local x,y,z = getElementVelocity(object) --if the object isn't moving then the x,y,z would be zero 
     outputChatBox(x.. "," ..y..","..z) --Outputs the x,y,z speed of the object 
end,1000,7) 

BTW, the setElementVelocity is only client-side only.

what ive done is made 2 objects, one is a ped the other is an object. i have attached them so that as the ped falls with graity the object falls too. then i want to get the velocity of the ped every 100ms. i know how to do all this and it should be easy. however even when the ped is clearly falling very fast, with the object attached, im getting 0,0,0 as my velocity

Link to comment

ok im being misunderstood. I have a script which makes a ped (not the player) and an object and attaches them. i dont need to be told how to do all that. i have the ped and object created, attached and falling, thats not what i needed help to do. now i need to use setTimer so i get the velocity of the ped as it falls every 100ms. when i do this in a different function, all i get is 0,0,0 on my outputChatBox. but i cant find a way of doing it in the same function. im bad at explaining so sorry if this make no sence

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