Jump to content

Command problem


SWEMike

Recommended Posts

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

Posted

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 )

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

[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:

Posted

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

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 )

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

[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. :D

Posted

Please use "edit" button next time.

Download this attachment.

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

Your welcome.

And thank you :)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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