dakata783 Posted July 28, 2012 Share Posted July 28, 2012 (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 July 28, 2012 by Guest Link to comment
robhol Posted July 28, 2012 Share Posted July 28, 2012 You forgot to post your code and error messages. Link to comment
robhol Posted July 28, 2012 Share Posted July 28, 2012 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
dakata783 Posted July 28, 2012 Author Share Posted July 28, 2012 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
Anderl Posted July 28, 2012 Share Posted July 28, 2012 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
robhol Posted July 28, 2012 Share Posted July 28, 2012 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. 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