Jump to content

Why is this code not working?


Recommended Posts

function explosion ()
    local pX, pY, pZ = getElementPosition (source)
    createExplosion (pX, pY, pZ, 6, source)
end
addCommandHandler ("explodir", explosion)

These are the errors when I type the command:

Bad argument @ 'getElementPosition' [Expected element at argument 1, got nil]

Bad ARgument @ 'createExplosion' [Expected vector 3 at argument 1, got boolean]

Link to comment
2 hours ago, Hugo_Almeidowski said:

function explosion ()
    local pX, pY, pZ = getElementPosition (source)
    createExplosion (pX, pY, pZ, 6, source)
end
addCommandHandler ("explodir", explosion)

These are the errors when I type the command:

Bad argument @ 'getElementPosition' [Expected element at argument 1, got nil]

Bad ARgument @ 'createExplosion' [Expected vector 3 at argument 1, got boolean]

function explosion (player)
    local pX, pY, pZ = getElementPosition player)
    createExplosion (pX, pY, pZ, 6, player)
end
addCommandHandler ("explodir", explosion)

 

Link to comment
36 minutes ago, KillerX said:

function explosion (player)
    local pX, pY, pZ = getElementPosition player)
    createExplosion (pX, pY, pZ, 6, player)
end
addCommandHandler ("explodir", explosion)

 

Thank you very much! BTW, you have a mistake on the second line after getElementPosition

 

Can you please explain why sometimes I don't need to add nothing between the function brackets and other times I have?

Link to comment
  • Moderators
3 hours ago, Hugo_Almeidowski said:

Thank you very much! BTW, you have a mistake on the second line after getElementPosition

Probably your code is set as client-side on the meta.xml. And on the client-side there is no 'player' parameter for addCommandHandler.

3 hours ago, Hugo_Almeidowski said:

Can you please explain why sometimes I don't need to add nothing between the function brackets and other times I have?

You should learn the difference between client and server-side, I also recommend you study programming logic and Lua syntax in the MTA.

Link to comment
18 hours ago, KillerX said:

no problem

-------------------------

you should read the function on the wiki first

https://wiki.multitheftauto.com/wiki/AddCommandHandler

Thanks! I've read it!

18 hours ago, DNL291 said:

Probably your code is set as client-side on the meta.xml. And on the client-side there is no 'player' parameter for addCommandHandler.

You should learn the difference between client and server-side, I also recommend you study programming logic and Lua syntax in the MTA.

I've been reading the wiki and following tutorials, but there are still a lot of things I don't get.

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