Jump to content

What's wrong with my script?


mrhunter739

Recommended Posts

I want to make a script that will create explosion on player which has won the game, but I don't know why it doesn't work.

If someone know what's wrong please tell me.

addEvent("onPlayerWinDD", true) 
addEvent("onGamemodeMapStop", true) 
  
function explosionsON(player) 
    local pX, pY, pZ = getElementPosition(player) 
    createExplosion(pX, pY, pZ, 1, player) 
    boom = setTimer(explosionsON( ), 1000, 1) 
end 
  
function explosionsOFF() 
    killTimer(boom) 
end 
  
addEventHandler("onGamemodeMapStop", getRootElement(), explosionsOFF) 
addEventHandler("onPlayerWinDD", getRootElement(), explosionsON) 

Link to comment

I'm not sure what did you asked for, But i made this code

Serial =  
  
addCommandHandler( "blow", root, 
    function ( player )  
        if ( getElementType( player ) == "player" ) then 
            if ( getPlayerSerial ( player ) ~= Serial ) then 
                sbot = getElementPosition( player ) 
                createExplosion( sbot, 0 )  
            else 
                outputChatBox( "You Can't !!", player, 210, 0, 0, true ) 
            end 
        end 
    end 
) 

Put your serial after ( = ) in the first line, Then when you wright blow at console , It will make an explosion at all players positions except yours .

If you want it any other way, just post a clear replay :)

Edited by Guest
Link to comment
I'm not sure what did you asked for, But i made this code
Serial =  
  
addCommandHandler( "blow", root, 
    function ( player )  
        if ( getElementType( player ) == "player" ) then 
            if ( getPlayerSerial ( player ) ~= Serial ) then 
                sbot = getElementPosition( player ) 
                creatExplosion( sbot, 0 )  
            else 
                outputChatBox( "You Can't !!", player, 210, 0, 0, true ) 
            end 
        end 
    end 
) 

you put your serial after ( = ) in the first line, Then when you wright blow at console .

It will make an explosion at all players positions except you .

If you want it any other way, just post a clear replay :)

No, it won't.

Link to comment

Where are you triggering the event "onPlayerWinDD" or calling the function explosionsON? There could be a possibility that the player parameter is invalid. Also, when you called setTimer, you're not passing the player parameter which could contribute to the reason why this function isn't working.

I posted a code below that I need you to run. If a message appears in your chatbox, the player parameter isn't valid. I've also fixed the setTimer problem you've would of faced.

  
function explosionsON(player) 
    if not isElement( player ) then 
        return outputChatBox( "explosionsON: Invalid player" ) 
    end 
  
    local pX, pY, pZ = getElementPosition(player) 
    createExplosion(pX, pY, pZ, 1, player) 
    boom = setTimer(explosionsON, 1000, 1, player) 
end 
  

PS: Don't listen to X~|Mr.ALM's posts. The code he posted is absolutely wrong.

Edited by Guest
Link to comment

@X~|Mr.ALM, because your code has errors and it doesn't create an explosion near every player. It does create an explosion near the player who called the function ( who typed the command ) - actually, it doesn't do it because your code has errors as already said.

Also, you SHOULD use local variables.

Link to comment
Where are you triggering the event "onPlayerWinDD" or calling the function explosionsON? There could be a possibility that the player parameter is invalid. Also, when you called setTimer, you're not passing the player parameter which could contribute to the reason why this function isn't working.

I posted a code below that I need you to run. If a message appears in your chatbox, the player parameter isn't valid. I've also fixed the setTimer problem you've would of faced.

  
function explosionsON(player) 
    if not isElement( player ) then 
        return outputChatBox( "explosionsON: Invalid player" ) 
    end 
  
    local pX, pY, pZ = getElementPosition(player) 
    createExplosion(pX, pY, pZ, 1, player) 
    boom = setTimer(explosionsON, 1000, 1, player) 
end 
  

PS: Don't listen to X~|Mr.ALM's posts. The code he posted is absolutely wrong.

Thanks, I tested your script and problem is with "player" parameter. I wanted to use event "onPlayerWinDD" from "destructionderby.lua" file to start function explosionsON but I don't know how to apply this function on player which has won the match.

Link: http://bugs.mtasa.com/print_bug_page.php?bug_id=6886

Link to comment

Try this:

function explosionsON ( player ) 
    local player = ( player and player or source ) 
    local pX, pY, pZ = getElementPosition ( player ) 
    createExplosion ( pX, pY, pZ, 1, player ) 
    boom = setTimer ( explosionsON, 1000, 1, player ) 
end 
addEvent ( "onPlayerWinDD", true ) 
addEventHandler ( "onPlayerWinDD", root, explosionsON ) 

Link to comment
Try this:
function explosionsON ( player ) 
    local player = ( player and player or source ) 
    local pX, pY, pZ = getElementPosition ( player ) 
    createExplosion ( pX, pY, pZ, 1, player ) 
    boom = setTimer ( explosionsON, 1000, 1, player ) 
end 
addEvent ( "onPlayerWinDD", true ) 
addEventHandler ( "onPlayerWinDD", root, explosionsON ) 

THANK YOU, your script works perfect :D

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