• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua War system

metiu11

Member
Joined
Mar 26, 2011
Messages
94
Solutions
2
Reaction score
5
Hello, i have script like this, and its works but when i add this script to the server all outfits are changed...
I have 20+ proffesions on server so all of them have unique outfits and this script reset all outfits to "basic", do u have idea how to repair it?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Team Event" version="2.0" author="Damadgerz" contact="[email protected]" enabled="yes">
<description>
Full auto Team BattleEvent(v2.0) for 0.3.6PL1  :
       
        1- I currently rescripted this event from scratch again.

        2- This version is much more better than the one before, it is more cleaner, clearer and with more options.

        3- This version dislike the previous one , was tested on 0.3.6PL1 and works just fine.

        4- Removed the npc part it is now based on tp creation.

        5- More silent boradcasting for in event progress and no spam, I hope!

        6- you now get the options to show event stats on cancel msg area and (to / not to) show left players with names each x interval.

        8- Team balancer have been added to only balance count in both teams.

        9- Added a countdown option before fight starts.

        10- Now starts on a defined time every day
               
   </description>

<config name="teamSetting"><![CDATA[
--[[Local Config]]--

--//storages

inBlue = 9900
inRed = 9901
joiner = 9907

blueKills = 9902
redKills = 9903

eventRecruiting = 9904
eventStarted = 9905
eventTime = 9906

itemToGet = 9908
countItemToGet = 9909

nextExecute = 9910

blueCount = 9911
redCount = 9912
   
--// Positions

teleporterPosition =    {x = 1081, y = 1014, z = 7}                            --Place where the event tp will be created

waitRoomPlace =     {x = 1543, y = 685, z = 7}                                --Place of the waitnig room (the place ppl will wait for team to be full)

waitRoomDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of waitnig room here
                            startPos = {x = 1537, y = 681, z = 7},
                            endPos = {x = 1551, y = 690, z = 7}
                            }
                           

eventPlaceDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of event place here
                            startPos = {x = 1553, y = 660, z = 7},
                            endPos = {x = 1595, y = 704, z = 7}
                            }
blueTeamPos = {x = 1555, y = 684, z = 7}
redTeamPos = {x = 1593, y = 684, z = 7}


--// General settings

recruitTime = 1                                    -- Time in minutes to gather players to event, will broadcast event started each min

minimumPlayersJoins = 2                            --If the number of layer joined is less than that then event would be cancelled

balanceTeams = true                                -- This will balance number of players in both teams the extra player will be kicked out of event


removeTeleportOnEventEnd = true                    -- if you want to remove the tp when the event finish set it to true, normally tp will just be diabled

eventMaxTime = 5                                    -- Time in minutes, this is the max time event will be running. After checks are caried winner is

showEventSats = true                                -- This is like a timer that is always there about event stats (time,oponents left, teammates left). It appears in the cancel messages place.

sendLeftPlayers = true                            -- Well this will send to all alive players the names& numebr of the oponents left each interval defined down          
intervalToSendLeftPlayers = 11                    -- interval(in seconds) to sendLeftPlayers , must be more than 10 sec


countDownOnStart = true                            -- Well this occurs when players are teleported to their places in the arena , so if this is true it start to count down to the joined players then when count down finish they can start killing each other(event really begins)

countDownFrom = 10                                    -- Starts count down from this number when event start, if above is set true            

minJoinLevel = 1500                                    -- minimm lvl that can join event

rewards = {          --Example [%] = {  {itemid/name, count}  ,..........}    count isnt more than 100

                    [65] = { {2160,1} , {"gold coin",500} }
                }
               
            --[[ Note : make sure if you edited % that sum should be equal to 100, you can add more % elements to suit your needs also more items if you want in each %
                    [65],[25],[10] -> is the % of this item to be found the rest is clear ,items in each % and it will be chosen randomly]]--
                                                           
   
]]></config>
<lib name="teamFunctions"><![CDATA[
domodlib('teamSetting')

--[[Conditions don't touch]]--
local bmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bmale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local bfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bfemale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local rmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rmale, {lookType = 656, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local rfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rfemale, {lookType = 656,lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local infight = createConditionObject(CONDITION_INFIGHT,-1)
--[[Local Config]]--

--[[Functions]]--

-- General info
function isFightOn()
    return getStorage(eventStarted) > 0
end
function isRecruitOn()
    return getStorage(eventRecruiting) > 0
end
function getMinJoinLevel()
    return minJoinLevel
end
function getJoiners()
    joiners = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isJoiner(cid) then
            if isInRecruitArea(cid) or isInFightArea(cid) then
                table.insert(joiners,cid)
            end
        end
    end
    return joiners
end

function getLeftMembersNames(team)
    str = "Oponents left("..#team..") :"
    left = ""
    for k,cid in ipairs(team) do left  = (left ..""..(k == 1 and "" or ", ")..""..getCreatureName(cid).."["..getPlayerLevel(cid).."]" ) end
    str = str .." " .. (left == "" and "none" or left).. "."
    return str
end
function disPlayEventStats()
    if not showEventSats then return false end
    if getStorage(eventTime) - os.time() <= 0 then return false end
   
    left = os.date("%M:%S",(getStorage(eventTime) - os.time()))
    for _,cid in ipairs(getJoiners()) do
        oponentsLeft = isBlue(cid) and #getRedMembers() or #getBlueMembers()
        teamMatesLeft = isBlue(cid) and math.max(0,#getBlueMembers()-1) or math.max(0,#getRedMembers()-1)
        doPlayerSendCancel(cid,"Time left: ".. left.."   ||   Oponents left: "..oponentsLeft.."/"..oponentCount(cid).."   ||   Team-mates left: "..teamMatesLeft.."/".. math.max(0,matesCount(cid)-1))
    end
   
end

function doSendLeftPlayers()
    if not sendLeftPlayers then return false end
    if intervalToSendLeftPlayers <= 10 then return false end
    for _,cid in ipairs(getJoiners()) do
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],getLeftMembersNames(isRed(cid) and getBlueMembers() or getRedMembers()))
    end
end

function getBlueMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) then
            table.insert(members,cid)
        end
    end
    return members
end
function getRedMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isRed(cid) then
            table.insert(members,cid)
        end
    end
    return members
end


-- starting fight

function startRecruiting()
    doSetStorage(eventRecruiting,1)
end
function startEvent()
    doSetStorage(eventRecruiting,-1)

    if removeTeleportOnEventEnd then
        tp = getTileItemById(teleporterPosition,1387).uid
        if tp > 0 then doRemoveItem(tp) end
    end
   
    if not balanceTeams() then
        resetEvent()
        return false
    end
    for _,cid in ipairs(getBlueMembers()) do
        doTeleportThing(cid,blueTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setBlueCount(#getBlueMembers())
    for _,cid in ipairs(getRedMembers()) do
        doTeleportThing(cid,redTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setRedCount(#getRedMembers())
    startCountDown()
    return true
end

function setBlueCount(count)
    doSetStorage(blueCount,-1)
    doSetStorage(blueCount,count)
end
function oponentCount(cid)
    return isBlue(cid) and getStorage(redCount) or getStorage(blueCount)
end
function matesCount(cid)
    return isBlue(cid) and getStorage(blueCount) or getStorage(redCount)
end
   
function setRedCount(count)
    doSetStorage(redCount,-1)
    doSetStorage(redCount,count)
end
function balanceTeams()
    members = getJoiners()
    if #members < minimumPlayersJoins then
        doBroadcastMessage("Team-Battle event was cancelled as only ".. #members .. " players joined.")
        return false
    end
    if (math.mod(#members,2) ~= 0) then
        kicked = members[#members]
        clearTeamEventStorages(kicked)
        doPlayerSendTextMessage(kicked,MESSAGE_TYPES["info"],"Sorry, you have been kicked out of event for balancing both teams.")
    end
    count = 1
    for _,cid in ipairs(getJoiners()) do
        if (math.mod(count,2) ~= 0) then
            addToBlue(cid)
        else
            addToRed(cid)
        end
        count = count + 1
    end
    return true
end
function startCountDown()
    if(countDownOnStart) then
        for _,cid in ipairs(getJoiners()) do
            doCreatureSetNoMove(cid,true)
            for i = 0,countDownFrom do
                addEvent(doPlayerSendTextMessage,i*1000, cid, MESSAGE_TYPES["info"], (i == 0 and countDownFrom or countDownFrom-i) )
            end
        end
        addEvent(startFight,(countDownFrom+1)*1000)
    else
        startFight()
    end
end
function startFight()
    doSetStorage(eventStarted,1)
    for _,cid in ipairs(getJoiners()) do
        doCreatureSetNoMove(cid,false)
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],"Fight Starts!")
    end
    addEvent(endTeamEvent,eventMaxTime*60*1000,"maxTime")
    doSetStorage(eventTime,os.time()+eventMaxTime*60)
end

function teleportToWaitRoom(cid)
    doTeleportThing(cid,waitRoomPlace)
    doSendMagicEffect(waitRoomPlace,10)
    if getPlayerGroupId(cid) < 4 then
        addToJoiners(cid)
    end
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"Please be patient till the event starts and don't logout.")
    return true
end
   

   
-- Modifing teams & checking member states
function isBlue(cid)
    return (getPlayerStorageValue(cid,inBlue) > 0)
end
function isRed(cid)
    return (getPlayerStorageValue(cid,inRed) > 0)
end
function isJoiner(cid)
    return (getPlayerStorageValue(cid,joiner) > 0)
end
function addToBlue(cid)
    setPlayerStorageValue(cid,inBlue,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and bmale or bfemale)
    doAddCondition(cid,infight)
end
function addToRed(cid)
    setPlayerStorageValue(cid,inRed,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and rmale or rfemale)
    doAddCondition(cid,infight)
end
function addToJoiners(cid)
    setPlayerStorageValue(cid,joiner,1)
end
function removeFromBlue(cid)
    setPlayerStorageValue(cid,inBlue,-1)
end
function removeFromRed(cid)
    setPlayerStorageValue(cid,inRed,-1)
end
function removeFromjoiners(cid)
    setPlayerStorageValue(cid,joiner,-1)
end
function isInRecruitArea(cid)
    return isInRange(getThingPos(cid),waitRoomDimensions.startPos,waitRoomDimensions.endPos)
end
function isInFightArea(cid)
    return isInRange(getThingPos(cid),eventPlaceDimensions.startPos,eventPlaceDimensions.endPos)
end
function clearTeamEventStorages(cid)
    if isInRecruitArea(cid) or isInFightArea(cid) then
        doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getThingPos(cid),10)
    end
   
    if isFightOn() then
        if isJoiner(cid) then
            if isBlue(cid) then
                addRedKills()
            elseif isRed(cid) then
                addBlueKills()
            end
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"You have died in Team-Battle Event.")
        end
    end
   
    removeFromjoiners(cid)
    removeFromBlue(cid)
    removeFromRed(cid)
    doRemoveConditions(cid, false)

end
function haveUnrecivedReward(cid)
    return getPlayerStorageValue(cid,itemToGet) > 0 and getPlayerStorageValue(cid,countItemToGet) > 0
end
function recieveLateReward(cid)
    if haveUnrecivedReward(cid) then
        if not doPlayerAddItem(cid,getPlayerStorageValue(cid,itemToGet),getPlayerStorageValue(cid,countItemToGet),false) then
            msg = "You need to free some space then relog to take your reward."
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],msg)
        else
            setPlayerStorageValue(cid,itemToGet,-1)
            setPlayerStorageValue(cid,countItemToGet,-1)
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],"You have recieved your reward.")
        end
    end
end

-- Win or lose
function thereIsAWinner()
    if redWon() or blueWon() then
        return true
    end
    return false
end
function blueWon()
    return( (#getBlueMembers() > 0 ) and ( #getRedMembers() == 0) )
end
function redWon()
    return( (#getRedMembers() > 0) and (#getBlueMembers() == 0) )
end
function isDraw()
    return #getBlueMembers() == #getRedMembers()
end
function getWinner()
    if #getBlueMembers() > #getRedMembers() then
        return {getBlueMembers(),getRedMembers(),"Anbu team won."}
    elseif #getRedMembers() > #getBlueMembers() then
        return {getRedMembers(),getBlueMembers(),"Akatsuki team won."}
    else
        return { {},{},"it was a draw."}
    end
end


-- Adding kills
function addBlueKills()
    doSetStorage(blueKills, math.max(1,getStorage(blueKills)+1))
end
function addRedKills()
    doSetStorage(redKills, math.max(1,getStorage(redKills)+1))
end

-- Ending event

function endTeamEvent(type)
    if isFightOn() then
        doSetStorage(eventStarted,-1)
        doBroadcastMessage("Team-Battle event ended and "..getWinner()[3])
        if not isDraw() then
            win(getWinner()[1],type)
            lose(getWinner()[2],type)
        else
            draw()
        end
    end
    addEvent(resetEvent,2 * 1000)  --- tp player to home remove all storages and reset event global storages
end

function getPercent()
    rand= math.random(1,100)
    prev = 0
    chosenItem = 0
    for k, v in pairs(rewards) do
        if rand > prev and rand <= k+prev then
            chosenItem = k
            break
        else
            prev =  k+prev
        end
    end
    return chosenItem
end
   
function generateReward(cid)
    percent = getPercent()
    if percent == 0 then
        print("Error in the reward item. Please inform Doggynub.")
        return true
    end
   
    randomizer = rewards[percent][math.random(1,#rewards[percent])]
    item = not tonumber(randomizer[1]) and getItemIdByName(randomizer[1]) or randomizer[1]
    count = isItemStackable(item) and math.min(randomizer[2],100) or 1
    if item == nil or item == 0 then
        print("Error in the  item format. Please inform Doggynub.")
        return true
    end
   
    msg = "You have won ".. (count == 1 and "a" or count) .." " .. getItemNameById(item) .. "" .. (count == 1 and "" or "s").."."
   
    if not doPlayerAddItem(cid,item,count,false) then
        msg = msg.. "You need to free some space then relog to take your reward."
        setPlayerStorageValue(cid,itemToGet,item)
        setPlayerStorageValue(cid,countItemToGet,count)
    end
   
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["white"],msg)
   
end



function generateStatsMessage(cid, type, stats)
    msg = {
                    ["KO"] = {     ["win"] = "Event ended. Your team have won by killing all oponent's team members. You will recieve your reward shortly, check incoming messages.",
                                ["lose"] = "Event ended. Your team have lost as the Oponent team killed all your team's members."
                            },
                    ["maxTime"] = {
                                    ["win"] = "Event max-time finished and your team have won. You will recieve your reward shortly, check incoming messages.",
                                    ["lose"] = "Event max-time finished and your team have lost.",
                                    ["draw"] = "Event max-time finished and it is a draw.(no team won)"
                                }
                }
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],msg[type][stats])
   
end
function win(winners,type)
    for _,cid in ipairs(winners) do
        generateStatsMessage(cid, type, "win")
        generateReward(cid)
    end
end
function lose(losers,type)
    for _,cid in ipairs(losers) do
        generateStatsMessage(cid, type, "lose")
    end
end
function draw()
    for _,cid in ipairs(getJoiners()) do
        generateStatsMessage(cid, "maxTime", "draw")
    end
end

function resetEvent()
    doSetStorage(eventRecruiting,-1)
    doSetStorage(nextExecute,-1)
    doSetStorage(eventStarted,-1)
    doSetStorage(eventTime,-1)
    doSetStorage(blueKills,-1)
    doSetStorage(redKills,-1)
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) or isRed(cid) or isJoiner(cid) then
            clearTeamEventStorages(cid)
        end
    end
end


]]></lib>
<event type="login" name="teambattleLogin" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogin(cid)
    clearTeamEventStorages(cid)
    recieveLateReward(cid)
       
    registerCreatureEvent(cid, "teamEventStats")
    registerCreatureEvent(cid, "teambattleLogout")
    registerCreatureEvent(cid, "teambattleCombat")
    return true
end
]]></event>
<event type="combat" name="teambattleCombat" event="script"><![CDATA[
domodlib('teamFunctions')

function onCombat(cid, target)
    if isFightOn() then
        if isBlue(cid) and isBlue(target) then
            return false
        end
        if isRed(cid) and isRed(target) then
            return false
        end
    end
    return true
end

]]></event>
<event type="logout" name="teambattleLogout" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogout(cid)
    clearTeamEventStorages(cid)
    if thereIsAWinner() then
        endTeamEvent("KO")
    end
    return true
end

]]></event>
<event type="statschange" name="teamEventStats" event="script"><![CDATA[
domodlib('teamFunctions')

corpse_ids = {
        [0] = 3065, -- female
        [1] = 3058 -- male
}
function onStatsChange(cid, attacker, type, combat, value)
    if combat == COMBAT_HEALING then
        return true
    end
    if getCreatureHealth(cid) > value then
        return true
    end
   
    if isInFightArea(cid) and isFightOn() then
        if isBlue(cid) or isRed(cid) then
            corpse = doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid))
            doCreateItem(2016, 2, getThingPos(cid))
            clearTeamEventStorages(cid)
            doItemSetAttribute(corpse, "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".n[Team-Event kill]")
            doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
            if thereIsAWinner() then
                endTeamEvent("KO")
            end
           
            return false
       
        end
   
    end

    return true
end
]]></event>

<globalevent name = "teamBattleStart" time="18:30" event="script"><![CDATA[
domodlib('teamFunctions')

function onTimer()
    resetEvent()
    if getTileItemById(teleporterPosition,1387).uid < 1 then
        tp = doCreateItem(1387,1,teleporterPosition)
        doItemSetAttribute(tp, "aid", 9990)
    end
   
    startRecruiting()
    for i = 0, recruitTime-1 do
        addEvent(doBroadcastMessage, i * 60* 1000,"Team-Battle event is recruting players by entering event tp. Fight begins in "..(i == 0 and recruitTime or recruitTime-i).." minutes.",MESSAGE_TYPES["warning"])
    end

    addEvent(startEvent, recruitTime * 60 * 1000)
   
    return true
end


]]></globalevent>

<globalevent name = "teamBattletime" interval="1" event="script"><![CDATA[
domodlib('teamFunctions')

function onThink()
    if isFightOn() then
        disPlayEventStats()
   
        if getStorage(nextExecute) == -1 or getStorage(nextExecute) <= os.time() then
            doSendLeftPlayers()
            doSetStorage(nextExecute,os.time()+intervalToSendLeftPlayers)
        end
    end
    return true
end

]]></globalevent>
<movevent type="StepIn" actionid="9990" event="script"><![CDATA[
domodlib('teamFunctions')

function onStepIn(cid, item, position, fromPosition)
    if not isRecruitOn() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Event isn't currently opened.")
        doTeleportThing(cid,fromPosition)
        doSendMagicEffect(fromPosition,2)
        return true
    end
    if getPlayerLevel(cid) < getMinJoinLevel() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Only players of level ".. getMinJoinLevel().. "+ can join this event.")
        doTeleportThing(cid,fromPosition)
        return true
    end
    teleportToWaitRoom(cid)
    return true
end


]]> </movevent>
</mod>
 
Last edited:
Solution
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Team Event" version="2.0" author="Damadgerz" contact="[email protected]" enabled="yes">
<description>
Full auto Team BattleEvent(v2.0) for 0.3.6PL1  :
    
        1- I currently rescripted this event from scratch again.

        2- This version is much more better than the one before, it is more cleaner, clearer and with more options.

        3- This version dislike the previous one , was tested on 0.3.6PL1 and works just fine.

        4- Removed the npc part it is now based on tp creation.

        5- More silent boradcasting for in event progress and no spam, I hope!

        6- you now get the options to show event stats on cancel msg area and (to / not to) show left players...
I have a script transformation that changes the character outfit. Is it possible that they collide with each other?
Duplication of storage can also affect this?
Ding dong! Have no idea how to repair it...
 
Last edited:
Cool i found code which reset outfits
Code:
    doRemoveConditions(cid, false)
When i remove it players get special outfit from event and dont reset when event end...
If player relog then his outfit will reset to correctly
Someone have idea how to reset outfits after event?
 
Cool i found code which reset outfits
Code:
    doRemoveConditions(cid, false)
When i remove it players get special outfit from event and dont reset when event end...
If player relog then his outfit will reset to correctly
Someone have idea how to reset outfits after event?
Hello,
I think u can create a Global Table, when player enters in event, insert a element in cid index table like:
Lua:
MyGlobalTable[cid] = getCreatureOutfit(cid)
And when finish the event, u load back the outfit to player and exclude the element from the table.
Lua:
doCreatureChangeOutfit(cid, MyGlobalTable[cid])
Don't know if im using right functions, i don't use 0.X versions for a long time... But i think this will work.
Good Luck.
 
@zxmatzx something wrong.... I dont understand what u mean about global table. I just add first line to my locals and add second line after
Code:
removeFromjoiners(cid)
    removeFromBlue(cid)
    removeFromRed(cid)

EDIT:
I am thinking what u mean and i have some idea.
So i can use
getCreatureOutfit(cid)
before them inside event and then
doCreatureChangeOutfit
but i still dont understand where my script save outfits and how to give them back with function
doCreatureChangeOutfit
 
Last edited:
@zxmatzx something wrong.... I dont understand what u mean about global table. I just add first line to my locals and add second line after
Code:
removeFromjoiners(cid)
    removeFromBlue(cid)
    removeFromRed(cid)

EDIT:
I am thinking what u mean and i have some idea.
So i can use
getCreatureOutfit(cid)
before them inside event and then
doCreatureChangeOutfit
but i still dont understand where my script save outfits and how to give them back with function
doCreatureChangeOutfit
Create a file in your lib folder TeamEventOutfitsTable.lua.
Lua:
TeamEventOutfits = {}
In you global.lua add:
Lua:
dofile('data/lib/TeamEventOutfitsTable.lua')
Change u code for this:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Team Event" version="2.0" author="Damadgerz" contact="[email protected]" enabled="yes">
<description>
Full auto Team BattleEvent(v2.0) for 0.3.6PL1  :
      
        1- I currently rescripted this event from scratch again.

        2- This version is much more better than the one before, it is more cleaner, clearer and with more options.

        3- This version dislike the previous one , was tested on 0.3.6PL1 and works just fine.

        4- Removed the npc part it is now based on tp creation.

        5- More silent boradcasting for in event progress and no spam, I hope!

        6- you now get the options to show event stats on cancel msg area and (to / not to) show left players with names each x interval.

        8- Team balancer have been added to only balance count in both teams.

        9- Added a countdown option before fight starts.

        10- Now starts on a defined time every day
              
   </description>

<config name="teamSetting"><![CDATA[
--[[Local Config]]--

--//storages

inBlue = 9900
inRed = 9901
joiner = 9907

blueKills = 9902
redKills = 9903

eventRecruiting = 9904
eventStarted = 9905
eventTime = 9906

itemToGet = 9908
countItemToGet = 9909

nextExecute = 9910

blueCount = 9911
redCount = 9912
  
--// Positions

teleporterPosition =    {x = 1081, y = 1014, z = 7}                            --Place where the event tp will be created

waitRoomPlace =     {x = 1543, y = 685, z = 7}                                --Place of the waitnig room (the place ppl will wait for team to be full)

waitRoomDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of waitnig room here
                            startPos = {x = 1537, y = 681, z = 7},
                            endPos = {x = 1551, y = 690, z = 7}
                            }
                          

eventPlaceDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of event place here
                            startPos = {x = 1553, y = 660, z = 7},
                            endPos = {x = 1595, y = 704, z = 7}
                            }
blueTeamPos = {x = 1555, y = 684, z = 7}
redTeamPos = {x = 1593, y = 684, z = 7}


--// General settings

recruitTime = 1                                    -- Time in minutes to gather players to event, will broadcast event started each min

minimumPlayersJoins = 2                            --If the number of layer joined is less than that then event would be cancelled

balanceTeams = true                                -- This will balance number of players in both teams the extra player will be kicked out of event


removeTeleportOnEventEnd = true                    -- if you want to remove the tp when the event finish set it to true, normally tp will just be diabled

eventMaxTime = 5                                    -- Time in minutes, this is the max time event will be running. After checks are caried winner is

showEventSats = true                                -- This is like a timer that is always there about event stats (time,oponents left, teammates left). It appears in the cancel messages place.

sendLeftPlayers = true                            -- Well this will send to all alive players the names& numebr of the oponents left each interval defined down         
intervalToSendLeftPlayers = 11                    -- interval(in seconds) to sendLeftPlayers , must be more than 10 sec


countDownOnStart = true                            -- Well this occurs when players are teleported to their places in the arena , so if this is true it start to count down to the joined players then when count down finish they can start killing each other(event really begins)

countDownFrom = 10                                    -- Starts count down from this number when event start, if above is set true           

minJoinLevel = 1500                                    -- minimm lvl that can join event

rewards = {          --Example [%] = {  {itemid/name, count}  ,..........}    count isnt more than 100

                    [65] = { {2160,1} , {"gold coin",500} }
                }
              
            --[[ Note : make sure if you edited % that sum should be equal to 100, you can add more % elements to suit your needs also more items if you want in each %
                    [65],[25],[10] -> is the % of this item to be found the rest is clear ,items in each % and it will be chosen randomly]]--
                                                          
  
]]></config>
<lib name="teamFunctions"><![CDATA[
domodlib('teamSetting')

--[[Conditions don't touch]]--
local bmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bmale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local bfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bfemale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local rmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rmale, {lookType = 656, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local rfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rfemale, {lookType = 656,lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local infight = createConditionObject(CONDITION_INFIGHT,-1)
--[[Local Config]]--

--[[Functions]]--

-- General info
function isFightOn()
    return getStorage(eventStarted) > 0
end
function isRecruitOn()
    return getStorage(eventRecruiting) > 0
end
function getMinJoinLevel()
    return minJoinLevel
end
function getJoiners()
    joiners = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isJoiner(cid) then
            if isInRecruitArea(cid) or isInFightArea(cid) then
                table.insert(joiners,cid)
            end
        end
    end
    return joiners
end

function getLeftMembersNames(team)
    str = "Oponents left("..#team..") :"
    left = ""
    for k,cid in ipairs(team) do left  = (left ..""..(k == 1 and "" or ", ")..""..getCreatureName(cid).."["..getPlayerLevel(cid).."]" ) end
    str = str .." " .. (left == "" and "none" or left).. "."
    return str
end
function disPlayEventStats()
    if not showEventSats then return false end
    if getStorage(eventTime) - os.time() <= 0 then return false end
  
    left = os.date("%M:%S",(getStorage(eventTime) - os.time()))
    for _,cid in ipairs(getJoiners()) do
        oponentsLeft = isBlue(cid) and #getRedMembers() or #getBlueMembers()
        teamMatesLeft = isBlue(cid) and math.max(0,#getBlueMembers()-1) or math.max(0,#getRedMembers()-1)
        doPlayerSendCancel(cid,"Time left: ".. left.."   ||   Oponents left: "..oponentsLeft.."/"..oponentCount(cid).."   ||   Team-mates left: "..teamMatesLeft.."/".. math.max(0,matesCount(cid)-1))
    end
  
end

function doSendLeftPlayers()
    if not sendLeftPlayers then return false end
    if intervalToSendLeftPlayers <= 10 then return false end
    for _,cid in ipairs(getJoiners()) do
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],getLeftMembersNames(isRed(cid) and getBlueMembers() or getRedMembers()))
    end
end

function getBlueMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) then
            table.insert(members,cid)
        end
    end
    return members
end
function getRedMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isRed(cid) then
            table.insert(members,cid)
        end
    end
    return members
end


-- starting fight

function startRecruiting()
    doSetStorage(eventRecruiting,1)
end
function startEvent()
    doSetStorage(eventRecruiting,-1)
    
    TeamEventOutfits = {}--Clear the global table, to erase old data

    if removeTeleportOnEventEnd then
        tp = getTileItemById(teleporterPosition,1387).uid
        if tp > 0 then doRemoveItem(tp) end
    end
  
    if not balanceTeams() then
        resetEvent()
        return false
    end
    for _,cid in ipairs(getBlueMembers()) do
        doTeleportThing(cid,blueTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setBlueCount(#getBlueMembers())
    for _,cid in ipairs(getRedMembers()) do
        doTeleportThing(cid,redTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setRedCount(#getRedMembers())
    startCountDown()
    return true
end

function setBlueCount(count)
    doSetStorage(blueCount,-1)
    doSetStorage(blueCount,count)
end
function oponentCount(cid)
    return isBlue(cid) and getStorage(redCount) or getStorage(blueCount)
end
function matesCount(cid)
    return isBlue(cid) and getStorage(blueCount) or getStorage(redCount)
end
  
function setRedCount(count)
    doSetStorage(redCount,-1)
    doSetStorage(redCount,count)
end
function balanceTeams()
    members = getJoiners()
    if #members < minimumPlayersJoins then
        doBroadcastMessage("Team-Battle event was cancelled as only ".. #members .. " players joined.")
        return false
    end
    if (math.mod(#members,2) ~= 0) then
        kicked = members[#members]
        clearTeamEventStorages(kicked)
        doPlayerSendTextMessage(kicked,MESSAGE_TYPES["info"],"Sorry, you have been kicked out of event for balancing both teams.")
    end
    count = 1
    for _,cid in ipairs(getJoiners()) do
        TeamEventOutfits[cid] = getCreatureOutfit(cid)--Get outfit player is using before change to red or blue
        if (math.mod(count,2) ~= 0) then
            addToBlue(cid)
        else
            addToRed(cid)
        end
        count = count + 1
    end
    return true
end
function startCountDown()
    if(countDownOnStart) then
        for _,cid in ipairs(getJoiners()) do
            doCreatureSetNoMove(cid,true)
            for i = 0,countDownFrom do
                addEvent(doPlayerSendTextMessage,i*1000, cid, MESSAGE_TYPES["info"], (i == 0 and countDownFrom or countDownFrom-i) )
            end
        end
        addEvent(startFight,(countDownFrom+1)*1000)
    else
        startFight()
    end
end
function startFight()
    doSetStorage(eventStarted,1)
    for _,cid in ipairs(getJoiners()) do
        doCreatureSetNoMove(cid,false)
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],"Fight Starts!")
        
    end
    addEvent(endTeamEvent,eventMaxTime*60*1000,"maxTime")
    doSetStorage(eventTime,os.time()+eventMaxTime*60)
end

function teleportToWaitRoom(cid)
    doTeleportThing(cid,waitRoomPlace)
    doSendMagicEffect(waitRoomPlace,10)
    if getPlayerGroupId(cid) < 4 then
        addToJoiners(cid)
    end
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"Please be patient till the event starts and don't logout.")
    return true
end
  

  
-- Modifing teams & checking member states
function isBlue(cid)
    return (getPlayerStorageValue(cid,inBlue) > 0)
end
function isRed(cid)
    return (getPlayerStorageValue(cid,inRed) > 0)
end
function isJoiner(cid)
    return (getPlayerStorageValue(cid,joiner) > 0)
end
function addToBlue(cid)
    setPlayerStorageValue(cid,inBlue,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and bmale or bfemale)
    doAddCondition(cid,infight)
end
function addToRed(cid)
    setPlayerStorageValue(cid,inRed,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and rmale or rfemale)
    doAddCondition(cid,infight)
end
function addToJoiners(cid)
    setPlayerStorageValue(cid,joiner,1)
end
function removeFromBlue(cid)
    setPlayerStorageValue(cid,inBlue,-1)
end
function removeFromRed(cid)
    setPlayerStorageValue(cid,inRed,-1)
end
function removeFromjoiners(cid)
    setPlayerStorageValue(cid,joiner,-1)
end
function isInRecruitArea(cid)
    return isInRange(getThingPos(cid),waitRoomDimensions.startPos,waitRoomDimensions.endPos)
end
function isInFightArea(cid)
    return isInRange(getThingPos(cid),eventPlaceDimensions.startPos,eventPlaceDimensions.endPos)
end
function clearTeamEventStorages(cid)
    if isInRecruitArea(cid) or isInFightArea(cid) then
        doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getThingPos(cid),10)
    end
  
    if isFightOn() then
        if isJoiner(cid) then
            if isBlue(cid) then
                addRedKills()
            elseif isRed(cid) then
                addBlueKills()
            end
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"You have died in Team-Battle Event.")
        end
    end
  
    removeFromjoiners(cid)
    removeFromBlue(cid)
    removeFromRed(cid)
    doRemoveConditions(cid, false)

end
function haveUnrecivedReward(cid)
    return getPlayerStorageValue(cid,itemToGet) > 0 and getPlayerStorageValue(cid,countItemToGet) > 0
end
function recieveLateReward(cid)
    if haveUnrecivedReward(cid) then
        if not doPlayerAddItem(cid,getPlayerStorageValue(cid,itemToGet),getPlayerStorageValue(cid,countItemToGet),false) then
            msg = "You need to free some space then relog to take your reward."
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],msg)
        else
            setPlayerStorageValue(cid,itemToGet,-1)
            setPlayerStorageValue(cid,countItemToGet,-1)
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],"You have recieved your reward.")
        end
    end
end

-- Win or lose
function thereIsAWinner()
    if redWon() or blueWon() then
        return true
    end
    return false
end
function blueWon()
    return( (#getBlueMembers() > 0 ) and ( #getRedMembers() == 0) )
end
function redWon()
    return( (#getRedMembers() > 0) and (#getBlueMembers() == 0) )
end
function isDraw()
    return #getBlueMembers() == #getRedMembers()
end
function getWinner()
    if #getBlueMembers() > #getRedMembers() then
        return {getBlueMembers(),getRedMembers(),"Anbu team won."}
    elseif #getRedMembers() > #getBlueMembers() then
        return {getRedMembers(),getBlueMembers(),"Akatsuki team won."}
    else
        return { {},{},"it was a draw."}
    end
end


-- Adding kills
function addBlueKills()
    doSetStorage(blueKills, math.max(1,getStorage(blueKills)+1))
end
function addRedKills()
    doSetStorage(redKills, math.max(1,getStorage(redKills)+1))
end

-- Ending event

function endTeamEvent(type)
    if isFightOn() then
        doSetStorage(eventStarted,-1)
        doBroadcastMessage("Team-Battle event ended and "..getWinner()[3])
        if not isDraw() then
            win(getWinner()[1],type)
            lose(getWinner()[2],type)
        else
            draw()
        end
    end
    addEvent(resetEvent,2 * 1000)  --- tp player to home remove all storages and reset event global storages
end

function getPercent()
    rand= math.random(1,100)
    prev = 0
    chosenItem = 0
    for k, v in pairs(rewards) do
        if rand > prev and rand <= k+prev then
            chosenItem = k
            break
        else
            prev =  k+prev
        end
    end
    return chosenItem
end
  
function generateReward(cid)
    percent = getPercent()
    if percent == 0 then
        print("Error in the reward item. Please inform Doggynub.")
        return true
    end
  
    randomizer = rewards[percent][math.random(1,#rewards[percent])]
    item = not tonumber(randomizer[1]) and getItemIdByName(randomizer[1]) or randomizer[1]
    count = isItemStackable(item) and math.min(randomizer[2],100) or 1
    if item == nil or item == 0 then
        print("Error in the  item format. Please inform Doggynub.")
        return true
    end
  
    msg = "You have won ".. (count == 1 and "a" or count) .." " .. getItemNameById(item) .. "" .. (count == 1 and "" or "s").."."
  
    if not doPlayerAddItem(cid,item,count,false) then
        msg = msg.. "You need to free some space then relog to take your reward."
        setPlayerStorageValue(cid,itemToGet,item)
        setPlayerStorageValue(cid,countItemToGet,count)
    end
  
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["white"],msg)
  
end



function generateStatsMessage(cid, type, stats)
    msg = {
                    ["KO"] = {     ["win"] = "Event ended. Your team have won by killing all oponent's team members. You will recieve your reward shortly, check incoming messages.",
                                ["lose"] = "Event ended. Your team have lost as the Oponent team killed all your team's members."
                            },
                    ["maxTime"] = {
                                    ["win"] = "Event max-time finished and your team have won. You will recieve your reward shortly, check incoming messages.",
                                    ["lose"] = "Event max-time finished and your team have lost.",
                                    ["draw"] = "Event max-time finished and it is a draw.(no team won)"
                                }
                }
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],msg[type][stats])
  
end
function win(winners,type)
    for _,cid in ipairs(winners) do
        generateStatsMessage(cid, type, "win")
        generateReward(cid)
    end
end
function lose(losers,type)
    for _,cid in ipairs(losers) do
        generateStatsMessage(cid, type, "lose")
    end
end
function draw()
    for _,cid in ipairs(getJoiners()) do
        generateStatsMessage(cid, "maxTime", "draw")
    end
end

function resetEvent()
    doSetStorage(eventRecruiting,-1)
    doSetStorage(nextExecute,-1)
    doSetStorage(eventStarted,-1)
    doSetStorage(eventTime,-1)
    doSetStorage(blueKills,-1)
    doSetStorage(redKills,-1)
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) or isRed(cid) or isJoiner(cid) then
            doCreatureChangeOutfit(cid, TeamEventOutfits[cid])--Give back outfit for player
            clearTeamEventStorages(cid)
        end
    end
end


]]></lib>
<event type="login" name="teambattleLogin" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogin(cid)
    clearTeamEventStorages(cid)
    recieveLateReward(cid)
      
    registerCreatureEvent(cid, "teamEventStats")
    registerCreatureEvent(cid, "teambattleLogout")
    registerCreatureEvent(cid, "teambattleCombat")
    return true
end
]]></event>
<event type="combat" name="teambattleCombat" event="script"><![CDATA[
domodlib('teamFunctions')

function onCombat(cid, target)
    if isFightOn() then
        if isBlue(cid) and isBlue(target) then
            return false
        end
        if isRed(cid) and isRed(target) then
            return false
        end
    end
    return true
end

]]></event>
<event type="logout" name="teambattleLogout" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogout(cid)
    clearTeamEventStorages(cid)
    if thereIsAWinner() then
        endTeamEvent("KO")
    end
    return true
end

]]></event>
<event type="statschange" name="teamEventStats" event="script"><![CDATA[
domodlib('teamFunctions')

corpse_ids = {
        [0] = 3065, -- female
        [1] = 3058 -- male
}
function onStatsChange(cid, attacker, type, combat, value)
    if combat == COMBAT_HEALING then
        return true
    end
    if getCreatureHealth(cid) > value then
        return true
    end
  
    if isInFightArea(cid) and isFightOn() then
        if isBlue(cid) or isRed(cid) then
            corpse = doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid))
            doCreateItem(2016, 2, getThingPos(cid))
            clearTeamEventStorages(cid)
            doItemSetAttribute(corpse, "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".n[Team-Event kill]")
            doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
            if thereIsAWinner() then
                endTeamEvent("KO")
            end
          
            return false
      
        end
  
    end

    return true
end
]]></event>

<globalevent name = "teamBattleStart" time="18:30" event="script"><![CDATA[
domodlib('teamFunctions')

function onTimer()
    resetEvent()
    if getTileItemById(teleporterPosition,1387).uid < 1 then
        tp = doCreateItem(1387,1,teleporterPosition)
        doItemSetAttribute(tp, "aid", 9990)
    end
  
    startRecruiting()
    for i = 0, recruitTime-1 do
        addEvent(doBroadcastMessage, i * 60* 1000,"Team-Battle event is recruting players by entering event tp. Fight begins in "..(i == 0 and recruitTime or recruitTime-i).." minutes.",MESSAGE_TYPES["warning"])
    end

    addEvent(startEvent, recruitTime * 60 * 1000)
  
    return true
end


]]></globalevent>

<globalevent name = "teamBattletime" interval="1" event="script"><![CDATA[
domodlib('teamFunctions')

function onThink()
    if isFightOn() then
        disPlayEventStats()
  
        if getStorage(nextExecute) == -1 or getStorage(nextExecute) <= os.time() then
            doSendLeftPlayers()
            doSetStorage(nextExecute,os.time()+intervalToSendLeftPlayers)
        end
    end
    return true
end

]]></globalevent>
<movevent type="StepIn" actionid="9990" event="script"><![CDATA[
domodlib('teamFunctions')

function onStepIn(cid, item, position, fromPosition)
    if not isRecruitOn() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Event isn't currently opened.")
        doTeleportThing(cid,fromPosition)
        doSendMagicEffect(fromPosition,2)
        return true
    end
    if getPlayerLevel(cid) < getMinJoinLevel() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Only players of level ".. getMinJoinLevel().. "+ can join this event.")
        doTeleportThing(cid,fromPosition)
        return true
    end
    teleportToWaitRoom(cid)
    return true
end


]]> </movevent>
</mod>

I think this will work, i can't test. Don't have 0.x server to do that...
Changes in line 208, 261, 519
 
@zxmatzx Hmm i got this error and the winner didnt back to city. but player which dead back to the normal outfit.
Second problem: All players got bad basic outfits
Code:
[05/06/2019 21:07:27] In a timer event called from:
[05/06/2019 21:07:27] buffer:onStatsChange
[05/06/2019 21:07:27] Description:
[05/06/2019 21:07:27] attempt to index a nil value
[05/06/2019 21:07:27] stack traceback:
[05/06/2019 21:07:27]     [C]: in function 'doCreatureChangeOutfit'
[05/06/2019 21:07:27]     [string "domodlib('teamSetting')..."]:414: in function <[string "domodlib('teamSetting')..."]:405>
 
Last edited:
Try now:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Team Event" version="2.0" author="Damadgerz" contact="[email protected]" enabled="yes">
<description>
Full auto Team BattleEvent(v2.0) for 0.3.6PL1  :
      
        1- I currently rescripted this event from scratch again.

        2- This version is much more better than the one before, it is more cleaner, clearer and with more options.

        3- This version dislike the previous one , was tested on 0.3.6PL1 and works just fine.

        4- Removed the npc part it is now based on tp creation.

        5- More silent boradcasting for in event progress and no spam, I hope!

        6- you now get the options to show event stats on cancel msg area and (to / not to) show left players with names each x interval.

        8- Team balancer have been added to only balance count in both teams.

        9- Added a countdown option before fight starts.

        10- Now starts on a defined time every day
              
   </description>

<config name="teamSetting"><![CDATA[
--[[Local Config]]--

--//storages

inBlue = 9900
inRed = 9901
joiner = 9907

blueKills = 9902
redKills = 9903

eventRecruiting = 9904
eventStarted = 9905
eventTime = 9906

itemToGet = 9908
countItemToGet = 9909

nextExecute = 9910

blueCount = 9911
redCount = 9912
 
--// Positions

teleporterPosition =    {x = 1081, y = 1014, z = 7}                            --Place where the event tp will be created

waitRoomPlace =     {x = 1543, y = 685, z = 7}                                --Place of the waitnig room (the place ppl will wait for team to be full)

waitRoomDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of waitnig room here
                            startPos = {x = 1537, y = 681, z = 7},
                            endPos = {x = 1551, y = 690, z = 7}
                            }
                          

eventPlaceDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of event place here
                            startPos = {x = 1553, y = 660, z = 7},
                            endPos = {x = 1595, y = 704, z = 7}
                            }
blueTeamPos = {x = 1555, y = 684, z = 7}
redTeamPos = {x = 1593, y = 684, z = 7}


--// General settings

recruitTime = 1                                    -- Time in minutes to gather players to event, will broadcast event started each min

minimumPlayersJoins = 2                            --If the number of layer joined is less than that then event would be cancelled

balanceTeams = true                                -- This will balance number of players in both teams the extra player will be kicked out of event


removeTeleportOnEventEnd = true                    -- if you want to remove the tp when the event finish set it to true, normally tp will just be diabled

eventMaxTime = 5                                    -- Time in minutes, this is the max time event will be running. After checks are caried winner is

showEventSats = true                                -- This is like a timer that is always there about event stats (time,oponents left, teammates left). It appears in the cancel messages place.

sendLeftPlayers = true                            -- Well this will send to all alive players the names& numebr of the oponents left each interval defined down         
intervalToSendLeftPlayers = 11                    -- interval(in seconds) to sendLeftPlayers , must be more than 10 sec


countDownOnStart = true                            -- Well this occurs when players are teleported to their places in the arena , so if this is true it start to count down to the joined players then when count down finish they can start killing each other(event really begins)

countDownFrom = 10                                    -- Starts count down from this number when event start, if above is set true           

minJoinLevel = 1500                                    -- minimm lvl that can join event

rewards = {          --Example [%] = {  {itemid/name, count}  ,..........}    count isnt more than 100

                    [65] = { {2160,1} , {"gold coin",500} }
                }
              
            --[[ Note : make sure if you edited % that sum should be equal to 100, you can add more % elements to suit your needs also more items if you want in each %
                    [65],[25],[10] -> is the % of this item to be found the rest is clear ,items in each % and it will be chosen randomly]]--
                                                          
 
]]></config>
<lib name="teamFunctions"><![CDATA[
domodlib('teamSetting')

--[[Conditions don't touch]]--
local bmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bmale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local bfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bfemale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local rmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rmale, {lookType = 656, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local rfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rfemale, {lookType = 656,lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local infight = createConditionObject(CONDITION_INFIGHT,-1)
--[[Local Config]]--

--[[Functions]]--

-- General info
function isFightOn()
    return getStorage(eventStarted) > 0
end
function isRecruitOn()
    return getStorage(eventRecruiting) > 0
end
function getMinJoinLevel()
    return minJoinLevel
end
function getJoiners()
    joiners = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isJoiner(cid) then
            if isInRecruitArea(cid) or isInFightArea(cid) then
                table.insert(joiners,cid)
            end
        end
    end
    return joiners
end

function getLeftMembersNames(team)
    str = "Oponents left("..#team..") :"
    left = ""
    for k,cid in ipairs(team) do left  = (left ..""..(k == 1 and "" or ", ")..""..getCreatureName(cid).."["..getPlayerLevel(cid).."]" ) end
    str = str .." " .. (left == "" and "none" or left).. "."
    return str
end
function disPlayEventStats()
    if not showEventSats then return false end
    if getStorage(eventTime) - os.time() <= 0 then return false end
 
    left = os.date("%M:%S",(getStorage(eventTime) - os.time()))
    for _,cid in ipairs(getJoiners()) do
        oponentsLeft = isBlue(cid) and #getRedMembers() or #getBlueMembers()
        teamMatesLeft = isBlue(cid) and math.max(0,#getBlueMembers()-1) or math.max(0,#getRedMembers()-1)
        doPlayerSendCancel(cid,"Time left: ".. left.."   ||   Oponents left: "..oponentsLeft.."/"..oponentCount(cid).."   ||   Team-mates left: "..teamMatesLeft.."/".. math.max(0,matesCount(cid)-1))
    end
 
end

function doSendLeftPlayers()
    if not sendLeftPlayers then return false end
    if intervalToSendLeftPlayers <= 10 then return false end
    for _,cid in ipairs(getJoiners()) do
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],getLeftMembersNames(isRed(cid) and getBlueMembers() or getRedMembers()))
    end
end

function getBlueMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) then
            table.insert(members,cid)
        end
    end
    return members
end
function getRedMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isRed(cid) then
            table.insert(members,cid)
        end
    end
    return members
end


-- starting fight

function startRecruiting()
    doSetStorage(eventRecruiting,1)
end
function startEvent()
    doSetStorage(eventRecruiting,-1)
    
    TeamEventOutfits = {}--Clear the global table, to erase old data

    if removeTeleportOnEventEnd then
        tp = getTileItemById(teleporterPosition,1387).uid
        if tp > 0 then doRemoveItem(tp) end
    end
 
    if not balanceTeams() then
        resetEvent()
        return false
    end
    for _,cid in ipairs(getBlueMembers()) do
        doTeleportThing(cid,blueTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setBlueCount(#getBlueMembers())
    for _,cid in ipairs(getRedMembers()) do
        doTeleportThing(cid,redTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setRedCount(#getRedMembers())
    startCountDown()
    return true
end

function setBlueCount(count)
    doSetStorage(blueCount,-1)
    doSetStorage(blueCount,count)
end
function oponentCount(cid)
    return isBlue(cid) and getStorage(redCount) or getStorage(blueCount)
end
function matesCount(cid)
    return isBlue(cid) and getStorage(blueCount) or getStorage(redCount)
end
 
function setRedCount(count)
    doSetStorage(redCount,-1)
    doSetStorage(redCount,count)
end
function balanceTeams()
    members = getJoiners()
    if #members < minimumPlayersJoins then
        doBroadcastMessage("Team-Battle event was cancelled as only ".. #members .. " players joined.")
        return false
    end
    if (math.mod(#members,2) ~= 0) then
        kicked = members[#members]
        clearTeamEventStorages(kicked)
        doPlayerSendTextMessage(kicked,MESSAGE_TYPES["info"],"Sorry, you have been kicked out of event for balancing both teams.")
    end
    count = 1
    for _,cid in ipairs(getJoiners()) do
        TeamEventOutfits[cid] = getCreatureOutfit(cid)--Get outfit player is using before change to red or blue
        if (math.mod(count,2) ~= 0) then
            addToBlue(cid)
        else
            addToRed(cid)
        end
        count = count + 1
    end
    return true
end
function startCountDown()
    if(countDownOnStart) then
        for _,cid in ipairs(getJoiners()) do
            doCreatureSetNoMove(cid,true)
            for i = 0,countDownFrom do
                addEvent(doPlayerSendTextMessage,i*1000, cid, MESSAGE_TYPES["info"], (i == 0 and countDownFrom or countDownFrom-i) )
            end
        end
        addEvent(startFight,(countDownFrom+1)*1000)
    else
        startFight()
    end
end
function startFight()
    doSetStorage(eventStarted,1)
    for _,cid in ipairs(getJoiners()) do
        doCreatureSetNoMove(cid,false)
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],"Fight Starts!")
        
    end
    addEvent(endTeamEvent,eventMaxTime*60*1000,"maxTime")
    doSetStorage(eventTime,os.time()+eventMaxTime*60)
end

function teleportToWaitRoom(cid)
    doTeleportThing(cid,waitRoomPlace)
    doSendMagicEffect(waitRoomPlace,10)
    if getPlayerGroupId(cid) < 4 then
        addToJoiners(cid)
    end
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"Please be patient till the event starts and don't logout.")
    return true
end
 

 
-- Modifing teams & checking member states
function isBlue(cid)
    return (getPlayerStorageValue(cid,inBlue) > 0)
end
function isRed(cid)
    return (getPlayerStorageValue(cid,inRed) > 0)
end
function isJoiner(cid)
    return (getPlayerStorageValue(cid,joiner) > 0)
end
function addToBlue(cid)
    setPlayerStorageValue(cid,inBlue,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and bmale or bfemale)
    doAddCondition(cid,infight)
end
function addToRed(cid)
    setPlayerStorageValue(cid,inRed,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and rmale or rfemale)
    doAddCondition(cid,infight)
end
function addToJoiners(cid)
    setPlayerStorageValue(cid,joiner,1)
end
function removeFromBlue(cid)
    setPlayerStorageValue(cid,inBlue,-1)
end
function removeFromRed(cid)
    setPlayerStorageValue(cid,inRed,-1)
end
function removeFromjoiners(cid)
    setPlayerStorageValue(cid,joiner,-1)
end
function isInRecruitArea(cid)
    return isInRange(getThingPos(cid),waitRoomDimensions.startPos,waitRoomDimensions.endPos)
end
function isInFightArea(cid)
    return isInRange(getThingPos(cid),eventPlaceDimensions.startPos,eventPlaceDimensions.endPos)
end
function clearTeamEventStorages(cid)
    if isInRecruitArea(cid) or isInFightArea(cid) then
        doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getThingPos(cid),10)
    end
 
    if isFightOn() then
        if isJoiner(cid) then
            if isBlue(cid) then
                addRedKills()
            elseif isRed(cid) then
                addBlueKills()
            end
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"You have died in Team-Battle Event.")
        end
    end
 
    removeFromjoiners(cid)
    removeFromBlue(cid)
    removeFromRed(cid)
    doRemoveConditions(cid, false)
    if TeamEventOutfits[cid] ~= nil then
        doCreatureChangeOutfit(cid, TeamEventOutfits[cid])--Give back outfit for player
    end
end
function haveUnrecivedReward(cid)
    return getPlayerStorageValue(cid,itemToGet) > 0 and getPlayerStorageValue(cid,countItemToGet) > 0
end
function recieveLateReward(cid)
    if haveUnrecivedReward(cid) then
        if not doPlayerAddItem(cid,getPlayerStorageValue(cid,itemToGet),getPlayerStorageValue(cid,countItemToGet),false) then
            msg = "You need to free some space then relog to take your reward."
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],msg)
        else
            setPlayerStorageValue(cid,itemToGet,-1)
            setPlayerStorageValue(cid,countItemToGet,-1)
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],"You have recieved your reward.")
        end
    end
end

-- Win or lose
function thereIsAWinner()
    if redWon() or blueWon() then
        return true
    end
    return false
end
function blueWon()
    return( (#getBlueMembers() > 0 ) and ( #getRedMembers() == 0) )
end
function redWon()
    return( (#getRedMembers() > 0) and (#getBlueMembers() == 0) )
end
function isDraw()
    return #getBlueMembers() == #getRedMembers()
end
function getWinner()
    if #getBlueMembers() > #getRedMembers() then
        return {getBlueMembers(),getRedMembers(),"Anbu team won."}
    elseif #getRedMembers() > #getBlueMembers() then
        return {getRedMembers(),getBlueMembers(),"Akatsuki team won."}
    else
        return { {},{},"it was a draw."}
    end
end


-- Adding kills
function addBlueKills()
    doSetStorage(blueKills, math.max(1,getStorage(blueKills)+1))
end
function addRedKills()
    doSetStorage(redKills, math.max(1,getStorage(redKills)+1))
end

-- Ending event

function endTeamEvent(type)
    if isFightOn() then
        doSetStorage(eventStarted,-1)
        doBroadcastMessage("Team-Battle event ended and "..getWinner()[3])
        if not isDraw() then
            win(getWinner()[1],type)
            lose(getWinner()[2],type)
        else
            draw()
        end
    end
    addEvent(resetEvent,2 * 1000)  --- tp player to home remove all storages and reset event global storages
end

function getPercent()
    rand= math.random(1,100)
    prev = 0
    chosenItem = 0
    for k, v in pairs(rewards) do
        if rand > prev and rand <= k+prev then
            chosenItem = k
            break
        else
            prev =  k+prev
        end
    end
    return chosenItem
end
 
function generateReward(cid)
    percent = getPercent()
    if percent == 0 then
        print("Error in the reward item. Please inform Doggynub.")
        return true
    end
 
    randomizer = rewards[percent][math.random(1,#rewards[percent])]
    item = not tonumber(randomizer[1]) and getItemIdByName(randomizer[1]) or randomizer[1]
    count = isItemStackable(item) and math.min(randomizer[2],100) or 1
    if item == nil or item == 0 then
        print("Error in the  item format. Please inform Doggynub.")
        return true
    end
 
    msg = "You have won ".. (count == 1 and "a" or count) .." " .. getItemNameById(item) .. "" .. (count == 1 and "" or "s").."."
 
    if not doPlayerAddItem(cid,item,count,false) then
        msg = msg.. "You need to free some space then relog to take your reward."
        setPlayerStorageValue(cid,itemToGet,item)
        setPlayerStorageValue(cid,countItemToGet,count)
    end
 
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["white"],msg)
 
end



function generateStatsMessage(cid, type, stats)
    msg = {
                    ["KO"] = {     ["win"] = "Event ended. Your team have won by killing all oponent's team members. You will recieve your reward shortly, check incoming messages.",
                                ["lose"] = "Event ended. Your team have lost as the Oponent team killed all your team's members."
                            },
                    ["maxTime"] = {
                                    ["win"] = "Event max-time finished and your team have won. You will recieve your reward shortly, check incoming messages.",
                                    ["lose"] = "Event max-time finished and your team have lost.",
                                    ["draw"] = "Event max-time finished and it is a draw.(no team won)"
                                }
                }
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],msg[type][stats])
 
end
function win(winners,type)
    for _,cid in ipairs(winners) do
        generateStatsMessage(cid, type, "win")
        generateReward(cid)
    end
end
function lose(losers,type)
    for _,cid in ipairs(losers) do
        generateStatsMessage(cid, type, "lose")
    end
end
function draw()
    for _,cid in ipairs(getJoiners()) do
        generateStatsMessage(cid, "maxTime", "draw")
    end
end

function resetEvent()
    doSetStorage(eventRecruiting,-1)
    doSetStorage(nextExecute,-1)
    doSetStorage(eventStarted,-1)
    doSetStorage(eventTime,-1)
    doSetStorage(blueKills,-1)
    doSetStorage(redKills,-1)
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) or isRed(cid) or isJoiner(cid) then
            clearTeamEventStorages(cid)
        end
    end
end


]]></lib>
<event type="login" name="teambattleLogin" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogin(cid)
    clearTeamEventStorages(cid)
    recieveLateReward(cid)
      
    registerCreatureEvent(cid, "teamEventStats")
    registerCreatureEvent(cid, "teambattleLogout")
    registerCreatureEvent(cid, "teambattleCombat")
    return true
end
]]></event>
<event type="combat" name="teambattleCombat" event="script"><![CDATA[
domodlib('teamFunctions')

function onCombat(cid, target)
    if isFightOn() then
        if isBlue(cid) and isBlue(target) then
            return false
        end
        if isRed(cid) and isRed(target) then
            return false
        end
    end
    return true
end

]]></event>
<event type="logout" name="teambattleLogout" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogout(cid)
    clearTeamEventStorages(cid)
    if thereIsAWinner() then
        endTeamEvent("KO")
    end
    return true
end

]]></event>
<event type="statschange" name="teamEventStats" event="script"><![CDATA[
domodlib('teamFunctions')

corpse_ids = {
        [0] = 3065, -- female
        [1] = 3058 -- male
}
function onStatsChange(cid, attacker, type, combat, value)
    if combat == COMBAT_HEALING then
        return true
    end
    if getCreatureHealth(cid) > value then
        return true
    end
 
    if isInFightArea(cid) and isFightOn() then
        if isBlue(cid) or isRed(cid) then
            corpse = doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid))
            doCreateItem(2016, 2, getThingPos(cid))
            clearTeamEventStorages(cid)
            doItemSetAttribute(corpse, "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".n[Team-Event kill]")
            doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
            if thereIsAWinner() then
                endTeamEvent("KO")
            end
          
            return false
      
        end
 
    end

    return true
end
]]></event>

<globalevent name = "teamBattleStart" time="18:30" event="script"><![CDATA[
domodlib('teamFunctions')

function onTimer()
    resetEvent()
    if getTileItemById(teleporterPosition,1387).uid < 1 then
        tp = doCreateItem(1387,1,teleporterPosition)
        doItemSetAttribute(tp, "aid", 9990)
    end
 
    startRecruiting()
    for i = 0, recruitTime-1 do
        addEvent(doBroadcastMessage, i * 60* 1000,"Team-Battle event is recruting players by entering event tp. Fight begins in "..(i == 0 and recruitTime or recruitTime-i).." minutes.",MESSAGE_TYPES["warning"])
    end

    addEvent(startEvent, recruitTime * 60 * 1000)
 
    return true
end


]]></globalevent>

<globalevent name = "teamBattletime" interval="1" event="script"><![CDATA[
domodlib('teamFunctions')

function onThink()
    if isFightOn() then
        disPlayEventStats()
 
        if getStorage(nextExecute) == -1 or getStorage(nextExecute) <= os.time() then
            doSendLeftPlayers()
            doSetStorage(nextExecute,os.time()+intervalToSendLeftPlayers)
        end
    end
    return true
end

]]></globalevent>
<movevent type="StepIn" actionid="9990" event="script"><![CDATA[
domodlib('teamFunctions')

function onStepIn(cid, item, position, fromPosition)
    if not isRecruitOn() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Event isn't currently opened.")
        doTeleportThing(cid,fromPosition)
        doSendMagicEffect(fromPosition,2)
        return true
    end
    if getPlayerLevel(cid) < getMinJoinLevel() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Only players of level ".. getMinJoinLevel().. "+ can join this event.")
        doTeleportThing(cid,fromPosition)
        return true
    end
    teleportToWaitRoom(cid)
    return true
end


]]> </movevent>
</mod>

All players joined the event by the right way? If not, the table don't will recive the player id, and can't find the base outfit.
The weird outfits, we will solve later. U have the server sources? If yes, send me luascript.cpp
 
@zxmatzx Yes, all players. It works :) We got the same outfits when event ends.
First time when i test it, i dont get reward and only this in console
("Error in the reward item. Please inform Doggynub.")
Second time i got normal reward, so idk what happend i will test it more times now.
EDIT: I cant add here this.... so thats the link to luascript.cpp ShareFiles (https://sharefiles.app/download/97e41c10be359e9e98957f39efba31aeedc8d2d9)
EDIT2: Okay i found bug... When red team won this event they dont get reward, when blue team won, they got normal reward.
 
Last edited:
@zxmatzx Yes, all players. It works :) We got the same outfits when event ends.
First time when i test it, i dont get reward and only this in console
("Error in the reward item. Please inform Doggynub.")
Second time i got normal reward, so idk what happend i will test it more times now.
EDIT: I cant add here this.... so thats the link to luascript.cpp ShareFiles (https://sharefiles.app/download/97e41c10be359e9e98957f39efba31aeedc8d2d9)
EDIT2: Okay i found bug... When red team won this event they dont get reward, when blue team won, they got normal reward.
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Team Event" version="2.0" author="Damadgerz" contact="[email protected]" enabled="yes">
<description>
Full auto Team BattleEvent(v2.0) for 0.3.6PL1  :
      
        1- I currently rescripted this event from scratch again.

        2- This version is much more better than the one before, it is more cleaner, clearer and with more options.

        3- This version dislike the previous one , was tested on 0.3.6PL1 and works just fine.

        4- Removed the npc part it is now based on tp creation.

        5- More silent boradcasting for in event progress and no spam, I hope!

        6- you now get the options to show event stats on cancel msg area and (to / not to) show left players with names each x interval.

        8- Team balancer have been added to only balance count in both teams.

        9- Added a countdown option before fight starts.

        10- Now starts on a defined time every day
              
   </description>

<config name="teamSetting"><![CDATA[
--[[Local Config]]--

--//storages

inBlue = 9900
inRed = 9901
joiner = 9907

blueKills = 9902
redKills = 9903

eventRecruiting = 9904
eventStarted = 9905
eventTime = 9906

itemToGet = 9908
countItemToGet = 9909

nextExecute = 9910

blueCount = 9911
redCount = 9912
 
--// Positions

teleporterPosition =    {x = 1081, y = 1014, z = 7}                            --Place where the event tp will be created

waitRoomPlace =     {x = 1543, y = 685, z = 7}                                --Place of the waitnig room (the place ppl will wait for team to be full)

waitRoomDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of waitnig room here
                            startPos = {x = 1537, y = 681, z = 7},
                            endPos = {x = 1551, y = 690, z = 7}
                            }
                          

eventPlaceDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of event place here
                            startPos = {x = 1553, y = 660, z = 7},
                            endPos = {x = 1595, y = 704, z = 7}
                            }
blueTeamPos = {x = 1555, y = 684, z = 7}
redTeamPos = {x = 1593, y = 684, z = 7}


--// General settings

recruitTime = 1                                    -- Time in minutes to gather players to event, will broadcast event started each min

minimumPlayersJoins = 2                            --If the number of layer joined is less than that then event would be cancelled

balanceTeams = true                                -- This will balance number of players in both teams the extra player will be kicked out of event


removeTeleportOnEventEnd = true                    -- if you want to remove the tp when the event finish set it to true, normally tp will just be diabled

eventMaxTime = 5                                    -- Time in minutes, this is the max time event will be running. After checks are caried winner is

showEventSats = true                                -- This is like a timer that is always there about event stats (time,oponents left, teammates left). It appears in the cancel messages place.

sendLeftPlayers = true                            -- Well this will send to all alive players the names& numebr of the oponents left each interval defined down         
intervalToSendLeftPlayers = 11                    -- interval(in seconds) to sendLeftPlayers , must be more than 10 sec


countDownOnStart = true                            -- Well this occurs when players are teleported to their places in the arena , so if this is true it start to count down to the joined players then when count down finish they can start killing each other(event really begins)

countDownFrom = 10                                    -- Starts count down from this number when event start, if above is set true           

minJoinLevel = 1500                                    -- minimm lvl that can join event

rewards = {          --Example [%] = {  {itemid/name, count}  ,..........}    count isnt more than 100

                    [65] = { {2160,1} , {"gold coin",500} }
                }
              
            --[[ Note : make sure if you edited % that sum should be equal to 100, you can add more % elements to suit your needs also more items if you want in each %
                    [65],[25],[10] -> is the % of this item to be found the rest is clear ,items in each % and it will be chosen randomly]]--
                                                          
 
]]></config>
<lib name="teamFunctions"><![CDATA[
domodlib('teamSetting')

--[[Conditions don't touch]]--
local bmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bmale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local bfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bfemale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local rmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rmale, {lookType = 656, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local rfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rfemale, {lookType = 656,lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local infight = createConditionObject(CONDITION_INFIGHT,-1)
--[[Local Config]]--

--[[Functions]]--

-- General info
function isFightOn()
    return getStorage(eventStarted) > 0
end
function isRecruitOn()
    return getStorage(eventRecruiting) > 0
end
function getMinJoinLevel()
    return minJoinLevel
end
function getJoiners()
    joiners = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isJoiner(cid) then
            if isInRecruitArea(cid) or isInFightArea(cid) then
                table.insert(joiners,cid)
            end
        end
    end
    return joiners
end

function getLeftMembersNames(team)
    str = "Oponents left("..#team..") :"
    left = ""
    for k,cid in ipairs(team) do left  = (left ..""..(k == 1 and "" or ", ")..""..getCreatureName(cid).."["..getPlayerLevel(cid).."]" ) end
    str = str .." " .. (left == "" and "none" or left).. "."
    return str
end
function disPlayEventStats()
    if not showEventSats then return false end
    if getStorage(eventTime) - os.time() <= 0 then return false end
 
    left = os.date("%M:%S",(getStorage(eventTime) - os.time()))
    for _,cid in ipairs(getJoiners()) do
        oponentsLeft = isBlue(cid) and #getRedMembers() or #getBlueMembers()
        teamMatesLeft = isBlue(cid) and math.max(0,#getBlueMembers()-1) or math.max(0,#getRedMembers()-1)
        doPlayerSendCancel(cid,"Time left: ".. left.."   ||   Oponents left: "..oponentsLeft.."/"..oponentCount(cid).."   ||   Team-mates left: "..teamMatesLeft.."/".. math.max(0,matesCount(cid)-1))
    end
 
end

function doSendLeftPlayers()
    if not sendLeftPlayers then return false end
    if intervalToSendLeftPlayers <= 10 then return false end
    for _,cid in ipairs(getJoiners()) do
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],getLeftMembersNames(isRed(cid) and getBlueMembers() or getRedMembers()))
    end
end

function getBlueMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) then
            table.insert(members,cid)
        end
    end
    return members
end
function getRedMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isRed(cid) then
            table.insert(members,cid)
        end
    end
    return members
end


-- starting fight

function startRecruiting()
    doSetStorage(eventRecruiting,1)
end
function startEvent()
    doSetStorage(eventRecruiting,-1)
    
    TeamEventOutfits = {}--Clear the global table, to erase old data

    if removeTeleportOnEventEnd then
        tp = getTileItemById(teleporterPosition,1387).uid
        if tp > 0 then doRemoveItem(tp) end
    end
 
    if not balanceTeams() then
        resetEvent()
        return false
    end
    for _,cid in ipairs(getBlueMembers()) do
        doTeleportThing(cid,blueTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setBlueCount(#getBlueMembers())
    for _,cid in ipairs(getRedMembers()) do
        doTeleportThing(cid,redTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setRedCount(#getRedMembers())
    startCountDown()
    return true
end

function setBlueCount(count)
    doSetStorage(blueCount,-1)
    doSetStorage(blueCount,count)
end
function oponentCount(cid)
    return isBlue(cid) and getStorage(redCount) or getStorage(blueCount)
end
function matesCount(cid)
    return isBlue(cid) and getStorage(blueCount) or getStorage(redCount)
end
 
function setRedCount(count)
    doSetStorage(redCount,-1)
    doSetStorage(redCount,count)
end
function balanceTeams()
    members = getJoiners()
    if #members < minimumPlayersJoins then
        doBroadcastMessage("Team-Battle event was cancelled as only ".. #members .. " players joined.")
        return false
    end
    if (math.mod(#members,2) ~= 0) then
        kicked = members[#members]
        clearTeamEventStorages(kicked)
        doPlayerSendTextMessage(kicked,MESSAGE_TYPES["info"],"Sorry, you have been kicked out of event for balancing both teams.")
    end
    count = 1
    for _,cid in ipairs(getJoiners()) do
        TeamEventOutfits[cid] = getCreatureOutfit(cid)--Get outfit player is using before change to red or blue
        if (math.mod(count,2) ~= 0) then
            addToBlue(cid)
        else
            addToRed(cid)
        end
        count = count + 1
    end
    return true
end
function startCountDown()
    if(countDownOnStart) then
        for _,cid in ipairs(getJoiners()) do
            doCreatureSetNoMove(cid,true)
            for i = 0,countDownFrom do
                addEvent(doPlayerSendTextMessage,i*1000, cid, MESSAGE_TYPES["info"], (i == 0 and countDownFrom or countDownFrom-i) )
            end
        end
        addEvent(startFight,(countDownFrom+1)*1000)
    else
        startFight()
    end
end
function startFight()
    doSetStorage(eventStarted,1)
    for _,cid in ipairs(getJoiners()) do
        doCreatureSetNoMove(cid,false)
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],"Fight Starts!")
        
    end
    addEvent(endTeamEvent,eventMaxTime*60*1000,"maxTime")
    doSetStorage(eventTime,os.time()+eventMaxTime*60)
end

function teleportToWaitRoom(cid)
    doTeleportThing(cid,waitRoomPlace)
    doSendMagicEffect(waitRoomPlace,10)
    if getPlayerGroupId(cid) < 4 then
        addToJoiners(cid)
    end
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"Please be patient till the event starts and don't logout.")
    return true
end
 

 
-- Modifing teams & checking member states
function isBlue(cid)
    return (getPlayerStorageValue(cid,inBlue) > 0)
end
function isRed(cid)
    return (getPlayerStorageValue(cid,inRed) > 0)
end
function isJoiner(cid)
    return (getPlayerStorageValue(cid,joiner) > 0)
end
function addToBlue(cid)
    setPlayerStorageValue(cid,inBlue,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and bmale or bfemale)
    doAddCondition(cid,infight)
end
function addToRed(cid)
    setPlayerStorageValue(cid,inRed,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and rmale or rfemale)
    doAddCondition(cid,infight)
end
function addToJoiners(cid)
    setPlayerStorageValue(cid,joiner,1)
end
function removeFromBlue(cid)
    setPlayerStorageValue(cid,inBlue,-1)
end
function removeFromRed(cid)
    setPlayerStorageValue(cid,inRed,-1)
end
function removeFromjoiners(cid)
    setPlayerStorageValue(cid,joiner,-1)
end
function isInRecruitArea(cid)
    return isInRange(getThingPos(cid),waitRoomDimensions.startPos,waitRoomDimensions.endPos)
end
function isInFightArea(cid)
    return isInRange(getThingPos(cid),eventPlaceDimensions.startPos,eventPlaceDimensions.endPos)
end
function clearTeamEventStorages(cid)
    if isInRecruitArea(cid) or isInFightArea(cid) then
        doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getThingPos(cid),10)
    end
 
    if isFightOn() then
        if isJoiner(cid) then
            if isBlue(cid) then
                addRedKills()
            elseif isRed(cid) then
                addBlueKills()
            end
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"You have died in Team-Battle Event.")
        end
    end
 
    removeFromjoiners(cid)
    removeFromBlue(cid)
    removeFromRed(cid)
    doRemoveConditions(cid, false)
    if TeamEventOutfits[cid] ~= nil then
        doSetCreatureOutfit(cid, TeamEventOutfits[cid])--Give back outfit for player
    end
end
function haveUnrecivedReward(cid)
    return getPlayerStorageValue(cid,itemToGet) > 0 and getPlayerStorageValue(cid,countItemToGet) > 0
end
function recieveLateReward(cid)
    if haveUnrecivedReward(cid) then
        if not doPlayerAddItem(cid,getPlayerStorageValue(cid,itemToGet),getPlayerStorageValue(cid,countItemToGet),false) then
            msg = "You need to free some space then relog to take your reward."
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],msg)
        else
            setPlayerStorageValue(cid,itemToGet,-1)
            setPlayerStorageValue(cid,countItemToGet,-1)
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],"You have recieved your reward.")
        end
    end
end

-- Win or lose
function thereIsAWinner()
    if redWon() or blueWon() then
        return true
    end
    return false
end
function blueWon()
    return( (#getBlueMembers() > 0 ) and ( #getRedMembers() == 0) )
end
function redWon()
    return( (#getRedMembers() > 0) and (#getBlueMembers() == 0) )
end
function isDraw()
    return #getBlueMembers() == #getRedMembers()
end
function getWinner()
    if #getBlueMembers() > #getRedMembers() then
        return {getBlueMembers(),getRedMembers(),"Anbu team won."}
    elseif #getRedMembers() > #getBlueMembers() then
        return {getRedMembers(),getBlueMembers(),"Akatsuki team won."}
    else
        return { {},{},"it was a draw."}
    end
end


-- Adding kills
function addBlueKills()
    doSetStorage(blueKills, math.max(1,getStorage(blueKills)+1))
end
function addRedKills()
    doSetStorage(redKills, math.max(1,getStorage(redKills)+1))
end

-- Ending event

function endTeamEvent(type)
    if isFightOn() then
        doSetStorage(eventStarted,-1)
        doBroadcastMessage("Team-Battle event ended and "..getWinner()[3])
        if not isDraw() then
            win(getWinner()[1],type)
            lose(getWinner()[2],type)
        else
            draw()
        end
    end
    addEvent(resetEvent,2 * 1000)  --- tp player to home remove all storages and reset event global storages
end

function getPercent()
    rand= math.random(1,100)
    prev = 0
    chosenItem = 0
    for k, v in pairs(rewards) do
        if rand > prev and rand <= k+prev then
            chosenItem = k
            break
        else
            prev =  k+prev
        end
    end
    return chosenItem
end
 
function generateReward(cid)
    percent = getPercent()
    if percent == 0 then
        print("Error in the reward item. Please inform Doggynub.")
        return true
    end
 
    randomizer = rewards[percent][math.random(1,#rewards[percent])]
    item = not tonumber(randomizer[1]) and getItemIdByName(randomizer[1]) or randomizer[1]
    count = isItemStackable(item) and math.min(randomizer[2],100) or 1
    if item == nil or item == 0 then
        print("Error in the  item format. Please inform Doggynub.")
        return true
    end
 
    msg = "You have won ".. (count == 1 and "a" or count) .." " .. getItemNameById(item) .. "" .. (count == 1 and "" or "s").."."
 
    if not doPlayerAddItem(cid,item,count,false) then
        msg = msg.. "You need to free some space then relog to take your reward."
        setPlayerStorageValue(cid,itemToGet,item)
        setPlayerStorageValue(cid,countItemToGet,count)
    end
 
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["white"],msg)
 
end



function generateStatsMessage(cid, type, stats)
    msg = {
                    ["KO"] = {     ["win"] = "Event ended. Your team have won by killing all oponent's team members. You will recieve your reward shortly, check incoming messages.",
                                ["lose"] = "Event ended. Your team have lost as the Oponent team killed all your team's members."
                            },
                    ["maxTime"] = {
                                    ["win"] = "Event max-time finished and your team have won. You will recieve your reward shortly, check incoming messages.",
                                    ["lose"] = "Event max-time finished and your team have lost.",
                                    ["draw"] = "Event max-time finished and it is a draw.(no team won)"
                                }
                }
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],msg[type][stats])
 
end
function win(winners,type)
    for _,cid in ipairs(winners) do
        generateStatsMessage(cid, type, "win")
        generateReward(cid)
    end
end
function lose(losers,type)
    for _,cid in ipairs(losers) do
        generateStatsMessage(cid, type, "lose")
    end
end
function draw()
    for _,cid in ipairs(getJoiners()) do
        generateStatsMessage(cid, "maxTime", "draw")
    end
end

function resetEvent()
    doSetStorage(eventRecruiting,-1)
    doSetStorage(nextExecute,-1)
    doSetStorage(eventStarted,-1)
    doSetStorage(eventTime,-1)
    doSetStorage(blueKills,-1)
    doSetStorage(redKills,-1)
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) or isRed(cid) or isJoiner(cid) then
            clearTeamEventStorages(cid)
        end
    end
end


]]></lib>
<event type="login" name="teambattleLogin" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogin(cid)
    clearTeamEventStorages(cid)
    recieveLateReward(cid)
      
    registerCreatureEvent(cid, "teamEventStats")
    registerCreatureEvent(cid, "teambattleLogout")
    registerCreatureEvent(cid, "teambattleCombat")
    return true
end
]]></event>
<event type="combat" name="teambattleCombat" event="script"><![CDATA[
domodlib('teamFunctions')

function onCombat(cid, target)
    if isFightOn() then
        if isBlue(cid) and isBlue(target) then
            return false
        end
        if isRed(cid) and isRed(target) then
            return false
        end
    end
    return true
end

]]></event>
<event type="logout" name="teambattleLogout" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogout(cid)
    clearTeamEventStorages(cid)
    if thereIsAWinner() then
        endTeamEvent("KO")
    end
    return true
end

]]></event>
<event type="statschange" name="teamEventStats" event="script"><![CDATA[
domodlib('teamFunctions')

corpse_ids = {
        [0] = 3065, -- female
        [1] = 3058 -- male
}
function onStatsChange(cid, attacker, type, combat, value)
    if combat == COMBAT_HEALING then
        return true
    end
    if getCreatureHealth(cid) > value then
        return true
    end
 
    if isInFightArea(cid) and isFightOn() then
        if isBlue(cid) or isRed(cid) then
            corpse = doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid))
            doCreateItem(2016, 2, getThingPos(cid))
            clearTeamEventStorages(cid)
            doItemSetAttribute(corpse, "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".n[Team-Event kill]")
            doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
            if thereIsAWinner() then
                endTeamEvent("KO")
            end
          
            return false
      
        end
 
    end

    return true
end
]]></event>

<globalevent name = "teamBattleStart" time="18:30" event="script"><![CDATA[
domodlib('teamFunctions')

function onTimer()
    resetEvent()
    if getTileItemById(teleporterPosition,1387).uid < 1 then
        tp = doCreateItem(1387,1,teleporterPosition)
        doItemSetAttribute(tp, "aid", 9990)
    end
 
    startRecruiting()
    for i = 0, recruitTime-1 do
        addEvent(doBroadcastMessage, i * 60* 1000,"Team-Battle event is recruting players by entering event tp. Fight begins in "..(i == 0 and recruitTime or recruitTime-i).." minutes.",MESSAGE_TYPES["warning"])
    end

    addEvent(startEvent, recruitTime * 60 * 1000)
 
    return true
end


]]></globalevent>

<globalevent name = "teamBattletime" interval="1" event="script"><![CDATA[
domodlib('teamFunctions')

function onThink()
    if isFightOn() then
        disPlayEventStats()
 
        if getStorage(nextExecute) == -1 or getStorage(nextExecute) <= os.time() then
            doSendLeftPlayers()
            doSetStorage(nextExecute,os.time()+intervalToSendLeftPlayers)
        end
    end
    return true
end

]]></globalevent>
<movevent type="StepIn" actionid="9990" event="script"><![CDATA[
domodlib('teamFunctions')

function onStepIn(cid, item, position, fromPosition)
    if not isRecruitOn() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Event isn't currently opened.")
        doTeleportThing(cid,fromPosition)
        doSendMagicEffect(fromPosition,2)
        return true
    end
    if getPlayerLevel(cid) < getMinJoinLevel() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Only players of level ".. getMinJoinLevel().. "+ can join this event.")
        doTeleportThing(cid,fromPosition)
        return true
    end
    teleportToWaitRoom(cid)
    return true
end


]]> </movevent>
</mod>
Test please.
Try this: Red team(player a, b, c) vs Blue team (d, e, f) after Red team(d, e, f) vs Blue team(a, b, c) check if only red team is getting the reward.
 
@zxmatzx no one gets a reward now :(
Code:
[05/06/2019 23:00:27] (luaGetItemIdByName) Item not found

[05/06/2019 23:00:27] [Error - CreatureScript Interface]
[05/06/2019 23:00:27] buffer:onStatsChange
[05/06/2019 23:00:27] Description:
[05/06/2019 23:00:27] data/lib/050-function.lua:293: attempt to index a boolean value
[05/06/2019 23:00:27] stack traceback:
[05/06/2019 23:00:27]     data/lib/050-function.lua:293: in function 'getItemNameById'
[05/06/2019 23:00:27]     [string "domodlib('teamSetting')..."]:362: in function 'generateReward'
[05/06/2019 23:00:27]     [string "domodlib('teamSetting')..."]:393: in function 'win'
[05/06/2019 23:00:27]     [string "domodlib('teamSetting')..."]:323: in function 'endTeamEvent'
[05/06/2019 23:00:27]     [string "loadBuffer"]:23: in function <[string "loadBuffer"]:7>
 
@zxmatzx no one gets a reward now :(
Code:
[05/06/2019 23:00:27] (luaGetItemIdByName) Item not found

[05/06/2019 23:00:27] [Error - CreatureScript Interface]
[05/06/2019 23:00:27] buffer:onStatsChange
[05/06/2019 23:00:27] Description:
[05/06/2019 23:00:27] data/lib/050-function.lua:293: attempt to index a boolean value
[05/06/2019 23:00:27] stack traceback:
[05/06/2019 23:00:27]     data/lib/050-function.lua:293: in function 'getItemNameById'
[05/06/2019 23:00:27]     [string "domodlib('teamSetting')..."]:362: in function 'generateReward'
[05/06/2019 23:00:27]     [string "domodlib('teamSetting')..."]:393: in function 'win'
[05/06/2019 23:00:27]     [string "domodlib('teamSetting')..."]:323: in function 'endTeamEvent'
[05/06/2019 23:00:27]     [string "loadBuffer"]:23: in function <[string "loadBuffer"]:7>
U changed something? The reward name was correct?
 
Try:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Team Event" version="2.0" author="Damadgerz" contact="[email protected]" enabled="yes">
<description>
Full auto Team BattleEvent(v2.0) for 0.3.6PL1  :
      
        1- I currently rescripted this event from scratch again.

        2- This version is much more better than the one before, it is more cleaner, clearer and with more options.

        3- This version dislike the previous one , was tested on 0.3.6PL1 and works just fine.

        4- Removed the npc part it is now based on tp creation.

        5- More silent boradcasting for in event progress and no spam, I hope!

        6- you now get the options to show event stats on cancel msg area and (to / not to) show left players with names each x interval.

        8- Team balancer have been added to only balance count in both teams.

        9- Added a countdown option before fight starts.

        10- Now starts on a defined time every day
              
   </description>

<config name="teamSetting"><![CDATA[
--[[Local Config]]--

--//storages

inBlue = 9900
inRed = 9901
joiner = 9907

blueKills = 9902
redKills = 9903

eventRecruiting = 9904
eventStarted = 9905
eventTime = 9906

itemToGet = 9908
countItemToGet = 9909

nextExecute = 9910

blueCount = 9911
redCount = 9912
 
--// Positions

teleporterPosition =    {x = 1081, y = 1014, z = 7}                            --Place where the event tp will be created

waitRoomPlace =     {x = 1543, y = 685, z = 7}                                --Place of the waitnig room (the place ppl will wait for team to be full)

waitRoomDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of waitnig room here
                            startPos = {x = 1537, y = 681, z = 7},
                            endPos = {x = 1551, y = 690, z = 7}
                            }
                          

eventPlaceDimensions = {                                                    --Enter the start pos[top left sqm] and end pos[bottom right sqm] of event place here
                            startPos = {x = 1553, y = 660, z = 7},
                            endPos = {x = 1595, y = 704, z = 7}
                            }
blueTeamPos = {x = 1555, y = 684, z = 7}
redTeamPos = {x = 1593, y = 684, z = 7}


--// General settings

recruitTime = 1                                    -- Time in minutes to gather players to event, will broadcast event started each min

minimumPlayersJoins = 2                            --If the number of layer joined is less than that then event would be cancelled

balanceTeams = true                                -- This will balance number of players in both teams the extra player will be kicked out of event


removeTeleportOnEventEnd = true                    -- if you want to remove the tp when the event finish set it to true, normally tp will just be diabled

eventMaxTime = 5                                    -- Time in minutes, this is the max time event will be running. After checks are caried winner is

showEventSats = true                                -- This is like a timer that is always there about event stats (time,oponents left, teammates left). It appears in the cancel messages place.

sendLeftPlayers = true                            -- Well this will send to all alive players the names& numebr of the oponents left each interval defined down         
intervalToSendLeftPlayers = 11                    -- interval(in seconds) to sendLeftPlayers , must be more than 10 sec


countDownOnStart = true                            -- Well this occurs when players are teleported to their places in the arena , so if this is true it start to count down to the joined players then when count down finish they can start killing each other(event really begins)

countDownFrom = 10                                    -- Starts count down from this number when event start, if above is set true           

minJoinLevel = 1500                                    -- minimm lvl that can join event

rewards = {          --Example [%] = {  {itemid/name, count}  ,..........}    count isnt more than 100

                    [65] = { {2160,1} , {"gold coin",500} }
                }
              
            --[[ Note : make sure if you edited % that sum should be equal to 100, you can add more % elements to suit your needs also more items if you want in each %
                    [65],[25],[10] -> is the % of this item to be found the rest is clear ,items in each % and it will be chosen randomly]]--
                                                          
 
]]></config>
<lib name="teamFunctions"><![CDATA[
domodlib('teamSetting')

--[[Conditions don't touch]]--
local bmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bmale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local bfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(bfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(bfemale, {lookType = 159, lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})

local rmale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rmale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rmale, {lookType = 656, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local rfemale = createConditionObject(CONDITION_OUTFIT)
setConditionParam(rfemale, CONDITION_PARAM_TICKS, -1)
addOutfitCondition(rfemale, {lookType = 656,lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})

local infight = createConditionObject(CONDITION_INFIGHT,-1)
--[[Local Config]]--

--[[Functions]]--

-- General info
function isFightOn()
    return getStorage(eventStarted) > 0
end
function isRecruitOn()
    return getStorage(eventRecruiting) > 0
end
function getMinJoinLevel()
    return minJoinLevel
end
function getJoiners()
    joiners = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isJoiner(cid) then
            if isInRecruitArea(cid) or isInFightArea(cid) then
                table.insert(joiners,cid)
            end
        end
    end
    return joiners
end

function getLeftMembersNames(team)
    str = "Oponents left("..#team..") :"
    left = ""
    for k,cid in ipairs(team) do left  = (left ..""..(k == 1 and "" or ", ")..""..getCreatureName(cid).."["..getPlayerLevel(cid).."]" ) end
    str = str .." " .. (left == "" and "none" or left).. "."
    return str
end
function disPlayEventStats()
    if not showEventSats then return false end
    if getStorage(eventTime) - os.time() <= 0 then return false end
 
    left = os.date("%M:%S",(getStorage(eventTime) - os.time()))
    for _,cid in ipairs(getJoiners()) do
        oponentsLeft = isBlue(cid) and #getRedMembers() or #getBlueMembers()
        teamMatesLeft = isBlue(cid) and math.max(0,#getBlueMembers()-1) or math.max(0,#getRedMembers()-1)
        doPlayerSendCancel(cid,"Time left: ".. left.."   ||   Oponents left: "..oponentsLeft.."/"..oponentCount(cid).."   ||   Team-mates left: "..teamMatesLeft.."/".. math.max(0,matesCount(cid)-1))
    end
 
end

function doSendLeftPlayers()
    if not sendLeftPlayers then return false end
    if intervalToSendLeftPlayers <= 10 then return false end
    for _,cid in ipairs(getJoiners()) do
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],getLeftMembersNames(isRed(cid) and getBlueMembers() or getRedMembers()))
    end
end

function getBlueMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) then
            table.insert(members,cid)
        end
    end
    return members
end
function getRedMembers()
    members = {}
    for _,cid in ipairs(getPlayersOnline()) do
        if isRed(cid) then
            table.insert(members,cid)
        end
    end
    return members
end


-- starting fight

function startRecruiting()
    doSetStorage(eventRecruiting,1)
end
function startEvent()
    doSetStorage(eventRecruiting,-1)
    
    TeamEventOutfits = {}--Clear the global table, to erase old data

    if removeTeleportOnEventEnd then
        tp = getTileItemById(teleporterPosition,1387).uid
        if tp > 0 then doRemoveItem(tp) end
    end
 
    if not balanceTeams() then
        resetEvent()
        return false
    end
    for _,cid in ipairs(getBlueMembers()) do
        doTeleportThing(cid,blueTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setBlueCount(#getBlueMembers())
    for _,cid in ipairs(getRedMembers()) do
        doTeleportThing(cid,redTeamPos,false)
        doSendMagicEffect(getThingPos(cid),10)
    end
    setRedCount(#getRedMembers())
    startCountDown()
    return true
end

function setBlueCount(count)
    doSetStorage(blueCount,-1)
    doSetStorage(blueCount,count)
end
function oponentCount(cid)
    return isBlue(cid) and getStorage(redCount) or getStorage(blueCount)
end
function matesCount(cid)
    return isBlue(cid) and getStorage(blueCount) or getStorage(redCount)
end
 
function setRedCount(count)
    doSetStorage(redCount,-1)
    doSetStorage(redCount,count)
end
function balanceTeams()
    members = getJoiners()
    if #members < minimumPlayersJoins then
        doBroadcastMessage("Team-Battle event was cancelled as only ".. #members .. " players joined.")
        return false
    end
    if (math.mod(#members,2) ~= 0) then
        kicked = members[#members]
        clearTeamEventStorages(kicked)
        doPlayerSendTextMessage(kicked,MESSAGE_TYPES["info"],"Sorry, you have been kicked out of event for balancing both teams.")
    end
    count = 1
    for _,cid in ipairs(getJoiners()) do
        TeamEventOutfits[cid] = getCreatureOutfit(cid)--Get outfit player is using before change to red or blue
        if (math.mod(count,2) ~= 0) then
            addToBlue(cid)
        else
            addToRed(cid)
        end
        count = count + 1
    end
    return true
end
function startCountDown()
    if(countDownOnStart) then
        for _,cid in ipairs(getJoiners()) do
            doCreatureSetNoMove(cid,true)
            for i = 0,countDownFrom do
                addEvent(doPlayerSendTextMessage,i*1000, cid, MESSAGE_TYPES["info"], (i == 0 and countDownFrom or countDownFrom-i) )
            end
        end
        addEvent(startFight,(countDownFrom+1)*1000)
    else
        startFight()
    end
end
function startFight()
    doSetStorage(eventStarted,1)
    for _,cid in ipairs(getJoiners()) do
        doCreatureSetNoMove(cid,false)
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],"Fight Starts!")
        
    end
    addEvent(endTeamEvent,eventMaxTime*60*1000,"maxTime")
    doSetStorage(eventTime,os.time()+eventMaxTime*60)
end

function teleportToWaitRoom(cid)
    doTeleportThing(cid,waitRoomPlace)
    doSendMagicEffect(waitRoomPlace,10)
    if getPlayerGroupId(cid) < 4 then
        addToJoiners(cid)
    end
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"Please be patient till the event starts and don't logout.")
    return true
end
 

 
-- Modifing teams & checking member states
function isBlue(cid)
    return (getPlayerStorageValue(cid,inBlue) > 0)
end
function isRed(cid)
    return (getPlayerStorageValue(cid,inRed) > 0)
end
function isJoiner(cid)
    return (getPlayerStorageValue(cid,joiner) > 0)
end
function addToBlue(cid)
    setPlayerStorageValue(cid,inBlue,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and bmale or bfemale)
    doAddCondition(cid,infight)
end
function addToRed(cid)
    setPlayerStorageValue(cid,inRed,1)
    doAddCondition(cid, (getPlayerSex(cid) == 1) and rmale or rfemale)
    doAddCondition(cid,infight)
end
function addToJoiners(cid)
    setPlayerStorageValue(cid,joiner,1)
end
function removeFromBlue(cid)
    setPlayerStorageValue(cid,inBlue,-1)
end
function removeFromRed(cid)
    setPlayerStorageValue(cid,inRed,-1)
end
function removeFromjoiners(cid)
    setPlayerStorageValue(cid,joiner,-1)
end
function isInRecruitArea(cid)
    return isInRange(getThingPos(cid),waitRoomDimensions.startPos,waitRoomDimensions.endPos)
end
function isInFightArea(cid)
    return isInRange(getThingPos(cid),eventPlaceDimensions.startPos,eventPlaceDimensions.endPos)
end
function clearTeamEventStorages(cid)
    if isInRecruitArea(cid) or isInFightArea(cid) then
        doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getThingPos(cid),10)
    end
 
    if isFightOn() then
        if isJoiner(cid) then
            if isBlue(cid) then
                addRedKills()
            elseif isRed(cid) then
                addBlueKills()
            end
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"You have died in Team-Battle Event.")
        end
    end
 
    removeFromjoiners(cid)
    removeFromBlue(cid)
    removeFromRed(cid)
    doRemoveConditions(cid, false)
    doSetCreatureOutfit(cid, TeamEventOutfits[cid])--Give back outfit for player
end
function haveUnrecivedReward(cid)
    return getPlayerStorageValue(cid,itemToGet) > 0 and getPlayerStorageValue(cid,countItemToGet) > 0
end
function recieveLateReward(cid)
    if haveUnrecivedReward(cid) then
        if not doPlayerAddItem(cid,getPlayerStorageValue(cid,itemToGet),getPlayerStorageValue(cid,countItemToGet),false) then
            msg = "You need to free some space then relog to take your reward."
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],msg)
        else
            setPlayerStorageValue(cid,itemToGet,-1)
            setPlayerStorageValue(cid,countItemToGet,-1)
            doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],"You have recieved your reward.")
        end
    end
end

-- Win or lose
function thereIsAWinner()
    if redWon() or blueWon() then
        return true
    end
    return false
end
function blueWon()
    return( (#getBlueMembers() > 0 ) and ( #getRedMembers() == 0) )
end
function redWon()
    return( (#getRedMembers() > 0) and (#getBlueMembers() == 0) )
end
function isDraw()
    return #getBlueMembers() == #getRedMembers()
end
function getWinner()
    if #getBlueMembers() > #getRedMembers() then
        return {getBlueMembers(),getRedMembers(),"Anbu team won."}
    elseif #getRedMembers() > #getBlueMembers() then
        return {getRedMembers(),getBlueMembers(),"Akatsuki team won."}
    else
        return { {},{},"it was a draw."}
    end
end


-- Adding kills
function addBlueKills()
    doSetStorage(blueKills, math.max(1,getStorage(blueKills)+1))
end
function addRedKills()
    doSetStorage(redKills, math.max(1,getStorage(redKills)+1))
end

-- Ending event

function endTeamEvent(type)
    if isFightOn() then
        doSetStorage(eventStarted,-1)
        doBroadcastMessage("Team-Battle event ended and "..getWinner()[3])
        if not isDraw() then
            win(getWinner()[1],type)
            lose(getWinner()[2],type)
        else
            draw()
        end
    end
    addEvent(resetEvent,2 * 1000)  --- tp player to home remove all storages and reset event global storages
end

function getPercent()
    rand= math.random(1,100)
    prev = 0
    chosenItem = 0
    for k, v in pairs(rewards) do
        if rand > prev and rand <= k+prev then
            chosenItem = k
            break
        else
            prev =  k+prev
        end
    end
    return chosenItem
end
 
function generateReward(cid)
    percent = getPercent()
    if percent == 0 then
        print("Error in the reward item. Please inform Doggynub.")
        return true
    end
 
    randomizer = rewards[percent][math.random(1,#rewards[percent])]
    item = not tonumber(randomizer[1]) and getItemIdByName(randomizer[1]) or randomizer[1]
    count = isItemStackable(item) and math.min(randomizer[2],100) or 1
    if item == nil or item == 0 then
        print("Error in the  item format. Please inform Doggynub.")
        return true
    end
 
    msg = "You have won ".. (count == 1 and "a" or count) .." " .. getItemNameById(item) .. "" .. (count == 1 and "" or "s").."."
 
    if not doPlayerAddItem(cid,item,count,false) then
        msg = msg.. "You need to free some space then relog to take your reward."
        setPlayerStorageValue(cid,itemToGet,item)
        setPlayerStorageValue(cid,countItemToGet,count)
    end
 
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["white"],msg)
 
end



function generateStatsMessage(cid, type, stats)
    msg = {
                    ["KO"] = {     ["win"] = "Event ended. Your team have won by killing all oponent's team members. You will recieve your reward shortly, check incoming messages.",
                                ["lose"] = "Event ended. Your team have lost as the Oponent team killed all your team's members."
                            },
                    ["maxTime"] = {
                                    ["win"] = "Event max-time finished and your team have won. You will recieve your reward shortly, check incoming messages.",
                                    ["lose"] = "Event max-time finished and your team have lost.",
                                    ["draw"] = "Event max-time finished and it is a draw.(no team won)"
                                }
                }
    doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],msg[type][stats])
 
end
function win(winners,type)
    for _,cid in ipairs(winners) do
        generateStatsMessage(cid, type, "win")
        generateReward(cid)
    end
end
function lose(losers,type)
    for _,cid in ipairs(losers) do
        generateStatsMessage(cid, type, "lose")
    end
end
function draw()
    for _,cid in ipairs(getJoiners()) do
        generateStatsMessage(cid, "maxTime", "draw")
    end
end

function resetEvent()
    doSetStorage(eventRecruiting,-1)
    doSetStorage(nextExecute,-1)
    doSetStorage(eventStarted,-1)
    doSetStorage(eventTime,-1)
    doSetStorage(blueKills,-1)
    doSetStorage(redKills,-1)
    for _,cid in ipairs(getPlayersOnline()) do
        if isBlue(cid) or isRed(cid) or isJoiner(cid) then
            clearTeamEventStorages(cid)
        end
    end
end


]]></lib>
<event type="login" name="teambattleLogin" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogin(cid)
    clearTeamEventStorages(cid)
    recieveLateReward(cid)
      
    registerCreatureEvent(cid, "teamEventStats")
    registerCreatureEvent(cid, "teambattleLogout")
    registerCreatureEvent(cid, "teambattleCombat")
    return true
end
]]></event>
<event type="combat" name="teambattleCombat" event="script"><![CDATA[
domodlib('teamFunctions')

function onCombat(cid, target)
    if isFightOn() then
        if isBlue(cid) and isBlue(target) then
            return false
        end
        if isRed(cid) and isRed(target) then
            return false
        end
    end
    return true
end

]]></event>
<event type="logout" name="teambattleLogout" event="script"><![CDATA[
domodlib('teamFunctions')

function onLogout(cid)
    clearTeamEventStorages(cid)
    if thereIsAWinner() then
        endTeamEvent("KO")
    end
    return true
end

]]></event>
<event type="statschange" name="teamEventStats" event="script"><![CDATA[
domodlib('teamFunctions')

corpse_ids = {
        [0] = 3065, -- female
        [1] = 3058 -- male
}
function onStatsChange(cid, attacker, type, combat, value)
    if combat == COMBAT_HEALING then
        return true
    end
    if getCreatureHealth(cid) > value then
        return true
    end
 
    if isInFightArea(cid) and isFightOn() then
        if isBlue(cid) or isRed(cid) then
            corpse = doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid))
            doCreateItem(2016, 2, getThingPos(cid))
            clearTeamEventStorages(cid)
            doItemSetAttribute(corpse, "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".n[Team-Event kill]")
            doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
            if thereIsAWinner() then
                endTeamEvent("KO")
            end
          
            return false
      
        end
 
    end

    return true
end
]]></event>

<globalevent name = "teamBattleStart" time="18:30" event="script"><![CDATA[
domodlib('teamFunctions')

function onTimer()
    resetEvent()
    if getTileItemById(teleporterPosition,1387).uid < 1 then
        tp = doCreateItem(1387,1,teleporterPosition)
        doItemSetAttribute(tp, "aid", 9990)
    end
 
    startRecruiting()
    for i = 0, recruitTime-1 do
        addEvent(doBroadcastMessage, i * 60* 1000,"Team-Battle event is recruting players by entering event tp. Fight begins in "..(i == 0 and recruitTime or recruitTime-i).." minutes.",MESSAGE_TYPES["warning"])
    end

    addEvent(startEvent, recruitTime * 60 * 1000)
 
    return true
end


]]></globalevent>

<globalevent name = "teamBattletime" interval="1" event="script"><![CDATA[
domodlib('teamFunctions')

function onThink()
    if isFightOn() then
        disPlayEventStats()
 
        if getStorage(nextExecute) == -1 or getStorage(nextExecute) <= os.time() then
            doSendLeftPlayers()
            doSetStorage(nextExecute,os.time()+intervalToSendLeftPlayers)
        end
    end
    return true
end

]]></globalevent>
<movevent type="StepIn" actionid="9990" event="script"><![CDATA[
domodlib('teamFunctions')

function onStepIn(cid, item, position, fromPosition)
    if not isRecruitOn() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Event isn't currently opened.")
        doTeleportThing(cid,fromPosition)
        doSendMagicEffect(fromPosition,2)
        return true
    end
    if getPlayerLevel(cid) < getMinJoinLevel() then
        doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Only players of level ".. getMinJoinLevel().. "+ can join this event.")
        doTeleportThing(cid,fromPosition)
        return true
    end
    teleportToWaitRoom(cid)
    return true
end


]]> </movevent>
</mod>
The error is not the same as before...
 
Code:
[06/06/2019 20:30:58] Admin has logged in.

[06/06/2019 20:30:58] [Error - CreatureScript Interface]
[06/06/2019 20:30:58] buffer:onLogin
[06/06/2019 20:30:58] Description:
[06/06/2019 20:30:58] attempt to index a number value
[06/06/2019 20:30:58] stack traceback:
[06/06/2019 20:30:58]     [C]: in function 'doSetCreatureOutfit'
[06/06/2019 20:30:58]     [string "domodlib('teamSetting')..."]:261: in function 'clearTeamEventStorages'
[06/06/2019 20:30:58]     [string "loadBuffer"]:4: in function <[string "loadBuffer"]:3>

[06/06/2019 20:30:58] [Error - CreatureScript Interface]
[06/06/2019 20:30:59] buffer:onLogout
[06/06/2019 20:30:59] Description:
[06/06/2019 20:30:59] attempt to index a number value
[06/06/2019 20:30:59] stack traceback:
[06/06/2019 20:30:59]     [C]: in function 'doSetCreatureOutfit'
[06/06/2019 20:30:59]     [string "domodlib('teamSetting')..."]:261: in function 'clearTeamEventStorages'
[06/06/2019 20:30:59]     [string "loadBuffer"]:4: in function <[string "loadBuffer"]:3>
[06/06/2019 20:30:59] Admin has logged out.
i cannot log in to the server now :D @zxmatzx
 
Code:
[06/06/2019 20:30:58] Admin has logged in.

[06/06/2019 20:30:58] [Error - CreatureScript Interface]
[06/06/2019 20:30:58] buffer:onLogin
[06/06/2019 20:30:58] Description:
[06/06/2019 20:30:58] attempt to index a number value
[06/06/2019 20:30:58] stack traceback:
[06/06/2019 20:30:58]     [C]: in function 'doSetCreatureOutfit'
[06/06/2019 20:30:58]     [string "domodlib('teamSetting')..."]:261: in function 'clearTeamEventStorages'
[06/06/2019 20:30:58]     [string "loadBuffer"]:4: in function <[string "loadBuffer"]:3>

[06/06/2019 20:30:58] [Error - CreatureScript Interface]
[06/06/2019 20:30:59] buffer:onLogout
[06/06/2019 20:30:59] Description:
[06/06/2019 20:30:59] attempt to index a number value
[06/06/2019 20:30:59] stack traceback:
[06/06/2019 20:30:59]     [C]: in function 'doSetCreatureOutfit'
[06/06/2019 20:30:59]     [string "domodlib('teamSetting')..."]:261: in function 'clearTeamEventStorages'
[06/06/2019 20:30:59]     [string "loadBuffer"]:4: in function <[string "loadBuffer"]:3>
[06/06/2019 20:30:59] Admin has logged out.
i cannot log in to the server now :D @zxmatzx
U closed the server and opened again right? The global table has reseted...
Find all
Lua:
doSetCreatureOutfit()
and change the to:
Lua:
doSetCreatureOutfit(cid, 100)
You will be able to login again, login all characters, and get back the lines. Try test.
 
Back
Top