Jump to content

Trouble with spawn script!


Maurize

Recommended Posts

Don´t know whats wrong...

Maybe someone have an idea what´s wrong.. :(

addEventHandler("onResourceStart", resourceRoot,
function()
for i,player in ipairs(getElementsByType("player")) do
		spawn(player)
end
end
)
 
function spawn(player)
repeat until spawnPlayer ( player, 2824.647, -2438.673+math.random(-0,5), 14, 90, 0 )
fadeCamera(source, false, 0.1, 0, 0, 0 )
end
 
addEventHandler("onPlayerLogin", root,
function()
     spawn(source)
local playerTeam = getPlayerTeam ( player )
if 
( getTeamName(playerTeam) == "Mercenaries" ) then 
spawnPlayer ( player, 2800.721, -2455.929, 13.630, 90, 179, team )
giveWeapon(player, 4, 68)
giveWeapon(player, 22, 68)
giveWeapon(player, 31, 100)
giveWeapon(player, 18, 5)
setPlayerStat ( thePlayer, 69, 999 )
setPlayerStat ( thePlayer, 78, 1000 )
setPlayerStat ( thePlayer, 24, 1000 )
setPlayerStat ( thePlayer, 23, 1000 )
elseif
( getTeamName(playerTeam) == "Police" ) then 
spawnPlayer ( player, 1580.233, -1636.650, 13.553, 90, math.random(280,281) )
giveWeapon(player, 3, 1)
giveWeapon(player, 22, 68)
giveWeapon(player, 29, 120)
setPlayerStat ( thePlayer, 69, 750 )
setPlayerStat ( thePlayer, 76, 1000 )
setPlayerStat ( thePlayer, 24, 1000 )
setPlayerStat ( thePlayer, 23, 1000 )
else
spawnPlayer ( player, 2824.647, -2438.673+math.random(-0,5), 14, 90, 0 )
giveWeapon(player, math.random(2,7))
end
end
)
 
addEventHandler("onPlayerWasted", root,
function()
setTimer(spawn, 5000, 1, source)
end
)

Link to comment
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, 2800.721, -2455.929, 13.630, 90, 179 )
fadeCamera(player, true)
setCameraTarget(player, player)
giveWeapon(player, 4, 68)
giveWeapon(player, 22, 68)
giveWeapon(player, 31, 100)
giveWeapon(player, 18, 5)
setPlayerStat ( thePlayer, 69, 999 )
setPlayerStat ( thePlayer, 78, 1000 )
setPlayerStat ( thePlayer, 24, 1000 )
setPlayerStat ( thePlayer, 23, 1000 )
elseif ( getTeamName(playerTeam) == "Police" ) then 
spawnPlayer ( player, 1580.233, -1636.650, 13.553, 90, math.random(280,281) )
fadeCamera(player, true)
setCameraTarget(player, player)
giveWeapon(player, 3, 1)
giveWeapon(player, 22, 68)
giveWeapon(player, 29, 120)
setPlayerStat ( thePlayer, 69, 750 )
setPlayerStat ( thePlayer, 76, 1000 )
setPlayerStat ( thePlayer, 24, 1000 )
setPlayerStat ( thePlayer, 23, 1000 )
else spawnPlayer ( player, 2824.647+math.random(-0,5), -2438.673+math.random(-0,5), 13, 90, 177 )
fadeCamera(player, true)
setCameraTarget(player, player)
giveWeapon(player, math.random(2,7))
end
end
 
addEventHandler("onPlayerLogin", root,
function()
     spawn(source)
end
)
 
addEventHandler("onPlayerWasted", root,
function()
setTimer(spawn, 5000, 1, source)
end
)

and the team script:

function playerJoined()
check(source)
end
addEventHandler("onPlayerJoin",getRootElement(),playerJoined)
 
function playerChangedNick(oldNick,newNick)
setTimer(check,1000,1,source)
end
addEventHandler("onPlayerChangeNick",getRootElement(),playerChangedNick)
 
function playerQuit()
removePlayerFromTeam(source)
end
addEventHandler("onPlayerQuit",getRootElement(),playerQuit)
 
function loggedIn()
check(source)
end
addEventHandler("onPlayerJoin",getRootElement(),loggedIn)
 
function loggedOut()
check(source)
end
addEventHandler("onPlayerLogout",getRootElement(),loggedOut)
 
function initiate()
local rootNode = getResourceConfig("config.xml")
local children = xmlNodeGetChildren(rootNode)
if children == false then
return
end
for _,node in pairs(children) do
local attributes = xmlNodeGetAttributes(node)
local name = attributes.name
local color = {getColorFromString(attributes.color)}
if not color[1] then
		color = {255,255,255}
end
	teams[name] = attributes
	teams[name].color = color
if not toboolean(get("noEmptyTeams")) then
		teams[name].team = createTeam(name,unpack(color))
end
end
for k,v in pairs(getElementsByType("player")) do
	check(v)
end
end
addEventHandler("onResourceStart",getResourceRootElement(),initiate)
 
function check(player)
if not isElement(player) or getElementType(player) ~= "player" then
debug("No player")
return
end
local nick = getPlayerName(player)
local accountName = getAccountName(getPlayerAccount(player))
for name,data in pairs(teams) do
local tagMatch = false
local aclGroupMatch = false
if data.tag ~= nil and string.find(nick,data.tag,1,true) then
		tagMatch = true
end
if data.aclGroup ~= nil and accountName and isObjectInACLGroup("user."..accountName,aclGetGroup(data.aclGroup)) then
		aclGroupMatch = true
end
if data.required == "both" then
if tagMatch and aclGroupMatch then
			addPlayerToTeam(player,name)
return
end
else
if tagMatch or aclGroupMatch then
			addPlayerToTeam(player,name)
return
end
end
end
removePlayerFromTeam(player)
setPlayerTeam(player,nil)
end
 
function addPlayerToTeam(player,name)
local team = teams[name].team
if not isElement(team) or getElementType(team) ~= "team" then
team = createTeam(teams[name].name,unpack(teams[name].color))
	teams[name].team = team
end
setPlayerTeam(player,team)
debug("Added player '"..getPlayerName(player).."' to team '"..name.."'")
end
 
function removePlayerFromTeam(player)
setPlayerTeam(player,nil)
debug("Removed player '"..getPlayerName(player).."' from team")
if toboolean(get("noEmptyTeams")) then
for k,v in pairs(teams) do
local team = v.team
if isElement(team) and getElementType(team) == "team" then
if countPlayersInTeam(team) == 0 then
destroyElement(team)
end
end
end
end
end
 
function toboolean(string)
if string == "false" or not string then
return false
end
return true
end
 
setElementData(getResourceRootElement(),"debug",true)
function debug(string)
if getElementData(getResourceRootElement(),"debug") then
outputDebugString("autoteams: "..string)
end
end

Link to comment
  • 4 weeks later...

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