Jump to content

What is wrong with this?


Antoni

Recommended Posts

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

Posted

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) 

Posted (edited)

createExplosionFunc is the handler of the command - you want to call createExplosion inside of that function. You were recursively calling itself (since you overwrote createExplosion, you were now calling itself) and it will end up throwing an error.

Edited by Guest
Posted

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.

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

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