Ir para conteúdo

warotserv

Posts Recomendados

Este sistema faz com que o server seja divido em 2 times, o time vermelho e o time azul.



em "data\creaturescripts\scripts" crie um arquivo chamado "pvpTeam.lua" e cole o seguinte código



redTeamSpawn = { x = 218, y = 172, z = 7} -- red team spawn position
blueTeamSpawn = { x = 218, y = 170, z = 7} -- blue team spawn position

redTeamParticipants = {}

blueTeamParticipants = {}

function teamLength(team) -- return the number of players in team
local count = 0
for _ in pairs(team) do count = count + 1 end
return count
end

function playerJoin(cid) -- try to join player in event
if ableToJoin(cid) then
redTeamParticipantsLength = teamLength(redTeamParticipants)
blueTeamParticipantsLength = teamLength(blueTeamParticipants)
if redTeamParticipantsLength <= blueTeamParticipantsLength then
redTeamParticipants[cid] = true
doPlayerSendTextMessage(cid,22,"Voce foi escolhido para ser do time vermelho.")
doTeleportThing(cid, redTeamSpawn)
else
blueTeamParticipants[cid] = true
doPlayerSendTextMessage(cid,22,"Voce foi escolhido para ser do time azul.")
doTeleportThing(cid, blueTeamSpawn)
end
return TRUE
else
return FALSE
end
end

function playerRemove(cid) -- remove player from event (if its participating)
if isParticipating(cid) then
if redTeamParticipants[cid] == true then
redTeamParticipants[cid] = nil
else
blueTeamParticipants[cid] = nil
end
return TRUE
else
return FALSE
end
end

function isParticipating (cid) -- verify if player is participating of the event
if blueTeamParticipants[cid] == true or redTeamParticipants[cid] == true then
return TRUE
else
return FALSE
end
end

function ableToJoin (cid) -- checks if players are able to join
if isPlayer(cid) and not isParticipating(cid) then
return TRUE
else
return FALSE
end
end

function arePlayersOfSameTeam (cid1, cid2) -- checks if the players are of the same team
if ((blueTeamParticipants[cid1] == true and blueTeamParticipants[cid2] == true) or (redTeamParticipants[cid1] and redTeamParticipants[cid2])) then
return TRUE
else
return FALSE
end
end

function onLogin(cid)
-- checks if it's really a player and if it's only
if isPlayer(cid) then
if isParticipating(cid) == true then
return FALSE -- Ooops! If the script reachs here, we gotta verify what's going wrong
else
if playerJoin(cid) == true then
return TRUE -- everything gone as expected
else
return FALSE -- Ooops! If the script reachs here, we gotta verify what's going wrong
end
end
else
return TRUE
end
end

function onLogout(cid) -- this function is essential to not unbalance the teams
if isParticipating (cid) then
return playerRemove(cid)
end
return TRUE
end

function onAttack(cid, attacker)
-- verify if both are players
if not isPlayer(cid) or not isPlayer(attacker) then return TRUE end

-- are those players participating of the event?
if not isParticipating(cid) or not isParticipating (attacker) then return TRUE end

if arePlayersOfSameTeam(cid, attacker) then
-- a player of the same team cannot attack the other!!
return FALSE
else
return TRUE
end
end

function onStatsChange(cid, attacker, t, combat, value)
-- verify if both are players
if not isPlayer(cid) or not isPlayer(attacker) then return TRUE end

-- verify if both are participating of PVP
if isParticipating(cid) and isParticipating(attacker) then
-- both are participating of event

-- verify if both are of the same team
if arePlayersOfSameTeam(cid, attacker) then
-- they're of the same team. Only heals are acceptable
if t == STATSCHANGE_HEALTHGAIN or t == STATSCHANGE_MANAGAIN then
return TRUE
else
return FALSE
end
else
-- they're not of the same team. Only damages are acceptable
if t == STATSCHANGE_HEALTHGAIN or t == STATSCHANGE_MANAGAIN then
return FALSE
else
return TRUE
end
end
else
-- one or both are not participating of event
return TRUE
end

-- getting
local player1Team = monstersTeam[getCreatureName(cid)]
-- return if it has no team
if player1Team == nil then return TRUE end

-- getting monster that is attacking team
local monster2Team = monstersTeam[getCreatureName(attacker)]
-- return if it has no team
if monster2Team == nil then return TRUE end

-- check if they're of the same team
if monster1Team == monster2Team then
-- if they're of the same team, returning false will not allow the damage to be done to its partner
return FALSE
else
return TRUE
end

return TRUE
end

agora, em "creaturescripts.xml" adicione o seguinte



<event type="attack" name="PvpTeam1" event="script" value="pvpTeam.lua"/>
<event type="statschange" name="PvpTeam2" event="script" value="pvpTeam.lua"/>
<event type="login" name="PvpTeam3" event="script" value="pvpTeam.lua"/>
<event type="logout" name="PvpTeam4" event="script" value="pvpTeam.lua"/>

depois, no arquivo "login.lua" que se encontra em "data\creaturescripts\scripts" adicione



registerCreatureEvent(cid, "PvpTeam1")
registerCreatureEvent(cid, "PvpTeam2")
registerCreatureEvent(cid, "PvpTeam3")
registerCreatureEvent(cid, "PvpTeam4")

Bom, é isso.



Espero ter ajudado.



P.S.: Não me importo que roubem meus créditos e/ou postem em outros fórums.


Link para o comentário
Compartilhar em outros sites

  • 2 weeks later...
×
×
  • Criar Novo...