Jump to content

Need some help!


Recommended Posts

I have 2 teams

-US army

-Enemies

and i want if someone from the US Army die to respawn him at ( 219.24492, 1861.24292, 13.14696 )

and if someone from the Enemies die to respawn him at ( source, -330.77100, 1532.63647, 75.35938 )

i tried to make this but i get Error: Stack Overflow

If you can help me, i'll be grateful!

function spawnPlayer( )  
    local playerTeam = getTeamName( source ) 
    if playerTeam == ArmyTeam then 
     spawnPlayer ( source, 219.24492, 1861.24292, 13.14696 , 0) 
     outputChatBox("Don't die anymore man! There is no place for mistakes!",source,0,0,255) 
     else 
     spawnPlayer ( source, -330.77100, 1532.63647, 75.35938 , 0) 
     outputChatBox("Oh cmon! Dead again? Go! Go! Go!",source,255,0,0) 
     end 
end 
addEventHandler("onPlayerWasted", getRootElement(), spawnPlayer ) 

Edited by Guest
Link to comment

The error here happens because you overwrite an MTA function and the new one ends up calling itself infinitely, hence the stack overflow - call your handler function something else.

Also, wrong parameters to getTeamName (it takes a team element, not a player) and you might have made a mistake with ArmyTeam - if this isn't a variable you assigned somewhere containing that team's name, it'll screw up and always do the "else" part of your if.

Link to comment

  
function createMedicTeam () 
        ArmyTeam = createTeam ("US army", 0, 0, 255) 
end 
addEventHandler ("onResourceStart", resourceRoot, createMedicTeam) 
  
function spawnThePlayer( )  
    local  getteam = getPlayerTeam ( source ) 
    local teamname = getTeamName ( getteam ) 
    if teamname == ArmyTeam then 
     spawnPlayer ( source, 219.24492, 1861.24292, 13.14696 , 0) 
     outputChatBox("Don't die anymore man! There is no place for mistakes!",source,0,0,255) 
     setElementModel(source,285) 
     else 
     spawnPlayer ( source, -330.77100, 1532.63647, 75.35938 , 0) 
     setElementModel(source,287) 
     outputChatBox("Oh cmon! Dead again? Go! Go! Go!",source,255,0,0) 
     end 
end 
addEventHandler("onPlayerWasted", getRootElement(), spawnThePlayer() ) 

I tried this and it is not working too.

Link to comment
local pArmyTeam = createTeam( 'US Army', 0, 0, 255 ); 
  
addEventHandler( 'onPlayerWastd', root, 
    function( ) 
        local pCurrentTeam = getTeamName( getPlayerTeam( source ) ) 
        if( pCurrentTeam ) then 
            if( pCurrentTeam == getTeamName( pArmyTeam ) ) then 
                spawnPlayer( source, 219.24492, 1861.24292, 13.14696, 0 ); 
                outputChatBox( 'Do not die anymore man! There is no place for mistakes!', source, 0, 0, 255, false ); 
                setElementModel( source, 285 ); 
            else 
                spawnPlayer( source, -330.77100, 1532.63647, 75.35938, 0 ); 
                setElementModel( source, 287 ); 
                outputChatBox( 'Oh cmon! Dead again? Go! Go! Go!', source 255, 0, 0, false ); 
            end 
        else 
            -- do something here if the player has no team 
        end 
    end 
) 

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