Jump to content

Command don't work, why?


ProCurator

Recommended Posts

Posted

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

Posted

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 ) 

Learn Lua - Learn to script - GUI scripting

Scripter tools - Find/fix errors yourself(!)

Don't pm me for scripting help, keep it for the Scripting subforum!

Posted

I know, I always checking everything in wiki, because i don't know functions...

But command still don't work, can somebody make it correct? :C

It's will really helpful.

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

So if your code is good, why it's still don't work?!

Maybe something is wrong with meta.xml?

<meta> 
    <info author="ProCurator" version="1.0" type="script" name="Get Position"/> 
    <script src="GetPosition.lua" /> 
</meta> 

Name of Lua: GetPosition.lua

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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