Greenie0101 Posted December 11, 2012 Share Posted December 11, 2012 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
manve1 Posted December 11, 2012 Share Posted December 11, 2012 setTimer( function( ) local x, y, z = getElementPosition(source) end, 100, 0 ) Link to comment
TAPL Posted December 11, 2012 Share Posted December 11, 2012 You will need to pass an argument because "source" is not defined here. Link to comment
TwiX! Posted December 11, 2012 Share Posted December 11, 2012 setTimer ( example, 100, 1, source ); function example ( player ) x, y, z = getElementPosition ( player ); end But if you not have source: You will need to pass an argument because "source" is not defined here. Link to comment
HunT Posted December 11, 2012 Share Posted December 11, 2012 Or : https://wiki.multitheftauto.com/wiki/OnClientRender Link to comment
Greenie0101 Posted December 11, 2012 Author Share Posted December 11, 2012 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 Or : https://wiki.multitheftauto.com/wiki/OnClientRender 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
TAPL Posted December 11, 2012 Share Posted December 11, 2012 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
Greenie0101 Posted December 11, 2012 Author Share Posted December 11, 2012 still getting 0 for everything even when the object i falling quite fast Link to comment
Jaysds1 Posted December 11, 2012 Share Posted December 11, 2012 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
Greenie0101 Posted December 12, 2012 Author Share Posted December 12, 2012 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
Tete omar Posted December 12, 2012 Share Posted December 12, 2012 As i understood from what you said you want to attach the object to the player that when the player falls or move anywhere the object moves with him too , so you supposed to use: attachElements already Link to comment
Greenie0101 Posted December 12, 2012 Author Share Posted December 12, 2012 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
Tete omar Posted December 12, 2012 Share Posted December 12, 2012 Oh you meant the object following the ped , but lately? Link to comment
Greenie0101 Posted December 12, 2012 Author Share Posted December 12, 2012 dont worry ill find a way around it. thanks for trying to help though 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