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

GlobalEvent Creating NPC in different places every day

Tairens

Member
Joined
Sep 23, 2007
Messages
90
Reaction score
5
This script is creating npc in different places every day like Rashid on real Tibia.
Fill config for your positions.Create in data/globalevents/scripts file "npcCreate.lua"
Code:
function getDayName()
	local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
	return days[os.date("*t")["wday"]]
end

local config =
{
	respawnPlaces = 
	{
		["Sunday"] = {x =, y = , z =}, 
		["Monday"] = {x =, y = , z =},  
		["Tuesday"] = {x =, y = , z =}, 
		["Wednesday"] = {x =, y = , z =}, 
		["Thursday"] = {x =, y = , z =}, 
		["Friday"] = {x =, y = , z =}, 
		["Saturday"] = {x =, y = , z =}
	},
	npcName = "Rashid"
}

function onStartup()
	doCreateNpc(config.npcName, config.respawnPlaces[getDayName()])
	return true
end

In data/globalevents/globalevents.xml add:
Code:
<globalevent name="npcCreate" type="startup" event="script" value="npcCreate.lua"/>

Yours,
Tairens
 
That's great

Is there a way to make it work like:

Saturday 14:00
Spawns NPC

etc?
 
@up
Lua:
function getDayName()
	local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
	return days[os.date("*t")["wday"]]
end

local config =
{
	respawnPlaces = 
	{
		["Sunday"] = {x =, y = , z =}, 
		["Monday"] = {x =, y = , z =},  
		["Tuesday"] = {x =, y = , z =}, 
		["Wednesday"] = {x =, y = , z =}, 
		["Thursday"] = {x =, y = , z =}, 
		["Friday"] = {x =, y = , z =}, 
		["Saturday"] = {x =, y = , z =}
	},
	npcName = "Rashid"
}

function onTimer()
	doCreateNpc(config.npcName, config.respawnPlaces[getDayName()])
	return true
end


XML:
<globalevent name="npcCreate" time="hour:minutes" event="script" value="npcCreate.lua"/>

i have just changed the function, now will be done everyday checking a hour, you can set up the hour in time="hour:minutes"
 
Instead of getDayName(), os.date('%A') can be used
 
@up
Lua:
function getDayName()
	local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
	return days[os.date("*t")["wday"]]
end

local config =
{
	respawnPlaces = 
	{
		["Sunday"] = {x =, y = , z =}, 
		["Monday"] = {x =, y = , z =},  
		["Tuesday"] = {x =, y = , z =}, 
		["Wednesday"] = {x =, y = , z =}, 
		["Thursday"] = {x =, y = , z =}, 
		["Friday"] = {x =, y = , z =}, 
		["Saturday"] = {x =, y = , z =}
	},
	npcName = "Rashid"
}

function onTimer()
	doCreateNpc(config.npcName, config.respawnPlaces[getDayName()])
	return true
end


XML:
<globalevent name="npcCreate" time="hour:minutes" event="script" value="npcCreate.lua"/>

i have just changed the function, now will be done everyday checking a hour, you can set up the hour in time="hour:minutes"

If u do that, the game will creates many of the same NPC in the map , or im wrong???
 
@JTCV15
~> doRemoveCreature(getCreatureByName(config.npcName))
before spawning
 
Lua:
function getDayName()
	local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
	return days[os.date("*t")["wday"]]
end
 
local config =
{
	respawnPlaces = 
	{
		["Sunday"] = {x =, y = , z =}, 
		["Monday"] = {x =, y = , z =},  
		["Tuesday"] = {x =, y = , z =}, 
		["Wednesday"] = {x =, y = , z =}, 
		["Thursday"] = {x =, y = , z =}, 
		["Friday"] = {x =, y = , z =}, 
		["Saturday"] = {x =, y = , z =}
	},
	npcName = "Rashid"
}
 
function onTimer()
	doRemoveCreature(getCreatureByName(config.npcName) )
	doCreateNpc(config.npcName, config.respawnPlaces[getDayName()])
	return true
end
 
Lua:
function getDayName()
	local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
	return days[os.date("*t")["wday"]]
end
 
local config =
{
	respawnPlaces = 
	{
		["Sunday"] = {x =, y = , z =}, 
		["Monday"] = {x =, y = , z =},  
		["Tuesday"] = {x =, y = , z =}, 
		["Wednesday"] = {x =, y = , z =}, 
		["Thursday"] = {x =, y = , z =}, 
		["Friday"] = {x =, y = , z =}, 
		["Saturday"] = {x =, y = , z =}
	},
	npcName = "Rashid"
}
 
function onTimer()
	doRemoveCreature(getCreatureByName(config.npcName) )
	doCreateNpc(config.npcName, config.respawnPlaces[getDayName()])
	return true
end

>onTimer
Remove the "r"...wait, why onTime? onThink it would be.
 
Back
Top