Serginov
Onkonkoronkonk
Ok so here is my scripts for my team battle server I made a while ago, they are tested on tfs 0.3.6 and are fully working.
If you want this to work for tfs 0.4 I think you only need to change all(I think so):
setPlayerStorageValue to doCreatureSetStorage
getPlayerStorageValue to getCreatureStorage
getGlobalStorageValue to getStorage
setGlobalStorageValue to setStorage
Changelog:
Edit; You need this function for the login part to work properly, you can just edit the login part to not give skills or anything if you want. but if you want it to give skills use this function.
050-functions.lua:
Globalevent changeMap.lua:
Globalevent teamScores.lua:
Globalevent teams.lua:
Globalevent.xml:
Creaturescript teamLogin.lua (sets the team of a player and teleports to the right map):
Creaturescript teamLogout.lua:
Creaturescript fixTeams.lua:
Creaturescript combat.lua
Creaturescript LookScores.lua:
Creaturescripts.xml:
Just set the interval between the mapchanges in globalevents.xml. 1800 = 30 min in tfs 0.3.6
If you want this to work for tfs 0.4 I think you only need to change all(I think so):
setPlayerStorageValue to doCreatureSetStorage
getPlayerStorageValue to getCreatureStorage
getGlobalStorageValue to getStorage
setGlobalStorageValue to setStorage
Changelog:
Code:
-
050-functions.lua:
Code:
function getPlayerMeleeSkill(cid)
return {[0] = getPlayerSkillLevel(cid, SKILL_FIST), [1] = getPlayerSkillLevel(cid, SKILL_CLUB), [2] = getPlayerSkillLevel(cid, SKILL_SWORD), [3] = getPlayerSkillLevel(cid, SKILL_AXE)}
end
function doPlayerAddMeleeSkill(cid, amount)
local rate = getConfigInfo('rateSkill')
for i = 0, 3 do
doPlayerAddSkillTry(cid, i, math.ceil((getPlayerRequiredSkillTries(cid, i, getPlayerSkillLevel(cid, i) + 1) - getPlayerSkillTries(cid, i)) / rate))
end
end
Code:
function onThink(interval, lastExecution, thinkInterval)
local maps = {
[1] = {mapName = "Ignitos", redTemple = {x = 1153, y = 1069, z = 6}, blueTemple = {x = 1146, y = 1120, z = 6}},
[2] = {mapName = "Dust2", redTemple = {x = 1169, y = 1192, z = 7}, blueTemple = {x = 1107, y = 1176, z = 6}},
[3] = {mapName = "Fridge", redTemple = {x = 1277, y = 1035, z = 3}, blueTemple = {x = 1225, y = 1035, z = 3}},
}
local teams = {
blueName = "Blue Bangbabies",
redName = "Red Rageboys",
blueScore = 101,
redScore = 102,
bluePlayerScore = 1004,
redPlayerScore = 1006,
}
local map = maps[getGlobalStorageValue(100)]
if getGlobalStorageValue(100) <= 0 then
setGlobalStorageValue(100, 1)
elseif getGlobalStorageValue(100) >= math.max(1, #maps) then
setGlobalStorageValue(100, 1)
elseif getGlobalStorageValue(100) >= 1 then
setGlobalStorageValue(100, getGlobalStorageValue(100)+1)
end
if map then
for _, cid in ipairs(getPlayersOnline()) do
if getPlayerStorageValue(cid, 1002) == 1 then
doTeleportThing(cid, map.blueTemple)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
elseif getPlayerStorageValue(cid, 1003) == 1 then
doTeleportThing(cid, map.redTemple)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
end
if getGlobalStorageValue(teams.blueScore) > getGlobalStorageValue(teams.redScore) then
str = "\n\nThe " .. teams.blueName .. " won!\n\nScores:\n" .. teams.blueName .. " " .. getGlobalStorageValue(blueScore) .. " - " .. getGlobalStorageValue(redScore) .. " " .. teams.redName .. "."
elseif getGlobalStorageValue(teams.redScore) > getGlobalStorageValue(teams.blueScore) then
str = "\n\nThe " .. teams.redName .. " won!\n\nScores:\n" .. teams.blueName .. " " .. getGlobalStorageValue(blueScore) .. " - " .. getGlobalStorageValue(redScore) .. " " .. teams.redName .. "."
end
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Map has been changed to " .. map.mapName .. "! Next map in 30 minutes!" .. str)
end
setGlobalStorageValue(teams.blueScore, 0)
setGlobalStorageValue(teams.redScore, 0)
end
return true
end
Code:
local blueScore = 101
local redScore = 102
local teams = {
blueName = "Blue Bangbabies",
redName = "Red Rageboys",
}
function onThink(interval, lastExecution, thinkInterval)
if getGlobalStorageValue(blueScore) > getGlobalStorageValue(redScore) then
str = "The leading team is the " .. teams.blueName .. "!\n\nScores:\n" .. teams.blueName .. " " .. getGlobalStorageValue(blueScore) .. " - " .. getGlobalStorageValue(redScore) .. " " .. teams.redName .. "."
elseif getGlobalStorageValue(redScore) > getGlobalStorageValue(blueScore) then
str = "The leading team is the " .. teams.redName .. "!\n\nScores:\n" .. teams.redName .. " " .. getGlobalStorageValue(redScore) .. " - " .. getGlobalStorageValue(blueScore) .. " " .. teams.blueName .. "."
elseif getGlobalStorageValue(redScore) == getGlobalStorageValue(blueScore) then
str = "The teams is tied to the lead!\n\nScores:\n" .. teams.redName .. " " .. getGlobalStorageValue(redScore) .. " - " .. getGlobalStorageValue(blueScore) .. " " .. teams.blueName .. "."
end
doBroadcastMessage(str .. "\n\nPlayers:\n" .. teams.blueName .. " - " .. getGlobalStorageValue(1000) .. " vs " .. getGlobalStorageValue(1001) .. " - " .. teams.redName .. ".", MESSAGE_EVENT_ORANGE)
return true
end
Code:
local conditionBlue = createConditionObject(CONDITION_OUTFIT)
setConditionParam(conditionBlue, CONDITION_PARAM_TICKS, 1800 * 1000)
addOutfitCondition(conditionBlue, {lookType = 130, lookHead = 87, lookBody = 87, lookLegs = 87, lookFeet = 87})
local conditionRed = createConditionObject(CONDITION_OUTFIT)
setConditionParam(conditionRed, CONDITION_PARAM_TICKS, 1800 * 1000)
addOutfitCondition(conditionRed, {lookType = 130, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94})
function onThink(interval, lastExecution, thinkInterval)
for _, cid in ipairs(getPlayersOnline()) do
if getPlayerStorageValue(cid, 1002) == 1 then
doAddCondition(cid, conditionBlue)
elseif getPlayerStorageValue(cid, 1003) == 1 then
doAddCondition(cid, conditionRed)
end
end
return true
end
Code:
<globalevent name="changeMap" interval="1800" event="script" value="changeMap.lua"/>
<globalevent name="teamScores" interval="80" event="script" value="teamScores.lua"/>
<globalevent name="teams" interval="1800" event="script" value="teams.lua"/>
Creaturescript teamLogin.lua (sets the team of a player and teleports to the right map):
Code:
local maps = {
[1] = {mapName = "Ignitos", redTemple = {x = 1153, y = 1069, z = 6}, blueTemple = {x = 1146, y = 1120, z = 6}},
[2] = {mapName = "Dust2", redTemple = {x = 1169, y = 1192, z = 7}, blueTemple = {x = 1107, y = 1176, z = 6}},
[3] = {mapName = "Fridge", redTemple = {x = 1277, y = 1035, z = 3}, blueTemple = {x = 1225, y = 1035, z = 3}},
}
local teams = {
blueName = "Blue Bangbabies",
redName = "Red Rageboys",
blueScore = 101,
redScore = 102,
bluePlayerScore = 1004,
redPlayerScore = 1006,
}
local blueScore = 101
local redScore = 102
local conditionBlue = createConditionObject(CONDITION_OUTFIT)
setConditionParam(conditionBlue, CONDITION_PARAM_TICKS, 1800 * 1000)
addOutfitCondition(conditionBlue, {lookType = 130, lookHead = 87, lookBody = 87, lookLegs = 87, lookFeet = 87})
local conditionRed = createConditionObject(CONDITION_OUTFIT)
setConditionParam(conditionRed, CONDITION_PARAM_TICKS, 1800 * 1000)
addOutfitCondition(conditionRed, {lookType = 130, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94})
function onLogin(cid)
registerCreatureEvent(cid, "fixTeam")
registerCreatureEvent(cid, "scoreDeath")
registerCreatureEvent(cid, "lookScores")
setPlayerStorageValue(cid, 1002, 0)
setPlayerStorageValue(cid, 1003, 0)
local map = maps[getGlobalStorageValue(100)]
if map then
if getGlobalStorageValue(1000) > getGlobalStorageValue(1001) then
setPlayerStorageValue(cid, 1003, 1)
doAddCondition(cid, conditionRed)
doTeleportThing(cid, map.redTemple)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
setGlobalStorageValue(1001, getGlobalStorageValue(1001)+1)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You were sent to fight for the " .. teams.redName .. "!\nYour team have scored " .. getGlobalStorageValue(redScore) .. " kills.\nCurrent map is " .. map.mapName .. ".")
else
setPlayerStorageValue(cid, 1002, 1)
doAddCondition(cid, conditionBlue)
doTeleportThing(cid, map.blueTemple)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
setGlobalStorageValue(1000, getGlobalStorageValue(1000)+1)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You were sent to fight for the " .. teams.blueName .. "!\nYour team have scored " .. getGlobalStorageValue(blueScore) .. " kills.\nCurrent map is " .. map.mapName .. ".")
end
end
if getPlayerStorageValue(cid, 10000) == 1 then
doPlayerAddExperience(cid, -getPlayerExperience(cid) + getExperienceForLevel(130))
elseif getPlayerStorageValue(cid, 10000) ~= 1 then
doPlayerAddExperience(cid, -getPlayerExperience(cid) + getExperienceForLevel(100))
end
if isSorcerer(cid) or isDruid(cid) then
if getPlayerStorageValue(cid, 10000) == 1 then
setCreatureMaxHealth(cid, 795)
setCreatureMaxMana(cid, 3695)
for i = 1, -getPlayerMagLevel(cid)+60 do doPlayerAddMagLevel(cid, 1) end
else
setCreatureMaxHealth(cid, 645)
setCreatureMaxMana(cid, 2795)
for i = 1, -getPlayerMagLevel(cid)+50 do doPlayerAddMagLevel(cid, 1) end
end
elseif isPaladin(cid) then
if getPlayerStorageValue(cid, 10000) == 1 then
setCreatureMaxHealth(cid, 1405)
setCreatureMaxMana(cid, 1865)
for i = 1, -getPlayerMagLevel(cid)+16 do doPlayerAddMagLevel(cid, 1) end
for i = 1, -getPlayerSkillLevel(cid, SKILL_DIST)+80 do addEvent(delayDist, 0.2 * 1000, cid) end
else
setCreatureMaxHealth(cid, 1105)
setCreaureMaxMana(cid, 1415)
for i = 1, -getPlayerMagLevel(cid)+14 do doPlayerAddMagLevel(cid, 1) end
for i = 1, -getPlayerSkillLevel(cid, SKILL_DIST)+70 do addEvent(delayDist, 0.2 * 1000, cid) end
end
elseif isKnight(cid) then
if getPlayerStorageValue(cid, 10000) == 1 then
setCreatureMaxHealth(cid, 2015)
setCreatureMaxMana(cid, 645)
for i = 1, -getPlayerMagLevel(cid)+9 do doPlayerAddMagLevel(cid, 1) end
for i = 1, -getPlayerMeleeSkill(cid)+75 do addEvent(delaySkill, 0.2 * 1000, cid) end
for i = 1, -getPlayerSkillLevel(cid, SKILL_SHIELD)+75 do addEvent(delayShield, 0.2 * 1000, cid) end
else
setCreatureMaxHealth(cid, 1565)
setCreatureMaxMana(cid, 495)
for i = 1, -getPlayerMagLevel(cid)+8 do doPlayerAddMagLevel(cid, 1) end
for i = 1, -getPlayerMeleeSkill(cid)+65 do addEvent(delaySkill, 0.2 * 1000, cid) end
for i = 1, -getPlayerSkillLevel(cid, SKILL_SHIELD)+65 do addEvent(delayShield, 0.2 * 1000, cid) end
end
doCreatureAddHealth(cid, -getCreatureHealth(cid)+getCreatureMaxHealth(cid))
doCreatureAddMana(cid, -getCreatureMana(cid)+getCreatureMaxMana(cid))
end
return true
end
function delaySkill(cid)
doPlayerAddMeleeSkill(cid, 1)
end
function delayShield(cid)
doPlayerAddSkill(cid, SKILL_SHIELD, 1)
end
function delayDist(cid)
doPlayerAddSkill(cid, SKILL_DIST, 1)
end
Creaturescript teamLogout.lua:
Code:
function onLogout(cid)
if getPlayerStorageValue(cid, 1002) == 1 then
setGlobalStorageValue(1000, getGlobalStorageValue(1000)-1)
elseif getPlayerStorageValue(cid, 1003) == 1 then
setGlobalStorageValue(1001, getGlobalStorageValue(1001)-1)
setPlayerStorageValue(cid, 1003, -1)
end
return true
end
Creaturescript fixTeams.lua:
Code:
local maps = {
[1] = {mapName = "Ignitos", redTemple = {x = 1153, y = 1069, z = 6}, blueTemple = {x = 1146, y = 1120, z = 6}},
[2] = {mapName = "Dust2", redTemple = {x = 1169, y = 1192, z = 7}, blueTemple = {x = 1107, y = 1176, z = 6}},
[3] = {mapName = "Fridge", redTemple = {x = 1277, y = 1035, z = 3}, blueTemple = {x = 1225, y = 1035, z = 3}},
}
local teams = {
blueName = "Blue Bangbabies",
redName = "Red Rageboys",
blueScore = 101,
redScore = 102,
bluePlayerScore = 1004,
bluePlayerDScore = 1005,
redPlayerScore = 1006,
redPlayerDScore = 1007,
}
function onStatsChange(cid, attacker, type, combat, value)
local map = maps[getGlobalStorageValue(100)]
local expGain = (getPlayerLevel(cid) + 50)*0.01 * 50 * (getPlayerLevel(cid) * getPlayerLevel(cid)) - (5 * getPlayerLevel(cid) + 8)
if type == 1 then
if getCreatureHealth(cid) <= value then
if isPlayer(cid) and isCreature(attacker) then
if getPlayerStorageValue(cid, 1003) == 1 then
local corpse = doCreateItem(3058, 1, getPlayerPosition(cid))
doItemSetAttribute(corpse, "description", "You recognize " .. getCreatureName(cid) .. "[" .. teams.redName .. ", level " .. getPlayerLevel(cid) .. "]. He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".")
doTeleportThing(cid, map.redTemple, true)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You got pwned by the " .. teams.blueName .. "!")
doPlayerSendTextMessage(attacker, MESSAGE_EVENT_ADVANCE, "You pwned one of the " .. teams.redName .. "!")
setGlobalStorageValue(teams.blueScore, getGlobalStorageValue(teams.blueScore)+1)
setPlayerStorageValue(attacker, teams.bluePlayerScore, getPlayerStorageValue(attacker, teams.bluePlayerScore)+1)
setPlayerStorageValue(cid, teams.bluePlayerDScore, getPlayerStorageValue(cid, teams.bluePlayerDScore)+1)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid), true)
doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
doPlayerAddExperience(attacker, expGain)
doPlayerAddExperience(cid, -expGain)
doSendAnimatedText(getPlayerPosition(attacker), expGain, TEXTCOLOR_WHITE)
elseif getPlayerStorageValue(cid, 1002) == 1 then
local corpse = doCreateItem(3058, 1, getPlayerPosition(cid))
doItemSetAttribute(corpse, "description", "You recognize " .. getCreatureName(cid) .. "[" .. teams.blueName .. ", level " .. getPlayerLevel(cid) .. "]. He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".")
doTeleportThing(cid, map.blueTemple, true)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You got pwned by the " .. teams.redName .. "!")
doPlayerSendTextMessage(attacker, MESSAGE_EVENT_ADVANCE, "You pwned one of the " .. teams.blueName .. "!")
setGlobalStorageValue(teams.redScore, getGlobalStorageValue(teams.redScore)+1)
setPlayerStorageValue(attacker, teams.redPlayerScore, getPlayerStorageValue(attacker, teams.redPlayerScore)+1)
setPlayerStorageValue(cid, teams.redPlayerDScore, getPlayerStorageValue(cid, teams.redPlayerDScore)+1)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid), true)
doCreatureAddMana(cid, getCreatureMaxMana(cid), true)
doPlayerAddExperience(attacker, expGain)
doPlayerAddExperience(cid, -expGain)
doSendAnimatedText(getPlayerPosition(attacker), expGain, TEXTCOLOR_WHITE)
end
end
return false
end
end
return true
end
Code:
function onCombat(cid, target)
if isPlayer(cid) and isPlayer(target) then
if getPlayerStorageValue(cid, 1003) == 1 and getPlayerStorageValue(target, 1003) == 1 then
return doPlayerSendCancel(cid, "You may not attack your teammates.") and false
elseif getPlayerStorageValue(cid, 1002) == 1 and getPlayerStorageValue(target, 1002) == 1 then
return doPlayerSendCancel(cid, "You may not attack your teammates.") and false
end
end
return true
end
Code:
local teams = {
blueName = "Blue Bangbabies",
redName = "Red Rageboys",
blueScore = 101,
redScore = 102,
bluePlayerScore = 1004,
redPlayerScore = 1006,
bluePlayerDScore = 1005,
redPlayerDScore = 1007,
}
function onLook(cid, thing, position, lookDistance)
if isPlayer(thing.uid) then
if getPlayerStorageValue(thing.uid, 1002) == 1 then
doPlayerSetSpecialDescription(thing.uid, ".\nPwned " .. getPlayerStorageValue(thing.uid, teams.bluePlayerScore) .. " " .. teams.redName .. ".\nPwned " .. getPlayerStorageValue(thing.uid, teams.bluePlayerDScore) .. " times by the " .. teams.redName .. "")
elseif getPlayerStorageValue(thing.uid, 1003) == 1 then
doPlayerSetSpecialDescription(thing.uid, ".\nPwned " .. getPlayerStorageValue(thing.uid, teams.redPlayerScore) .. " " .. teams.blueName .. ".\nPwned " .. getPlayerStorageValue(thing.uid, teams.redPlayerDScore) .. " times by the " .. teams.blueName .. "")
end
end
return true
end
Code:
<event type="login" name="teamLogin" event="script" value="teamLogin.lua"/>
<event type="logout" name="teamLogout" event="script" value="teamLogout.lua"/>
<event type="combat" name="teamCombat" event="script" value="combat.lua"/>
<event type="statschange" name="fixTeam" event="script" value="fixTeam.lua"/>
<event type="look" name="lookScores" event="script" value="lookScores.lua"/>
Last edited: