SWEMike Posted August 15, 2010 Share Posted August 15, 2010 function onResourceStart ( name, root ) vehBar = getElementByID ( "vehbar" ) origX, origY, origZ = getElementPosition ( vehBar ) end function closeVehicleBar ( playerSource, commandName ) local preX, preY, preZ = getObjectRotation( vehBar ) if preY == 0.0 then local rotY = 90.0 moveObject ( vehBar, 4000, origX, origY, origZ, 0.0, rotY, 0.0 ) end end function openVehicleBar ( playerSource, commandName ) local preX, preY, preZ = getObjectRotation( vehBar ) if preY == 90.0 then local rotY = -90.0 moveObject ( vehBar, 4000, origX, origY, origZ, 0.0, rotY, 0.0 ) end end addEventHandler ( "onResourceStart", getRootElement(), onResourceStart ) addCommandHandler ( "closebar", closeVehicleBar ) addCommandHandler ( "openbar", openVehicleBar ) Can anyone tell me why I have to write the commands two times everytime I want to use it to make it work? Explanation: I go ingame, write /openbar, ntohing happens, I write /openbar again, it works. I then want to close it, I use the command /closebar, ntohing happens, I do it again there it goes down. I have tested it lots of times it always works on the second use of the commands, and yes, I even tried waiting a few seconds after that it closed/opened all the way, still the same result. Link to comment
dzek (varez) Posted August 15, 2010 Share Posted August 15, 2010 https://wiki.multitheftauto.com/wiki/Debugging example: function onResourceStart ( name, root ) vehBar = getElementByID ( "vehbar" ) origX, origY, origZ = getElementPosition ( vehBar ) end function closeVehicleBar ( playerSource, commandName ) outputDebugString("player "..getPlayerName(playerSource).." wants to close bar") local preX, preY, preZ = getObjectRotation( vehBar ) outputDebugString("current bar rotation: "..tostring(preY)) if preY == 0.0 then outputDebugString("moving bar:") local rotY = 90.0 outputDebugString(tostring(moveObject ( vehBar, 4000, origX, origY, origZ, 0.0, rotY, 0.0 ))) end end function openVehicleBar ( playerSource, commandName ) outputDebugString("player "..getPlayerName(playerSource).." wants to open bar") local preX, preY, preZ = getObjectRotation( vehBar ) outputDebugString("current bar rotation: "..tostring(preY)) if preY == 90.0 then outputDebugString("moving bar:") local rotY = -90.0 outputDebugString(tostring(moveObject ( vehBar, 4000, origX, origY, origZ, 0.0, rotY, 0.0 ))) end end addEventHandler ( "onResourceStart", getRootElement(), onResourceStart ) addCommandHandler ( "closebar", closeVehicleBar ) addCommandHandler ( "openbar", openVehicleBar ) Link to comment
SWEMike Posted August 15, 2010 Author Share Posted August 15, 2010 [19:59:43] INFO: player Michael_Sund wants to open bar [19:59:43] INFO: current bar rotation: 90 [19:59:43] INFO: moving bar: [19:59:43] INFO: true [19:59:48] INFO: player Michael_Sund wants to close bar [19:59:48] INFO: current bar rotation: 90 [19:59:50] INFO: player Michael_Sund wants to close bar [19:59:50] INFO: current bar rotation: 0 [19:59:50] INFO: moving bar: [19:59:50] INFO: true [19:59:56] INFO: player Michael_Sund wants to open bar [19:59:56] INFO: current bar rotation: 0 I don't get it! D: Link to comment
dzek (varez) Posted August 15, 2010 Share Posted August 15, 2010 and what if you wait few seconds after closing/opening? could you post your map file too (can be just with that one object)? this looks rly weird Link to comment
SWEMike Posted August 15, 2010 Author Share Posted August 15, 2010 (edited) If I wait a few seconds nothing happens. And sure, I'll give ya the map. Edited August 16, 2010 by Guest Link to comment
dzek (varez) Posted August 15, 2010 Share Posted August 15, 2010 Looks like this is a bug (i will report it). Just after every move, getObjectRotation twice - to get right value.. and btw: onResourceStart should be attached to getResourceRootElement(getThisResource()) NOT to getRootElement() ! Why? Read here. Here's your script: function onResourceStart ( name, root ) vehBar = getElementByID ( "vehbar" ) origX, origY, origZ = getElementPosition ( vehBar ) end function closeVehicleBar ( playerSource, commandName ) local preX, preY, preZ = getObjectRotation( vehBar ) local preX, preY, preZ = getObjectRotation( vehBar ) if preY == 0.0 then local rotY = 90.0 end end function openVehicleBar ( playerSource, commandName ) local preX, preY, preZ = getObjectRotation( vehBar ) local preX, preY, preZ = getObjectRotation( vehBar ) if preY == 90.0 then local rotY = -90.0 end end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), onResourceStart ) addCommandHandler ( "closebar", closeVehicleBar ) addCommandHandler ( "openbar", openVehicleBar ) Link to comment
SWEMike Posted August 15, 2010 Author Share Posted August 15, 2010 Okay, thanks! I'll try it right away. Link to comment
SWEMike Posted August 15, 2010 Author Share Posted August 15, 2010 [21:34:01] WARNING: rp\server\army.lua:15: Bad argument @ 'getObjectRotation' [21:34:01] WARNING: rp\server\army.lua:16: Bad argument @ 'getObjectRotation' [21:34:04] WARNING: rp\server\army.lua:15: Bad argument @ 'getObjectRotation' [21:34:04] WARNING: rp\server\army.lua:16: Bad argument @ 'getObjectRotation' [21:34:06] WARNING: rp\server\army.lua:7: Bad argument @ 'getObjectRotation' [21:34:06] WARNING: rp\server\army.lua:8: Bad argument @ 'getObjectRotation' [21:34:09] WARNING: rp\server\army.lua:7: Bad argument @ 'getObjectRotation' [21:34:09] WARNING: rp\server\army.lua:8: Bad argument @ 'getObjectRotation' I don't think LUA likes me too much. Link to comment
dzek (varez) Posted August 15, 2010 Share Posted August 15, 2010 Please use "edit" button next time. Download this attachment. Link to comment
SWEMike Posted August 16, 2010 Author Share Posted August 16, 2010 Okay, it works now. Thank you very much! Oh, and sorry about the edit thing, I'll use it next time. Link to comment
dzek (varez) Posted August 16, 2010 Share Posted August 16, 2010 Your welcome. And thank you 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