Jump to content

Need some help!


Recommended Posts

Posted (edited)

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
560x95.png
Posted

You forgot to post your code and error messages.

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

Posted

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.

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

Posted

  
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.

560x95.png
Posted
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 
) 

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

Please provide a fuller explanation of exactly what you expect to happen and what does. In this case I'm noticing that you're comparing a team name with an actual team. Also pay attention to indentation.

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

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