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?

BUY/SELL/TRADE ANYTHING RELATED TO MTA

SERVER ACCOUNTS

SERVER MONEY

GAMEMODES

SCRIPTING SERVICES

temp_Sig.png

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) 

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

No I don't think that worked either.

BUY/SELL/TRADE ANYTHING RELATED TO MTA

SERVER ACCOUNTS

SERVER MONEY

GAMEMODES

SCRIPTING SERVICES

temp_Sig.png

Posted

The code has no errors. Make sure that the meta.xml is correct and the resource is running.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

Why is it createExplosionFunc and where would the explosion take place?

BUY/SELL/TRADE ANYTHING RELATED TO MTA

SERVER ACCOUNTS

SERVER MONEY

GAMEMODES

SCRIPTING SERVICES

temp_Sig.png

Posted

You can't use a name of a MTA function (not in your case) as a name of a function.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

What? I thought that was the entire point, so for each function I just make it up?

BUY/SELL/TRADE ANYTHING RELATED TO MTA

SERVER ACCOUNTS

SERVER MONEY

GAMEMODES

SCRIPTING SERVICES

temp_Sig.png

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

I used to know how to code, but then I took an arrow in the knee.

Project Redivivus - Remaking Old School MTA With New Code

MTA 0.6 Nightly 1 released

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.

"The total IQ of the world is a constant.

The more people, the more idiots."

- Anonymous.

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