Prestin32k
New Member
- Joined
- Jul 16, 2012
- Messages
- 20
- Reaction score
- 0
Hi guys, I need youre help. I created a NPC summoner, who spawns monsters on demand.
There's a delay of 60 seconds between each reqeusts, so once in 60 seconds players can ask for monsters.
I use os.difftime for this, but the problem is, that I believe os.difftime is called system wide, so when I place multiple NPC's they trigger eachothers timer. Making it 60 seconds delay for _EVERY_ NPC when someone asks for monsters one time.
Would be great if someone helped me out!
The goal is: Let each NPC summon individually with their own timer.
TFS 1.1
PrinterLua RL-PACK
There's a delay of 60 seconds between each reqeusts, so once in 60 seconds players can ask for monsters.
I use os.difftime for this, but the problem is, that I believe os.difftime is called system wide, so when I place multiple NPC's they trigger eachothers timer. Making it 60 seconds delay for _EVERY_ NPC when someone asks for monsters one time.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local lastSound = 0
function onThink()
if lastSound < os.time() then
lastSound = (os.time() + 5)
if math.random(100) < 15 then
Npc():say("Keywords: rats, rotworm, cyclops, orc, dragons. Becareful!", TALKTYPE_SAY)
end
end
npcHandler:onThink()
end
local function greetCallback(cid)
local player = Player(cid)
npcHandler:setMessage(MESSAGE_GREET, 'Hi |PLAYERNAME|, what do you wish me to summon? Try rats, rotworm, cyclops, orc, dragons')
return true
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local rats = { 'Rat', 'Rat', 'Rat', 'Rat' }
local rots = { 'Rotworm', 'Carrion Worm', 'Rotworm', 'Rotworm' }
local cycs = { 'Cyclops', 'Cyclops Smith', 'Cyclops' }
local orcs = { 'Orc Berserker', 'Orc Berserker', 'Orc Leader' }
local dragons = { 'Dragon', 'Dragon Hatchling' }
t1 = os.time()
local time = os.difftime(t1, t2)
local player = Player(cid)
if time >= 60 then
if msgcontains(msg, "rat") then
for i = 1, #rats do
Game.createMonster(rats[i], Npc():getPosition())
print(time)
end
t2 = os.time()
end
if msgcontains(msg, "rotworm") then
for i = 1, #rots do
Game.createMonster(rots[i], Npc():getPosition())
print(time)
end
t2 = os.time()
end
if msgcontains(msg, "cyclops") then
for i = 1, #cycs do
Game.createMonster(cycs[i], Npc():getPosition())
print(time)
end
t2 = os.time()
end
if msgcontains(msg, "orc") then
for i = 1, #orcs do
Game.createMonster(orcs[i], Npc():getPosition())
print(time)
end
t2 = os.time()
end
if msgcontains(msg, "dragon") then
for i = 1, #dragons do
Game.createMonster(dragons[i], Npc():getPosition())
print(time)
end
t2 = os.time()
end
end
Npc():say(60 - time .. " seconds left for a new spawn", TALKTYPE_SAY)
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Would be great if someone helped me out!
The goal is: Let each NPC summon individually with their own timer.
TFS 1.1
PrinterLua RL-PACK