Maurize Posted July 27, 2010 Share Posted July 27, 2010 (edited) .. I started to learn .lua. My problem is im very very new and i want to know if my team spawn work. I want to spawn different teams in different locations... So i used MtaWiki for help And now i want to know if this is correct or will i have to change something? addEventHandler("onResourceStart", resourceRoot, function() for i,player in ipairs(getElementsByType("player")) do spawn(player) end end ) function spawn(player, source, key, TeamName ) local playerTeam = getPlayerTeam ( source ) if ( playerTeam == "Mercenaries" ) then spawnPlayer ( player, 2824.647+math.random(-0,5), -2438.673+math.random(-0,5), 13, 90, 179 ) giveWeapon(player,23,51) fadeCamera(player, true) setCameraTarget(player, player) else spawnPlayer ( player, 1000+math.random(-0,5), 1000+math.random(-0,5), 13, 90, 177 ) fadeCamera(player, true) setCameraTarget(player, player) end addEventHandler("onPlayerJoin", root, function() spawn(source) end ) addEventHandler("onPlayerWasted", root, function() setTimer(spawn, 5000, 1, source) end ) Edited July 4, 2011 by Guest Link to comment
Dark Dragon Posted July 28, 2010 Share Posted July 28, 2010 addEventHandler("onResourceStart", resourceRoot, function() for i,player in ipairs(getElementsByType("player")) do spawn(player) end end ) function spawn(player) -- not sure where you want to get source, key, and TeamName from, you use spawn(player), therefore the first argument will be the only valid one, as you don't use any of those anyways i'd just remove them local playerTeam = getPlayerTeam ( player ) -- player instead of source here if ( getTeamName(playerTeam) == "Mercenaries" ) then -- remember that a team element is not the same as the teams name spawnPlayer ( player, 2824.647+math.random(-0,5), -2438.673+math.random(-0,5), 13, 90, 179 ) giveWeapon(player,23,51) fadeCamera(player, true) setCameraTarget(player, player) else spawnPlayer ( player, 1000+math.random(-0,5), 1000+math.random(-0,5), 13, 90, 177 ) fadeCamera(player, true) setCameraTarget(player, player) end end addEventHandler("onPlayerJoin", root, function() spawn(source) end ) addEventHandler("onPlayerWasted", root, function() setTimer(spawn, 5000, 1, source) end ) Link to comment
Maurize Posted July 28, 2010 Author Share Posted July 28, 2010 hmm there must be a bug. this ressource doesn´t work but the console don´t say anything... the spawn script doesn´t, work the others does. i tried do debug but i don´t know... u use autoteams... if this is important there is the standart team ( civilian ) then ( police ) and ( mercenaries ) so this is what i did: addEventHandler("onResourceStart", resourceRoot, function() for i,player in ipairs(getElementsByType("player")) do spawn(player) end end ) function spawn(player) local playerTeam = getPlayerTeam ( player ) if ( getTeamName(playerTeam) == "Mercenaries" ) then spawnPlayer ( player, 2824.647+math.random(-0,5), -2438.673+math.random(-0,5), 13, 90, 179 ) giveWeapon(player, 22, 51) giveWeapon(player, 31, 100) setPlayerStat ( thePlayer, 69, 999 ) setPlayerStat ( thePlayer, 78, 1000 ) setPlayerStat ( thePlayer, 24, 1000 ) fadeCamera(player, true) setCameraTarget(player, player) elseif ( getTeamName(playerTeam) == "Police" ) then spawnPlayer ( player, 2300.647+math.random(-0,5), -2000.673+math.random(-0,5), 13, 90, 172 ) giveWeapon(player, 22, 51) setPlayerStat ( thePlayer, 70, 999 ) fadeCamera(player, true) setCameraTarget(player, player) else spawnPlayer ( player, 1000+math.random(-0,5), 1000+math.random(-0,5), 13, 90, 177 ) fadeCamera(player, true) setCameraTarget(player, player) end addEventHandler("onPlayerJoin", root, function() spawn(source) end ) addEventHandler("onPlayerWasted", root, function() setTimer(spawn, 5000, 1, source) end ) Link to comment
Dark Dragon Posted July 28, 2010 Share Posted July 28, 2010 oh yes, there's an 'end' missing after line 28, also note that the player has to be in a team already if you want them to spawn in the predetermined area for the Mercenaries and the Police Link to comment
Maurize Posted July 29, 2010 Author Share Posted July 29, 2010 wow .. works...! Thanks a lot friend! 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