Guest Posted January 7, 2008 Share Posted January 7, 2008 Hi. I'd like to write script, which will create ramps in front of my car and after some seconds delete it, but It's not easy for me to create that script (I'm LUA newbie ). I'm not asking You to make this script for me, I'm asking You for solutions how to do it. I think I should check vehicle's position and rotation, but I'm not sure what to do later... Sorry for my bad english. I hope You will help me Link to comment
rjcnz333 Posted January 7, 2008 Share Posted January 7, 2008 Later you need to createObject, and destroyElement (your object) after some seconds. Link to comment
ratoc Posted January 7, 2008 Share Posted January 7, 2008 local x, y, z = getElementPosition(player) local a = getPlayerRotation(player) x += (10 * math.sin(-a)) y += (10 * math.cos(-a)) createObject (modelid, x, y, z, 0, 0, a) ^ you can create an object in front of the player with this code Link to comment
Guest Posted January 7, 2008 Share Posted January 7, 2008 (edited) Thank You very much :)I've got one more question...How can I make my script "sleep" for 50ms. ? @down OK, thx Edited January 7, 2008 by Guest Link to comment
ratoc Posted January 7, 2008 Share Posted January 7, 2008 you should create a timer.. Link to comment
Guest Posted January 7, 2008 Share Posted January 7, 2008 x += (10 * math.sin(-a)) y += (10 * math.cos(-a)) = SCRIPT ERROR: ...ramp.lua:5: '=' expected near '+' What does "x +=" mean? How can I fix this error? Link to comment
[email protected] Posted January 7, 2008 Share Posted January 7, 2008 (edited) function spawnRamp( thePlayer ) local x, y, z = getElementPosition(player) local a = getPlayerRotation(player) x2 = (10 * math.sin(-a)) y2 = (10 * math.cos(-a)) local ramp = createObject (3593, x2, y2, z, 0, 0, a) [color=#FF0000]setTimer ( removeRamp, 3000, 1, [b]ramp[/b] )[/color] end [color=#FF0000]function removeRamp ( [b]rampObj[/b] )[/color] [color=#FF0000] destroyElement(rampObj)[/color] [color=#FF0000] end[/color] bindKey ( thePlayer, "c", "down", spawnRamp ) You should have scripted it like above: 2 functions: 1 spawns the ramp, 1 destroys the ramp. 1 timer: inside the spawnfunction, that will trigger the destroy function when it expires. EDIT: text in red is changed code, but noticed previous post got deleted, I also didn't verify whether your code really does what it is supposed to do, just the correct use of the 2 functions and the timer Edited January 7, 2008 by Guest Link to comment
lil Toady Posted January 7, 2008 Share Posted January 7, 2008 unfortunatly '+=' wont work in lua. i'd do something like that function createRamp ( player, command ) local x, y, z = getElementPosition ( player ) local r = getPlayerRotation ( player ) x = x - math.sin ( math.rad ( r ) ) * 5 y = y + math.cos ( math.rad ( r ) ) * 5 createObject ( 1655, x, y, z, 0, 0, r ) end addCommandHandler ( "ramp", createRamp ) Link to comment
rjcnz333 Posted January 7, 2008 Share Posted January 7, 2008 (edited) Ok, and why so difficult? Just function createRamp ( player, command ) local x, y, z = getElementPosition ( player ) local r = getPlayerRotation ( player ) x = x + math.cos(r) * 10 y = y + math.sin(r) * 10 createObject ( 1655, x, y, z, 0, 0, -r ) end addCommandHandler ( "ramp", createRamp ) Damn. Something goes wrong in my script( Edited January 7, 2008 by Guest Link to comment
Guest Posted January 7, 2008 Share Posted January 7, 2008 Thanks. The last question: How can I remove ramp? Link to comment
rjcnz333 Posted January 7, 2008 Share Posted January 7, 2008 GetPlayerRotation doesn't work when player is in a vehicle. We need something else. Link to comment
Guest Posted January 7, 2008 Share Posted January 7, 2008 function createRamp ( player, command ) local x, y, z = getElementPosition ( player ) local r = getPlayerRotation ( player ) x = x - math.sin ( math.rad ( r ) ) * 20 y = y + math.cos ( math.rad ( r ) ) * 20 createObject ( 1655, x, y, z, 0, 0, r ) setTimer ( RemoveRamp, 10000, 1 ) end addCommandHandler ( "ramp", createRamp ) function RemoveRamp () outputChatBox ( "Blablabla", thePlayer ) end It DOES work, when player is in vehicle Link to comment
rjcnz333 Posted January 8, 2008 Share Posted January 8, 2008 I have tried it. It works only when I'm not in a vehicle. When I'm in a vehicle, it spawns ramps with the static rotation, and it depends on the rotation what I have, when I entered the car. So, if I turn, and then spawn the ramp, I can't jump, because the rotation is wrong. This script is fully working: ffunction createRamp ( player, command ) local x, y, z = getElementPosition ( player ) local theVehicle = getPlayerOccupiedVehicle ( player ) local a,b,r = getVehicleRotation ( theVehicle ) x = x - math.sin ( math.rad(r) ) * 20 y = y + math.cos ( math.rad(r) ) * 20 ramp = createObject ( 1655, x, y, z, 0, 0, r ) setTimer ( RemoveRamp, 8000, 1 ) end function RemoveRamp () destroyElement(ramp) end addCommandHandler ( "r", createRamp ) Link to comment
Guest Posted January 8, 2008 Share Posted January 8, 2008 Thank You, but there is little problem... The ramp spawns, but when You will spawn more than 1 ramps (type quickly /ramp twice), two ramps will apear, but only one will disapear. I wrote this: function createRamp ( player, command ) local x, y, z = getElementPosition ( player ) local theVehicle = getPlayerOccupiedVehicle ( player ) local a,b,r = getVehicleRotation ( theVehicle ) if ( spawned == yes ) then x = x - math.sin ( math.rad(r) ) * 20 y = y + math.cos ( math.rad(r) ) * 20 ramp = createObject ( 1655, x, y, z, 0, 0, r ) spawned = yes setTimer ( RemoveRamp, 8000, 1 ) setTimer ( setClock, 8000, 1 ) end if (spawned == no) then outputChatBox("Wait, please...", thePlayer) end end function setClock () spawned = no end function RemoveRamp () destroyElement(ramp) end addCommandHandler ( "ramp", createRamp ) But it doesn't work Link to comment
[email protected] Posted January 8, 2008 Share Posted January 8, 2008 You can do it with much less difficulty: You had: ramp = createObject ( 1655, x, y, z, 0, 0, r ) ... setTimer ( RemoveRamp, 8000, 1 ) just add the ramp as argument to that timer: setTimer ( RemoveRamp, 8000, 1, ramp ) This way it will function as if ramp was an argument of the functioncall, usually written as: RemoveRamp( ramp ) Link to comment
Guest Posted January 8, 2008 Share Posted January 8, 2008 Thank You It works very good now! function createRamp ( player, command ) local x, y, z = getElementPosition ( player ) local theVehicle = getPlayerOccupiedVehicle ( player ) local a,b,r = getVehicleRotation ( theVehicle ) x = x - math.sin ( math.rad(r) ) * 20 y = y + math.cos ( math.rad(r) ) * 20 ramp = createObject ( 1655, x, y, z, 0, 0, r ) setTimer ( RemoveRamp, 8000, 1, ramp ) end end function RemoveRamp (ramp) destroyElement(ramp) end addCommandHandler ( "ramp", createRamp ) Link to comment
rjcnz333 Posted January 8, 2008 Share Posted January 8, 2008 What about binds? When I have tried to bind C on ramp, my client crashed. Link to comment
Guest Posted January 8, 2008 Share Posted January 8, 2008 function createRamp ( source, key, keyState ) local x, y, z = getElementPosition ( source ) local theVehicle = getPlayerOccupiedVehicle ( source ) local a,b,r = getVehicleRotation ( theVehicle ) x = x - math.sin ( math.rad(r) ) * 20 y = y + math.cos ( math.rad(r) ) * 20 ramp = createObject ( 1655, x, y, z, 0, 0, r ) setTimer ( RemoveRamp, 8000, 1, ramp ) end function RemoveRamp (ramp) destroyElement(ramp) end function bindTheKeys ( source ) bindKey ( source, "c", "down", createRamp ) outputChatBox( "Press 'c' to spawn ramp (you must be in any vehicle)",thePlayer ) end addCommandHandler ( "ramp", bindTheKeys ) I'm using this one and it works very good You need to type /ramp to activate ramps. To spawn ramp in front of You, press C. Link to comment
norby89 Posted January 8, 2008 Share Posted January 8, 2008 you could also use setElementVelocity to get the same effect, or why not, make the vehicle jump even higher 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