Jump to content

Command don't work, why?


ProCurator

Recommended Posts

I'm new in Lua, now I'm trying to make first Command, but it's don't work. The question is: why?

function GetPosition ( player ) 
    local x, y, z =  GetElementPosition( player ) 
    local rx, ry, rz = GetElementRotation( player ) 
    outputChatBox( "Your Position: "..x..", "..y..", "..z..", Rotation: "..rx..", "..ry..", "..rz) 
end 
addCommandHandler ( "pos", GetPosition ) 

I was looking for a some Topic for new noobs in making commands, but i don't found nothing.

PS: And sorry for my english :F

Link to comment

Welcome to Lua :)

1st, use [ lua][ /lua] tags.

2nd, Lua scripts are case sensitive, so you need to check the wiki when you're scripting with MTA functions.

function GetPosition ( player ) 
    local x, y, z =  getElementPosition( player ) 
    local rx, ry, rz = getElementRotation( player ) 
    outputChatBox( "Your Position: "..x..", "..y..", "..z..", Rotation: "..rx..", "..ry..", "..rz) 
end 
addCommandHandler ( "pos", GetPosition ) 

Link to comment

it works in server side, if you want it client side then do:

function GetPosition () 
    local x, y, z =  getElementPosition( getLocalPlayer() ) 
    local rx, ry, rz = getElementRotation( getLocalPlayer() ) 
    outputChatBox( "Your Position: "..x..", "..y..", "..z..", Rotation: "..rx..", "..ry..", "..rz) 
end 
addCommandHandler ( "pos", GetPosition ) 

you can define what side will be in meta.xml.

Link to comment

with this code it works:

  
function GetPosition ( player ) 
    local x, y, z =  getElementPosition( player ) 
    local rx, ry, rz = getElementRotation( player ) 
    outputChatBox( "Your Position: "..x..", "..y..", "..z..", Rotation: "..rx..", "..ry..", "..rz,player) 
end 
addCommandHandler ( "pos", GetPosition ) 

i've tested it and has no problems.

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