Jump to content

What is wrong with this?


Antoni

Recommended Posts

function createExplosion(thePlayer, command) 
    local x,y,x = getElementPosition(thePlayer) 
    y = y + 20 
    local createExplosion(x,y,z, 0) 
    if createdExplosion == false) then 
        outputChatBox("Failed to cause an explosion.",thePlayer) 
    end 
end 
addCommandHandler("explosion", createExplosion) 

I wanted to make a simple command /explosion that will make an explosion near the player, what is wrong with it?

Link to comment
  • Moderators

Try this:

function createExplosionFunc(thePlayer, command) 
    local x,y,x = getElementPosition(thePlayer) 
    y = y + 20 
    local createdExplosion = createExplosion(x,y,z, 0) 
    if createdExplosion == false then 
        outputChatBox("Failed to cause an explosion.",thePlayer) 
    end 
end 
addCommandHandler("explosion", createExplosionFunc) 

Link to comment

Nah, not a stack overflow, because the second time he executes createExplosion from within the createExplosion function, his createExplosion function will miss parameters (player) and will throw up an error.

He himself made a createExplosion function and that overwrites the default MTA createExplosion function. Just rename your "function createExplosion(thePlayer, command)" to something else like "function createExplosionCommand (thePlayer, command)", don't forget to change "addCommandHandler("explosion", createExplosion)" into "addCommandHandler("explosion", createExplosionCommand)" and you're done.

Link to comment
Nah, not a stack overflow, because the second time he executes createExplosion from within the createExplosion function, his createExplosion function will miss parameters (player) and will throw up an error.

Indeed, I'm sorry for the mistake, I haven't seen the code carefully.

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