• 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!

Zombie Event - Without Bugs! Work on all TFS

Oskar1121

Excellent OT User
Joined
Jul 15, 2009
Messages
633
Reaction score
537
Location
Poland
MAP!
Click to download map




Make file into mods folder and paste this:

~~TFS 0.4+~~
Lua:
<?xml version='1.0' encoding='ISO-8859-1'?>
<mod name='Zombie Event' version='2.0' author='Oskar' contact='[email protected]' enabled='yes'>
<config name='zombieEvent_conf'><![CDATA[
zombieRewards = {
				random = false, --czy ma losowac nagrode
				rew = {2160,5} --nagrody, wypelniamy w ten sposob {itemId1, count1, itemId2, count2 ...}
				}

zombieMaxPlayers = 1 --ilosc graczy wymaganych do rozpoczecia eventu
zombieMinPlayers = 1 --minimalna ilosc graczy
zombieAccesToIgnore = 5 --acces ktory nie jest liczony jako osoba uczestniczaca w evencie
timeOnJoinToEvent = 10 --ilosc minut ktora czeka skrypt na wymagana ilosc graczy

zombieJoinType = 'booth' --movement, talkaction lub oba, sposob dolaczania sie do eventu

-- POSITIONS
zombieKickPosition = {x=1517,y=1501,z=7} --gdzie wyrzuca graczy po wyrzuceniu z eventu (przegranej)
zombieEnterPosition = {x=1639,y=1269,z=7} --pozycja gdzie teleportuje graczy po rozpoczeciu eventu

zombieCenterRoomPosition = {x=1638,y=1269,z=7} --idealny srodek pomieszczenia
zombieRangeX_RangeY = {22,18} --szerokosc oraz wysokosc pomieszczenia dzielona przez dwa (liczone w najszerszych miejscach)

zombieStorageStatus = 13300 --storage uzywane do eventu

ZOMBIE = {
		  --UWAGA! NAZWY POTWORÓW KONIECZNIE PISANE Z MAŁYCH LITER!
		  --['nazwa potwora'] = {szansa na stworzenie, szansa na zainfekowanie}
			['horned mutant'] = {20,1},
			['vile centurion'] = {15,2},
			['daidalost'] = {10,4},
			['mongrel man'] = {5,8},
			['propell zombie'] = {2,16},
			['scrathclaw'] = {1,32}
			}

function chooseZombieMonster()
local monster = false
for k, v in pairs(ZOMBIE) do
	monster = monster or (math.random(100) <= v[1] and k or false)
end
return monster or chooseZombieMonster()
end

function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
	pos.stackpos = i
	local tile = getTileThingByPos(pos)
		if tile.itemid ~= 0 and not isCreature(tile.uid) then
			if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
				return false
			end
		end
end
return true
end

local _f = doTeleportThing
function doTeleportThing(cid, newpos, ignoreBlocking)
	return (ignoreBlocking or isWalkable(newpos, true, true, false) or false) and _f(cid, newpos, true)
end
 
function getZombiesEventPlayers()
	local players = {}
	for _, cid in pairs(getPlayersOnline()) do
		if getCreatureStorage(cid, zombieStorageStatus) == 1 and getPlayerAccess(cid) < zombieAccesToIgnore then
			table.insert(players, cid)
		end
	end
	return players
end

function kickPlayerFromZombiesArea(cid)
	doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
	doTeleportThing(cid, zombieKickPosition, true)
	doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
	return doCreatureSetStorage(cid, zombieStorageStatus, 0) and doCreatureSetNoMove(cid, false)
end

function loseOnZombieArena(cid)
    local players, msg = getZombiesEventPlayers(), ''
	doCreatureSetStorage(cid, zombieStorageStatus+1, 0)
    kickPlayerFromZombiesArea(cid)
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You are dead.')
    if(#getZombiesEventPlayers() <= 1) then
        local winner = getZombiesEventPlayers()[1] or players[1]
        if winner then
            if zombieRewards.random then
				local i = math.random(#zombieRewards.rew/2)
				local rewardItem = doPlayerAddItem(winner, zombieRewards.rew[i*2-1], zombieRewards.rew[i*2], true)
			else
				for i = 1, #zombieRewards.rew/2 do
					doPlayerAddItem(winner, zombieRewards.rew[i*2-1], zombieRewards.rew[i*2], true)
				end
			end
			doPlayerSendTextMessage(winner, MESSAGE_INFO_DESCR, 'You won Zombie Event.')
            msg = getCreatureName(winner) .. ' won Zombie Event.'
            kickPlayerFromZombiesArea(winner)
        else
            msg = 'Zombie Event finished! No one win!'
        end
		if getSpectators(zombieCenterRoomPosition, zombieRangeX_RangeY[1], zombieRangeX_RangeY[2]) then
			for _, v in ipairs(getSpectators(zombieCenterRoomPosition, zombieRangeX_RangeY[1], zombieRangeX_RangeY[2])) do
				if isMonster(v) then
					doRemoveThing(v)
				elseif isPlayer(v) then
					kickPlayerFromZombiesArea(v)
				end
			end
		end
		doSetStorage(zombieStorageStatus, 0)
    end
return (msg ~= '' and doBroadcastMessage(msg) or true)
end
 
function addPlayerToZombiesArea(cid, block)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
doTeleportThing(cid, zombieEnterPosition, true)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
return doCreatureSetStorage(cid, zombieStorageStatus, 1) and doCreatureSetNoMove(cid, block)
end
 
function spawnNewZombie(fromPosition, n)
local n, pos = n or 0, {x = zombieCenterRoomPosition.x + math.random(-zombieRangeX_RangeY[1],zombieRangeX_RangeY[1]), y = zombieCenterRoomPosition.y + math.random(-zombieRangeX_RangeY[2],zombieRangeX_RangeY[2]), z = zombieCenterRoomPosition.z}
if isWalkable(pos, true, true, true) then 
	local monster = chooseZombieMonster()
    local cid = doCreateMonster((monster == '' and 'horned mutant' or monster), pos, false)
	doSendMagicEffect(pos, CONST_ME_MORTAREA)
	return (isMonster(cid) and registerCreatureEvent(cid, 'zombieEventDeath') and registerCreatureEvent(cid, 'zombieEventThink')) and (fromPosition and doSendDistanceShoot(fromPosition, pos, CONST_ANI_SUDDENDEATH) or true)
end
return (n < 200 and spawnNewZombie(fromPosition, n+1) or true)
end

function setZombieEventStart()
if getStorage(zombieStorageStatus) < 1 then 
	doSetStorage(zombieStorageStatus, 1)
	doBroadcastMessage('Zombie Arena Event is started. If you want join to event say !zombie join or enter the teleport in depot. We wait on '..zombieMaxPlayers..' players.')
	if getSpectators(zombieCenterRoomPosition, zombieRangeX_RangeY[1], zombieRangeX_RangeY[2]) then
		for _, cid in pairs(getSpectators(zombieCenterRoomPosition, zombieRangeX_RangeY[1], zombieRangeX_RangeY[2])) do
			if isMonster(cid) then doRemoveThing(cid) end
		end
	end
end
return true
end
]]></config>

<event type='death' name='zombieEventDeath' event='script'><![CDATA[
domodlib('zombieEvent_conf')
function onDeath(cid)
	for i = 1, math.random(2) do
		spawnNewZombie(getThingPos(cid))
	end
	doSendMagicEffect(getThingPos(cid), CONST_ME_MORTAREA)
	return doCreatureSay(cid, 'I\'ll be back!', TALKTYPE_ORANGE_1)
end
]]></event>

<event type='think' name='zombieEventThink' event='script'><![CDATA[
domodlib('zombieEvent_conf')
function onThink(cid)
local name, target = getCreatureName(cid):lower(), getCreatureTarget(cid)
if isMonster(cid) and ZOMBIE[name] and target and isPlayer(target) then
	if getCreatureStorage(target, zombieStorageStatus+1) < os.time() and getDistanceBetween(getThingPos(target), getThingPos(cid)) <= 1 and math.random(100) <= ZOMBIE[name][2] then
		doSendAnimatedText(getThingPos(target), 'INFECTED!', COLOR_LIGHTGREEN)
		doCreatureSetStorage(target, zombieStorageStatus+1, os.time() + 3)
		doPlayerSendTextMessage(target, MESSAGE_STATUS_CONSOLE_BLUE, 'You are infected. You can cure, just say "disable infection", but remember, you have only three seconds on it.')
		return addEvent(function()
								if isPlayer(target) then
									if getCreatureStorage(target, zombieStorageStatus+1) ~= os.time() then
										return false
									end
									doCreatureAddHealth(target, getCreatureMaxHealth(target))
									return loseOnZombieArena(target) 
								end return true end,
								3000,
								target)
	end
end
return true
end
]]></event>

<talkaction words='disable' event='script'><![CDATA[
domodlib('zombieEvent_conf')
function onSay(cid, words, param, channel)
if getCreatureStorage(cid, zombieStorageStatus+1) < os.time() or param ~= 'infection' then
	return false
end
doSendAnimatedText(getThingPos(cid), 'CURE!', COLOR_LIGHTBLUE)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You use an antidote on infection.')
return doCreatureSetStorage(cid, zombieStorageStatus+1, 0)
end
]]></talkaction>

<event type='statschange' name='zombieEventStatsChange' event='script'><![CDATA[
domodlib('zombieEvent_conf')
function onStatsChange(cid, attacker, type, combat, value)
if isMonster(attacker) and isPlayer(cid) and ZOMBIE[getCreatureName(attacker):lower()] and type == STATSCHANGE_HEALTHLOSS and math.abs(value) >= getCreatureHealth(cid) then
	doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
	return loseOnZombieArena(cid) and false
end
return true
end
]]></event>

<globalevent name='zombieStart' type='start' event='script'><![CDATA[
domodlib('zombieEvent_conf')
function onStartup()
	return doSetStorage(zombieStorageStatus, 0)
end
]]></globalevent>

<moveevent type='stepIn' uniqueid='3000' event='script'><![CDATA[
domodlib('zombieEvent_conf')
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
if zombieJoinType == 'talkaction' then
	return doTeleportThing(cid, fromPosition, true) end
local msg = ''
if isPlayer(cid) then
	if getCreatureCondition(cid, CONDITION_INFIGHT) and getPlayerAccess(cid) < zombieAccesToIgnore then
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You have a PZ! You have to get rid of it. Somehow.')
	end
	if getPlayerAccess(cid) >= zombieAccesToIgnore then
		setZombieEventStart()
		return doTeleportThing(cid, zombieEnterPosition, true)
	elseif #getZombiesEventPlayers() < zombieMaxPlayers and getStorage(zombieStorageStatus) == 1 then
		addPlayerToZombiesArea(cid, true)
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You are player of number '..#getZombiesEventPlayers()..', which join to event.')
		if #getZombiesEventPlayers() == zombieMaxPlayers then
			doSetStorage(zombieStorageStatus, 2)
			for i = 1, math.random(2) do
				spawnNewZombie(getThingPos(cid))
			end
			for _, v in pairs(getZombiesEventPlayers()) do
				addPlayerToZombiesArea(v, false)
			end
			msg = 'Zombie Event is started. We have ' .. zombieMaxPlayers .. ' players, which joined to event. Have fun!'
		else
			msg = getCreatureName(cid) .. ' has entered a Zombie Arena. We still need ' .. zombieMaxPlayers - #getZombiesEventPlayers() .. ' players.'
		end
		return (msg ~= '' and doBroadcastMessage(msg) or true)
	else
		return doTeleportThing(cid, fromPosition, true) and doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Arena is full.')
	end
end
return true
end
]]></moveevent>

<talkaction words='!zombie' event='script'><![CDATA[
domodlib('zombieEvent_conf')
function onSay(cid, words, param, channel)
if zombieJoinType == 'movement' then
	return false end
local msg = ''
if isInArray({'join','add','go','joined'}, param:lower()) then
	if getCreatureCondition(cid, CONDITION_INFIGHT) and getPlayerAccess(cid) <= zombieAccesToIgnore then
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You have a PZ! You have to get rid of it. Somehow.')
	end
	if getPlayerAccess(cid) >= zombieAccesToIgnore then
		setZombieEventStart()
		return doTeleportThing(cid, zombieEnterPosition, true)
	elseif #getZombiesEventPlayers() < zombieMaxPlayers and getStorage(zombieStorageStatus) == 1 then
		addPlayerToZombiesArea(cid, true)
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You are player of number '..#getZombiesEventPlayers()..', which join to event.')
		if #getZombiesEventPlayers() == zombieMaxPlayers then
			doSetStorage(zombieStorageStatus, 2)
			for i = 1, math.random(2) do
				spawnNewZombie(getThingPos(cid))
			end
			for _, v in pairs(getZombiesEventPlayers()) do
				addPlayerToZombiesArea(v, false)
			end
			msg = 'Zombie Event is started. We have ' .. zombieMaxPlayers .. ' players, which joined to event. Have fun!'
		else
			msg = getCreatureName(cid) .. ' has entered a Zombie Arena. We still need ' .. zombieMaxPlayers - #getZombiesEventPlayers() .. ' players.'
		end
		return (msg ~= '' and doBroadcastMessage(msg) or true)
	else
		return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (getStorage(zombieStorageStatus) == -1 and 'Event is no started.' or 'Arena is full.'))
	end
elseif isInArray({'leave','abort','delete'}, param:lower()) then
	if getStorage(zombieStorageStatus) < 2 then
		doCreatureSetStorage(cid, zombieStorageStatus, 0)
		doCreatureSetNoMove(cid, false)
		return doTeleportThing(cid, getCreatureLastPosition(cid), true)
	end
	return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You can\'t leave from arena if event is already running.')
end
return true
end
]]></talkaction>

<globalevent name="zombieTime" time="19:01" event="script"><![CDATA[
domodlib("zombieEvent_conf")
function onTimer()
	addEvent(function()
						if getStorage(zombieStorageStatus) == 2 then return true end
						if getStorage(zombieStorageStatus) == 1 and #getZombiesEventPlayers() >= zombieMinPlayers then
							doSetStorage(zombieStorageStatus, 2)
							for i = 1, math.random(2) do
								spawnNewZombie(getThingPos(cid))
							end
							for _, v in ipairs(getZombiesEventPlayers()) do
								addPlayerToZombiesArea(v, false)
							end
							return doBroadcastMessage('Zombie Event is started. We have '..#getZombiesEventPlayers()..' players on area')
						end
						for _, v in ipairs(getZombiesEventPlayers()) do
							kickPlayerFromZombiesArea(v)
						end
						return doBroadcastMessage('Zombie Event is stopped. We could not find enough players.')
						end,
						timeOnJoinToEvent * 1000 * 60)
						
	return setZombieEventStart()
end
]]></globalevent>

<event type="login" name="zombieEventLogin" event="script"><![CDATA[
function onLogin(cid)
	doCreatureSetStorage(cid, zombieStorageStatus, 0)
	return registerCreatureEvent(cid, 'zombieEventStatsChange')
end
]]></event>
</mod>




Now go to data/monsters and create 6 files about names and paste:
horned mutant.xml
vile centurion.xml
daidalost.xml
mongrel man.xml
propell zombie.xml
scrathclaw.xml

Into monsters.xml add:
PHP:
<monster name="Horned mutant" file="horned mutant.xml"/>
<monster name="Vile centurion" file="vile centurion.xml"/>
<monster name="Daidalost" file="daidalost.xml"/>
<monster name="Mongrel man" file="mongrel man.xml"/>
<monster name="Propell zombie" file="propell zombie.xml"/>
<monster name="Scrathclaw" file="scrathclaw.xml"/>


PHP:
ZE_REWARDS = {
				random = false,
				rew = {2160,5,2645,1}
				}
random - do you want to rand rewards
rew - rewards, example {itemId1, count1, itemId2, count2 ... itemIdX, countX}

PHP:
ZE_MAX_PLAYERS = 1
Number of requied players to start event

PHP:
ZE_ACCESS_TO_IGNORE_ARENA = 7
Number of acces who does't to count all of player which joined to event

PHP:
ZE_kickPosition = {x=1517,y=1501,z=7}
ZE_enterPosition = {x=1595,y=1501,z=7}
First position is place where player will be teleported, when he die.
Second position is place where all of players, who joined to event will be teleported, but just only event is started

PHP:
ZE_centerRoomPosition = {x=1601,y=1503,z=7}
ZE_rX_rY = {22,18}
Position is center of the zombie arena.
Second variable is size of arena in 'x' and 'y' length.

PHP:
ZE_STATUS = 13300
Storage number

PHP:
ZOMBIE = {
			['horned mutant'] = {20,1},
			['vile centurion'] = {15,2},
			['daidalost'] = {10,4},
			['mongrel man'] = {5,8},
			['propell zombie'] = {2,16},
			['scrathclaw'] = {1,32}
			}
['monsterName'] = {chanceOnSpawnOnArena, chanceOnInfection}
When zombie is die then on arena spawned from 1 to 2 new zombies.


Okey. When event is started we can joined on two variants:
[*] Enter in teleport, which are in dp (uniqueid='3000')
[*] Use command !zombie join and wait on start

Zombie event can be to start in this part of script:
PHP:
globalevent name="zombieTime" time="23:01"
Where time is... just time xd



When you will be infected, we have three seconds to use the command ('disable infection') in order to cure.


Sorry for my english
 
Last edited:
put in monsters.xml


<monster name="Horned mutant" file="horned mutant.xml"/>
<monster name="Vile centurion" file="vile centurion.xml"/>
<monster name="Daidalost" file="daidalost.xml"/>
<monster name="Mongrel man" file="mongrel man.xml"/>
<monster name="Propell zombie" file="propell zombie.xml"/>
<monster name="Scrathclaw" file="scrathclaw.xml"/>
 
That's my error, i can make a better imppaint if you want, don't know if it can help you to solve the error but..
I can join the event throw the teleport and I recive 'Zombie Event started', but then this error appears and don't spawn any
monster..
Maybe are you missing something? I tried to solve but no results.

error.jpg
 
18:06 Zombie Arena Event is started. If you want join to event say !zombie join or enter the teleport in depot. We wait on 1 players.
18:07 Zombie Event is started.

The same error appears, but i can tell you something more:
error 2.PNG

And yes, I have put the monsters on monsters.xml i can summon it with a GOD. Thanks
 
Does it work to tfs 0.3.6?
And please map!
 
Last edited:
First post is edited. Script now work good and I added a map, top on my post.
 
tfs 0.3.6
[21/11/2011 10:26:00] [Error - GlobalEvents::timer] Couldn't execute event: zombieTime
 
I have a question i tested it with gm and i only joined will it summon zombies or not, because it didnt summon something and i didnt get any error.
 
Last edited:
I tryed with normal player, it didnt create any monster and i didnt get any error! tfs 0.3.6
 
Back
Top