Antoni Posted April 13, 2013 Share Posted April 13, 2013 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
DNL291 Posted April 13, 2013 Share Posted April 13, 2013 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
Antoni Posted April 13, 2013 Author Share Posted April 13, 2013 No I don't think that worked either. Link to comment
DNL291 Posted April 13, 2013 Share Posted April 13, 2013 The code has no errors. Make sure that the meta.xml is correct and the resource is running. Link to comment
Antoni Posted April 13, 2013 Author Share Posted April 13, 2013 Why is it createExplosionFunc and where would the explosion take place? Link to comment
DNL291 Posted April 13, 2013 Share Posted April 13, 2013 You can't use a name of a MTA function (not in your case) as a name of a function. Link to comment
Antoni Posted April 13, 2013 Author Share Posted April 13, 2013 What? I thought that was the entire point, so for each function I just make it up? Link to comment
ixjf Posted April 13, 2013 Share Posted April 13, 2013 (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 April 13, 2013 by Guest Link to comment
Puma Posted April 13, 2013 Share Posted April 13, 2013 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
ixjf Posted April 13, 2013 Share Posted April 13, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now