This is an example script that i made to implement world changes. This one will create NPC Yasir in Liberty Bay, Ankrahmun or Carlin (Note that the script will creates only the npc, not the whole ship). Also, this shows you how to change the position of Rashid, depending of the day.
The script sets a global storage when a change is made to make Towncryer alert about the change.
(The excessive tab is made by the forum, paste it at Notepad and you'll see it normal)
Enjoy
The script sets a global storage when a change is made to make Towncryer alert about the change.
(The excessive tab is made by the forum, paste it at Notepad and you'll see it normal)
Lua:
function onStartup()
--Mini world changes
local changes =
{
--[id] = {storage = x, chance = %, change = function() doTheChange end}[,]
{storage = 61260, chance = 25, change = function() --Yasir 25%
local random = math.random(1, 3)
local cities =
{
[1] = {x = 33101, y = 32885, z = 6}, --ankrahmun
[2] = {x = 32323, y = 32895, z = 6},-- liberty bay
[3] = {x = 32400, y = 31815, z = 6} --carlin
}
return doCreateNpc("Yasir", cities[random])
end}
}
for _, wc in ipairs(changes) do
if math.random(1, 100) <= wc.chance then
wc.change()
doSetStorage(wc.storage, 1)
end
end
--RASHID
local days =
{
[1] = {x = 32328, y = 31782, z = 6}, --Sunday // Domingo
[2] = {x = 32207, y = 31155, z = 7}, --Monday // Lunes
[3] = {x = 32300, y = 32837, z = 7}, --Tuesday // Martes
[4] = {x = 32577, y = 32753, z = 7}, --Wednesday // Miercoles
[5] = {x = 33066, y = 32879, z = 6}, --Thursday // Jueves
[6] = {x = 33235, y = 32483, z = 7}, --Friday // Viernes
[7] = {x = 33166, y = 31810, z = 6} --Saturday // Sabado
}
local day = os.date("*t").wday
if days[day] then
doCreateNpc("Rashid", days[day])
else
print("[!] -> Cannot create Rashid. Day: " .. day .. ".")
end
return true
end
Enjoy