• 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 - NEW version, bug free, updated

In TFS 0.4 in /data/lib/zombie_event.lua should be this:
PHP:
-- CONFIG
ZE_DEFAULT_NUMBER_OF_PLAYERS = 1
ZE_ACCESS_TO_IGNORE_ARENA = 3
-- POSITIONS
ZE_blockEnterItemPosition = {x= 797, y=731, z=15}
ZE_enterPosition = {x = 850, y = 701, z = 15}
ZE_kickPosition = {x=792, y=731, z=15}
ZE_spawnFromPosition = {x = 836, y = 692, z = 15}
ZE_spawnToPosition = {x = 859, y = 712, z = 15}
-- ITEM IDS
ZE_blockEnterItemID = 8634
-- STORAGES
-- - player
ZE_isOnZombieArea = 39970
-- - global
ZE_STATUS = 39970 -- =< 0 - off, 1 - waiting for players, 2 - is running
ZE_PLAYERS_NUMBER = 39971
ZE_ZOMBIES_TO_SPAWN = 39972
ZE_ZOMBIES_SPAWNED = 39973
 
-- FUNCTION
 
function setZombiesEventPlayersLimit(value)
	doSetStorage(ZE_PLAYERS_NUMBER, value)
end
 
function getZombiesEventPlayersLimit()
	return getStorage(ZE_PLAYERS_NUMBER)
end
 
function addPlayerToZombiesArea(cid)
	doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
	doTeleportThing(cid, ZE_enterPosition, true)
	doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
	if(getPlayerAccess(cid) < ZE_ACCESS_TO_IGNORE_ARENA) then
		setPlayerZombiesEventStatus(cid, os.time())
	end
end
 
function kickPlayerFromZombiesArea(cid)
	doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
	doTeleportThing(cid, ZE_kickPosition, true)
	doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
	setPlayerZombiesEventStatus(cid, 0)
end
 
function getPlayerZombiesEventStatus(cid)
	return getCreatureStorage(cid, ZE_isOnZombieArea)
end
 
function setPlayerZombiesEventStatus(cid, value)
	doCreatureSetStorage(cid, ZE_isOnZombieArea, value)
end
 
function getZombiesEventPlayers()
	local players = {}
	for i, cid in pairs(getPlayersOnline()) do
		if(getPlayerZombiesEventStatus(cid) > 0) then
			table.insert(players, cid)
		end
	end
	return players
end
 
function getZombiesCount()
	return getStorage(ZE_ZOMBIES_SPAWNED)
end
 
function addZombiesCount()
	doSetStorage(ZE_ZOMBIES_SPAWNED, getStorage(ZE_ZOMBIES_SPAWNED)+1)
end
 
function resetZombiesCount()
	doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
end
 
function getZombiesToSpawnCount()
	return getStorage(ZE_ZOMBIES_TO_SPAWN)
end
 
function setZombiesToSpawnCount(count)
	doSetStorage(ZE_ZOMBIES_TO_SPAWN, count)
end
 
function addZombiesEventBlockEnterPosition()
	if(getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID).uid == 0) then
		doCreateItem(ZE_blockEnterItemID, 1, ZE_blockEnterItemPosition)
	end
end
 
function removeZombiesEventBlockEnterPosition()
	local item = getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID)
	if(item.uid ~= 0) then
		doRemoveItem(item.uid)
	end
end
 
function spawnNewZombie()
	local posx = {}
	local posy = {}
	local posz = {}
	local pir = {}
	for i=1, 5 do
		local posx_tmp = math.random(ZE_spawnFromPosition.x ,ZE_spawnToPosition.x)
		local posy_tmp = math.random(ZE_spawnFromPosition.y ,ZE_spawnToPosition.y)
		local posz_tmp = math.random(ZE_spawnFromPosition.z ,ZE_spawnToPosition.z)
		local pir_tmp = 0
		local spec = getSpectators({x=posx_tmp, y=posy_tmp, z=posz_tmp}, 3, 3, false)
		if(spec and #spec > 0) then
			for z, pid in pairs(spec) do
				if(isPlayer(pid)) then
					pir_tmp = pir_tmp + 1
				end
			end
		end
		posx[i] = posx_tmp
		posy[i] = posy_tmp
		posz[i] = posz_tmp
		pir[i] = pir_tmp
	end
	local lowest_i = 1
	for i=2, 5 do
		if(pir[i] < pir[lowest_i]) then
			lowest_i = i
		end
	end
	local ret = (type(doCreateMonster("Zombie Event", {x=posx[lowest_i], y=posy[lowest_i], z=posz[lowest_i]}, false, false, false)) == 'number')
	if(ret) then
		addZombiesCount()
	end
	return ret
end

Thank you :) Bye
 
weak, why did he have to break compatibility :p

I only said how it is done in TFS 0.4.

It can be done in other way like this (without breaking compatibility :) ):
Lua:
local monster = getCreatureByName(NAME)

if isCreature(monster) then
	if doTileQueryAdd(monster, POS) == RETURNVALUE_NOERROR then
		doCreateMonster(NAME, POS)
	end
end
 
When the players enter to arena, the event never start because it says, that nobody is in arena, but there is!.
what is the problem???
 
Set on teleport ActionId that you set in movements.xml (5555?)
In this code is actionid:
PHP:
 <movevent type="StepIn" actionid="5555" event="script" value="zombie/onenter.lua"
 
I have a question, whether it is possible after the event, the "Zombies Event" to die or disappear..
 
I had problem with magic walls on arena. If you have it too, replace in mwall/wild growth (spell/rune):
Lua:
function onCastSpell(cid, var)
	return doCombat(cid, combat, var)
end
with:
Lua:
function onCastSpell(cid, var)
	if(getPlayerZombiesEventStatus(cid) <= 0) then
		return doCombat(cid, combat, var)
	else
		return false
	end
end
 
Auto start event

dervin13 said:
The teeleport could appear, when the even start, ...
I don't like scripts where teleports appear, because something (player,monster, m-wall...) can block this position and teleport doesn't appear :(

--------------------------------------------------------------
PM from dervin13 said:
Finally! Done! Ty for script man!
Could you transform script of talkaction in globalevent, to go automatically??
Yes :)
Create ../data/globalevents/scripts/zombie/onstartup_autostart.lua and paste:
Lua:
function onStartup()
	doSetStorage(45267, os.time()+300)
	doSetStorage(45268, 0)
	return true
end

Create ../data/globalevents/scripts/zombie/onthink_autostart.lua and paste:
Lua:
local autoStartInterval = 60 -- time between arenas in minutes, default 60 = 1 hour

function onThink(interval, lastExecution, thinkInterval)
	if(getStorage(ZE_STATUS) ~= 2) then
		if(getStorage(45267)+autoStartInterval*60 <= os.time() and getStorage(45268) ~= 1) then
			doSetStorage(45268, 1)
			removeZombiesEventBlockEnterPosition()
			doSetStorage(ZE_STATUS, 1)
			doBroadcastMessage("Zombie Arena Event teleport will be opened for 2 minutes. We are waiting for " .. getZombiesEventPlayersLimit() - #getZombiesEventPlayers() .. " players to start.")
		elseif(getStorage(45267)+autoStartInterval*60+120 <= os.time() and getStorage(45268) == 1) then
			addZombiesEventBlockEnterPosition()
			doSetStorage(45268, 0)
			doSetStorage(ZE_STATUS, 2)
			doSetStorage(45267, os.time())
			doBroadcastMessage("Zombie Arena Event started.")
		end
	end
	return true
end

In ../data/globalevents/globalevents.xml add:
XML:
<globalevent name="ZombieGlobalThink_AutoStart" interval="5" event="script" value="zombie/onthink_autostart.lua"/>
<globalevent name="ZombieGlobalStartup_AutoStart" type="start" event="script" value="zombie/onstartup_autostart.lua"/>
 
Error: Debug Using Rev 4389 TFS 0.4? (Client 8.71)

Debugs apon killing zombie. Simple fix tho. In Creaturescripts\scripts\zombie\ondeath.lua

replace
PHP:
	doCreatureSay(cid, "I'll be back!", 19)

with
PHP:
	doCreatureSay(cid, "I'll be back!", TALKTYPE_ORANGE_1)


Cheers!

edit:
sorry the proper way to code that using my rev would have been..
PHP:
	doCreatureSay(cid, "I'll be back!", 13)

but both should work fine
 
Last edited:
For some reason when i turn on the event the object thats set dosent disapear, And the countdown of players dosent occur.
Im guessing its because of this error.............
[Error - GlobalEvent Interface]
data/globalevents/scripts/zombie/onstartup.lua:eek:nStartup
Description:
data/globalevents/scripts/zombie/startup.lua:2: in function attemp to call field 'execute query <a nil value>
stack traceback:
data/globalevents/scripts/zombie/startup.lua:2 in function <data/globalevents/scripts/zombie/onstartup.lua:1>

I realy wana use this Event and the script looks fine to me, so if anybody knows the problem Please can you tell me how to solve it, thanks.

ImageShack? - Online Photo and Video Hosting
 
For some reason when i turn on the event the object thats set dosent disapear, And the countdown of players dosent occur.
Im guessing its because of this error.............
[Error - GlobalEvent Interface]
data/globalevents/scripts/zombie/onstartup.lua: onStartup
Description:
data/globalevents/scripts/zombie/startup.lua:2: in function attemp to call field 'execute query <a nil value>
stack traceback:
data/globalevents/scripts/zombie/startup.lua:2 in function <data/globalevents/scripts/zombie/onstartup.lua:1>

I realy wana use this Event and the script looks fine to me, so if anybody knows the problem Please can you tell me how to solve it, thanks.

ImageShack� - Online Photo and Video Hosting
 
I had problem with magic walls on arena. If you have it too, replace in mwall/wild growth (spell/rune):
Lua:
function onCastSpell(cid, var)
	return doCombat(cid, combat, var)
end
with:
Lua:
function onCastSpell(cid, var)
	if(getPlayerZombiesEventStatus(cid) <= 0) then
		return doCombat(cid, combat, var)
	else
		return false
	end
end


All players in server can't use spells in moment of event ?
This might become a problem.

Nice Code.

Thanks :cool:
 
can anyone tell me where to put position of the teleport??? or i put it from the map and have to put uniqid or aid????
 
Back
Top