function onStartUp()
if os.date('%A') == "Sunday" then
doCreateNpc("Rashid", {x = 11111, y = 11111, z = 11})
elseif os.date('%A') == "Monday" then
doCreateNpc("Rashid", {x = 22222, y = 22222, z = 22})
elseif os.date('%A') == "Tuesday" then
doCreateNpc("Rashid", {x = 33333, y = 33333, z = 33})
elseif os.date('%A') == "Wednesday" then
doCreateNpc("Rashid", {x = 44444, y = 44444, z = 44})
elseif os.date('%A') == "Thursday" then
doCreateNpc("Rashid", {x = 55555, y = 55555, z = 55})
elseif os.date('%A') == "Friday" then
doCreateNpc("Rashid", {x = 66666, y = 66666, z = 66})
elseif os.date('%A')...
function onStartUp()
if os.date('%A') == "Sunday" then
doCreateNpc("Rashid", {x = 11111, y = 11111, z = 11})
elseif os.date('%A') == "Monday" then
doCreateNpc("Rashid", {x = 22222, y = 22222, z = 22})
elseif os.date('%A') == "Tuesday" then
doCreateNpc("Rashid", {x = 33333, y = 33333, z = 33})
elseif os.date('%A') == "Wednesday" then
doCreateNpc("Rashid", {x = 44444, y = 44444, z = 44})
elseif os.date('%A') == "Thursday" then
doCreateNpc("Rashid", {x = 55555, y = 55555, z = 55})
elseif os.date('%A') == "Friday" then
doCreateNpc("Rashid", {x = 66666, y = 66666, z = 66})
elseif os.date('%A') == "Saturday" then
doCreateNpc("Rashid", {x = 77777, y = 77777, z = 77})
end
return true
end
local days = {
["Sunday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}},
{npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}},
{npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}}
},
["Monday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}}
},
["Tuesday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}}
},
["Wednesday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}}
},
["Thursday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}}
},
["Friday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}}
},
["Saturday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}}
}
}
function onStartUp()
local currentDay = os.date('%A')
for v, k in pairs(days) do
if currentDay == v then
for i = 1, #k do
doCreateNpc(k[i].npc, k[i].pos)
end
break
end
end
return true
end
Updated version to include multiple npc's, since this thread was linked to semi-recently. xD
Lua:local days = { ["Sunday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}}, {npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}}, {npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}} }, ["Monday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}} }, ["Tuesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}} }, ["Wednesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}} }, ["Thursday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}} }, ["Friday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}} }, ["Saturday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}} } } function onStartUp() local currentDay = os.date('%A') for v, k in pairs(days) do if currentDay == v then for i = 1, #k do doCreateNpc(k[i].npc, k[i].pos) end break end end return true end
Every 5 minutes he changes position?Xini all working fine, but this work only when server restart.
How change script to Create NPC Rashid on Time 23:55 on first place, second place etc ? Thanks for your reply.
deSpawnOnNextDay = true
those npcs are removed from the server whenever it moves to the next day. (up to 5 minute delay)deSpawnOnNextDay = false
they are not removed until next server shutdown. (note: if server is online for 8+ days, you'll get double spawned npcs.)local days = {
["Sunday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true},
{npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false},
{npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false}
},
["Monday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Tuesday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Wednesday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Thursday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Friday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Saturday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
}
}
local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes)
local previousDay = "Day"
local npcs = {}
local function removeNpcs()
for v, k in pairs(npcs) do
if isCreature(k.creature) then
doRemoveCreature(k.creature)
end
end
npcs = {}
end
local function npcSpawnChecker()
local currentDay = os.date('%A')
if currentDay ~= previousDay then
previousDay = currentDay
removeNpcs()
for v, k in pairs(days) do
if currentDay == v then
for i = 1, #k do
local creature = doCreateNpc(k[i].npc, k[i].pos)
if k[i].deSpawnOnNextDay then
npcs[#npcs + 1] = {creature = creature}
end
end
break
end
end
end
addEvent(npcSpawnChecker, delayBetweenChecks)
end
function onStartUp()
npcSpawnChecker()
return true
end
Every 5 minutes he changes position?
Or every time it changes to a new day he changes position?
Post automatically merged:
Well w/e, just gonna assume you meant the latter
NPC's are created upon start-up, based on day.
IfdeSpawnOnNextDay = true
those npcs are removed from the server whenever it moves to the next day. (up to 5 minute delay)
ifdeSpawnOnNextDay = false
they are not removed until next server shutdown. (note: if server is online for 8+ days, you'll get double spawned npcs.)
Lua:local days = { ["Sunday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}, {npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false}, {npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false} }, ["Monday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Tuesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Wednesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Thursday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Friday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Saturday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} } } local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes) local previousDay = "Day" local npcs = {} local function removeNpcs() for v, k in pairs(npcs) do local creature = Creature(k.creatureId) if creature then creature:remove() end end npcs = {} end local function npcSpawnChecker() local currentDay = os.date('%A') if currentDay ~= previousDay then previousDay = currentDay removeNpcs() for v, k in pairs(days) do if currentDay == v then for i = 1, #k do local creature = doCreateNpc(k[i].npc, k[i].pos) if k[i].deSpawnOnNextDay then npcs[#npcs + 1] = {creatureId = creature:getId()} end end addEvent(npcSpawnChecker, delayBetweenChecks) break end end end end function onStartUp() npcSpawnChecker() return true end
The original script already does this..Xikini , not every 5 minutes.
Function on start-up = create NPC only when do restart server.
If I don't restart server, NPC stay on position (etc. MONDAY) - two days not restart stay on monday position.
Sorry for my f**king ENG.
Maybe use function TIME, and removecreature (position prev) and createcreature (postionon next) ?
The original script already does this..
they spawn on start-up, and no other npc's will spawn regardless of how long the server has been up.
Server stays up for 5 days, and it'll stay monday npc
function onStartUp()
npcSpawnChecker()
return true
end
Sorry for probably asking a dumb question but do I put this in globalevents as a new script or do I add it to a existing script?Every 5 minutes he changes position?
Or every time it changes to a new day he changes position?
Post automatically merged:
Well w/e, just gonna assume you meant the latter
NPC's are created upon start-up, based on day.
IfdeSpawnOnNextDay = true
those npcs are removed from the server whenever it moves to the next day. (up to 5 minute delay)
ifdeSpawnOnNextDay = false
they are not removed until next server shutdown. (note: if server is online for 8+ days, you'll get double spawned npcs.)
Lua:local days = { ["Sunday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}, {npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false}, {npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false} }, ["Monday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Tuesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Wednesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Thursday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Friday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Saturday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} } } local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes) local previousDay = "Day" local npcs = {} local function removeNpcs() for v, k in pairs(npcs) do if isCreature(k.creature) then doRemoveCreature(k.creature) end end npcs = {} end local function npcSpawnChecker() local currentDay = os.date('%A') if currentDay ~= previousDay then previousDay = currentDay removeNpcs() for v, k in pairs(days) do if currentDay == v then for i = 1, #k do local creature = doCreateNpc(k[i].npc, k[i].pos) if k[i].deSpawnOnNextDay then npcs[#npcs + 1] = {creature = creature} end end addEvent(npcSpawnChecker, delayBetweenChecks) break end end end end function onStartUp() npcSpawnChecker() return true end
yes xPSorry for probably asking a dumb question but do I put this in globalevents as a new script or do I add it to a existing script?
Once again sorry, I'm relatively new to this
data/globalevents/globalevents.xml
<globalevent name="xxxxxxxxx" type="start" event="script" value="xxxxxxxxx.lua"/>
data/globalevents/scripts/xxxxxxxxx.lua
Thank you sir and this should work for tfs 1.2 too right? =)yes xP
as a new script
data/globalevents/globalevents.xml
and script goes intoXML:<globalevent name="xxxxxxxxx" type="start" event="script" value="xxxxxxxxx.lua"/>
data/globalevents/scripts/xxxxxxxxx.lua
No, the above is for tfs 0.x servers.Thank you sir and this should work for tfs 1.2 too right? =)
<globalevent type="startup" name="XxxxxXxxxx" script="xxxxxxx.lua" />
local days = {
["Sunday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true},
{npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false},
{npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false}
},
["Monday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Tuesday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Wednesday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Thursday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Friday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
},
["Saturday"] = {
{npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}
}
}
local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes)
local previousDay = "Day"
local npcs = {}
local function removeNpcs()
for v, k in pairs(npcs) do
local npc = Npc(k.npcId)
if isNpc(npc) then
npc:remove()
end
end
npcs = {}
end
local function npcSpawnChecker()
local currentDay = os.date('%A')
if currentDay ~= previousDay then
previousDay = currentDay
removeNpcs()
for v, k in pairs(days) do
if currentDay == v then
for i = 1, #k do
local npc = Game.createNpc(k[i].npc, k[i].pos)
if k[i].deSpawnOnNextDay then
npcs[#npcs + 1] = {npcId = npc:getId()}
end
end
break
end
end
end
addEvent(npcSpawnChecker, delayBetweenChecks)
end
function onStartUp()
npcSpawnChecker()
return true
end
Thanks but I am getting following error:No, the above is for tfs 0.x servers.
tfs 1.0+ is below
XML:<globalevent type="startup" name="XxxxxXxxxx" script="xxxxxxx.lua" />
Lua:local days = { ["Sunday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}, {npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false}, {npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false} }, ["Monday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Tuesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Wednesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Thursday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Friday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Saturday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} } } local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes) local previousDay = "Day" local npcs = {} local function removeNpcs() for v, k in pairs(npcs) do local npc = Npc(k.npcId) if isNpc(npc) then npc:remove() end end npcs = {} end local function npcSpawnChecker() local currentDay = os.date('%A') if currentDay ~= previousDay then previousDay = currentDay removeNpcs() for v, k in pairs(days) do if currentDay == v then for i = 1, #k do local npc = Game.createNpc(k[i].npc, k[i].pos) if k[i].deSpawnOnNextDay then npcs[#npcs + 1] = {npcId = npc:getId()} end end break end end end addEvent(npcSpawnChecker, delayBetweenChecks) end function onStartUp() npcSpawnChecker() return true end
function onStartup()
Are you sure you copied the entire script?Thanks but I am getting following error:
[Warning - Event::checkScript] Event onStartup not found. scripts/npctravel.lua
Tried addingto the script and error went away but rashid is not spawningLua:function onStartup()
Yes that's what I found odd.Are you sure you copied the entire script?
Because onStartUp is at the bottom.
<globalevent type="startup" name="TravellingNPC" script="npctravel.lua" />
local days = {
["Sunday"] = {
{npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true},
{npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false},
{npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false}
},
["Monday"] = {
{npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true}
},
["Tuesday"] = {
{npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true}
},
["Wednesday"] = {
{npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true}
},
["Thursday"] = {
{npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true}
},
["Friday"] = {
{npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true}
},
["Saturday"] = {
{npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true}
}
}
local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes)
local previousDay = "Day"
local npcs = {}
local function removeNpcs()
for v, k in pairs(npcs) do
local npc = Npc(k.npcId)
if isNpc(npc) then
npc:remove()
end
end
npcs = {}
end
local function npcSpawnChecker()
local currentDay = os.date('%A')
if currentDay ~= previousDay then
previousDay = currentDay
removeNpcs()
for v, k in pairs(days) do
if currentDay == v then
for i = 1, #k do
local npc = Game.createNpc(k[i].npc, k[i].pos)
if k[i].deSpawnOnNextDay then
npcs[#npcs + 1] = {npcId = npc:getId()}
end
end
break
end
end
end
addEvent(npcSpawnChecker, delayBetweenChecks)
end
function onStartUp()
npcSpawnChecker()
return true
end
Try this.Yes that's what I found odd.
I have only changed x,y,z.
in globalevents.xml
XML:<globalevent type="startup" name="TravellingNPC" script="npctravel.lua" />
and the script:
Lua:local days = { ["Sunday"] = { {npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true}, {npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false}, {npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false} }, ["Monday"] = { {npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true} }, ["Tuesday"] = { {npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true} }, ["Wednesday"] = { {npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true} }, ["Thursday"] = { {npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true} }, ["Friday"] = { {npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true} }, ["Saturday"] = { {npc = "Rashid", pos = {x = 32348, y = 32832, z = 7}, deSpawnOnNextDay = true} } } local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes) local previousDay = "Day" local npcs = {} local function removeNpcs() for v, k in pairs(npcs) do local npc = Npc(k.npcId) if isNpc(npc) then npc:remove() end end npcs = {} end local function npcSpawnChecker() local currentDay = os.date('%A') if currentDay ~= previousDay then previousDay = currentDay removeNpcs() for v, k in pairs(days) do if currentDay == v then for i = 1, #k do local npc = Game.createNpc(k[i].npc, k[i].pos) if k[i].deSpawnOnNextDay then npcs[#npcs + 1] = {npcId = npc:getId()} end end break end end end addEvent(npcSpawnChecker, delayBetweenChecks) end function onStartUp() npcSpawnChecker() return true end
local days = {
["Sunday"] = {
{npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true},
--{npc = "Npc 2", pos = Position(1000, 1000, 7), deSpawnOnNextDay = false},
--{npc = "Npc 3", pos = Position(1000, 1000, 7), deSpawnOnNextDay = false}
},
["Monday"] = {
{npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true}
},
["Tuesday"] = {
{npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true}
},
["Wednesday"] = {
{npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true}
},
["Thursday"] = {
{npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true}
},
["Friday"] = {
{npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true}
},
["Saturday"] = {
{npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true}
}
}
local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes)
local previousDay = "Day"
local npcs = {}
local function removeNpcs()
for v, k in pairs(npcs) do
local npc = Npc(k.npcId)
if isNpc(npc) then
npc:remove()
end
end
npcs = {}
end
local function npcSpawnChecker()
print("Checking current day..")
local currentDay = os.date('%A')
print(currentDay, previousDay)
if currentDay ~= previousDay then
print("New day found.. spawning npcs..")
previousDay = currentDay
removeNpcs()
for v, k in pairs(days) do
if currentDay == v then
for i = 1, #k do
print("Spawning Npc named " .. k[i].npc .. "")
local npc = Game.createNpc(k[i].npc, k[i].pos)
if k[i].deSpawnOnNextDay then
print("adding to npc table for removal, as deSpawnOnNextDay = true")
npcs[#npcs + 1] = {npcId = npc:getId()}
end
end
break
end
end
end
addEvent(npcSpawnChecker, delayBetweenChecks)
end
function onStartup()
print("TravellingNPC script is functional.")
npcSpawnChecker()
return true
end
Try this.
Tell me what prints to console
Lua:local days = { ["Sunday"] = { {npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true}, --{npc = "Npc 2", pos = Position(1000, 1000, 7), deSpawnOnNextDay = false}, --{npc = "Npc 3", pos = Position(1000, 1000, 7), deSpawnOnNextDay = false} }, ["Monday"] = { {npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true} }, ["Tuesday"] = { {npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true} }, ["Wednesday"] = { {npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true} }, ["Thursday"] = { {npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true} }, ["Friday"] = { {npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true} }, ["Saturday"] = { {npc = "Rashid", pos = Position(32348, 32832, 7), deSpawnOnNextDay = true} } } local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes) local previousDay = "Day" local npcs = {} local function removeNpcs() for v, k in pairs(npcs) do local npc = Npc(k.npcId) if isNpc(npc) then npc:remove() end end npcs = {} end local function npcSpawnChecker() print("Checking current day..") local currentDay = os.date('%A') print(currentDay, previousDay) if currentDay ~= previousDay then print("New day found.. spawning npcs..") previousDay = currentDay removeNpcs() for v, k in pairs(days) do if currentDay == v then for i = 1, #k do print("Spawning Npc named " .. k[i].npc .. "") local npc = Game.createNpc(k[i].npc, k[i].pos) if k[i].deSpawnOnNextDay then print("adding to npc table for removal, as deSpawnOnNextDay = true") npcs[#npcs + 1] = {npcId = npc:getId()} end end break end end end addEvent(npcSpawnChecker, delayBetweenChecks) end function onStartUp() print("TravellingNPC script is functional.") npcSpawnChecker() return true end
>> Loading config
>> Establishing database connection... MySQL 6.1.2
>> Running database manager
> Optimizing table players_online... [success]
> Optimizing table tile_store... [success]
>> Loading groups
>> Loading vocations
>> Loading items
>> Loading script systems
[Warning - Event::checkScript] Event onStartup not found. scripts/npctravel.lua
>> Loading monsters
>> Loading outfits
>> Checking world type... PVP
>> Loading map
> Map size: 33568x33111.
> Map loading time: 4.967 seconds.
> Loaded house items in: 0.017 s
>> Initializing gamestate
>> Loaded all modules, server starting up...
>> Forgotten Server Online!
copy again, I edited post. xPCode:>> Loading config >> Establishing database connection... MySQL 6.1.2 >> Running database manager > Optimizing table players_online... [success] > Optimizing table tile_store... [success] >> Loading groups >> Loading vocations >> Loading items >> Loading script systems [Warning - Event::checkScript] Event onStartup not found. scripts/npctravel.lua >> Loading monsters >> Loading outfits >> Checking world type... PVP >> Loading map > Map size: 33568x33111. > Map loading time: 4.967 seconds. > Loaded house items in: 0.017 s >> Initializing gamestate >> Loaded all modules, server starting up... >> Forgotten Server Online!
^ same as before =(
Perfect. Script works perfectly now =)copy again, I edited post. xP
Every 5 minutes he changes position?
Or every time it changes to a new day he changes position?
Post automatically merged:
Well w/e, just gonna assume you meant the latter
NPC's are created upon start-up, based on day.
IfdeSpawnOnNextDay = true
those npcs are removed from the server whenever it moves to the next day. (up to 5 minute delay)
ifdeSpawnOnNextDay = false
they are not removed until next server shutdown. (note: if server is online for 8+ days, you'll get double spawned npcs.)
Lua:local days = { ["Sunday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true}, {npc = "Npc 2", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false}, {npc = "Npc 3", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = false} }, ["Monday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Tuesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Wednesday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Thursday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Friday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} }, ["Saturday"] = { {npc = "Rashid", pos = {x = 1000, y = 1000, z = 7}, deSpawnOnNextDay = true} } } local delayBetweenChecks = 300000 -- 1000 * 60 * 5 (5 minutes) local previousDay = "Day" local npcs = {} local function removeNpcs() for v, k in pairs(npcs) do if isCreature(k.creature) then doRemoveCreature(k.creature) end end npcs = {} end local function npcSpawnChecker() local currentDay = os.date('%A') if currentDay ~= previousDay then previousDay = currentDay removeNpcs() for v, k in pairs(days) do if currentDay == v then for i = 1, #k do local creature = doCreateNpc(k[i].npc, k[i].pos) if k[i].deSpawnOnNextDay then npcs[#npcs + 1] = {creature = creature} end end break end end end addEvent(npcSpawnChecker, delayBetweenChecks) end function onStartUp() npcSpawnChecker() return true end