Raikou
Well-Known Member
- Joined
- Jul 18, 2007
- Messages
- 145
- Solutions
- 2
- Reaction score
- 54
Hello all,
I got a problem with getting the onKill event triggered more than once.
Several checks have been done and my conclusion is that the script gets triggered several times.
The script is called within the creaturescript:
<event type="kill" name="Bosskill" script="Bosskill.lua"/>
From there on it lands into the following lua:
This boss is done by 2 to 4 people.
With 2 people it seems to be triggered mostly once, but if it 3 or 4 it gets triggered more often.
I made an attempt with the playerTable but it's only locally so that won't help if the script gets called twice.
Anyone has a good suggestion what's going on, or what i could change?
I got a problem with getting the onKill event triggered more than once.
Several checks have been done and my conclusion is that the script gets triggered several times.
The script is called within the creaturescript:
<event type="kill" name="Bosskill" script="Bosskill.lua"/>
From there on it lands into the following lua:
Lua:
function onKill(creature, target)
local config = {
["asmadeus"] = {
loot = {{2152,100,85},{7759,25,5}},
message = "Congratulations for defeating Asmadeus, Your reward is now in your backpack",
BagId = 9774
},
local monster = config[Creature(target):getName():lower()] --boss name to give reward
local playerTable = {}
if not monster then --check if killed monster(target) is the boss
print(Creature(target):getName():lower() .. " Not correct monster")
return true --if not, return true
end
print(Creature(target):getName():lower() .. " Correct monster")
for pid, _ in pairs(target:getDamageMap()) do --get damageMap from target killed
local attackerPlayer = Player(pid) --get userData of each player that damaged the target
if attackerPlayer and playerTable[attackerPlayer] ~= 1 then --if player exist and not get reward yet
local bag = attackerPlayer:addItem(monster.BagId, 1)
print("Created bag for: " .. attackerPlayer:getName() .. "!")
for i = 1,#monster.loot do
if monster.loot[i][2] >= math.random(1,100) then
local amount = math.random(1,monster.loot[i][3])
bag:addItem(monster.loot[i][1], amount, INDEX_WHEREEVER, FLAG_NOLIMIT)
end
end
attackerPlayer:sendTextMessage(22, monster.message)
end
playerTable[attackerPlayer] = 1
end
return true
end
This boss is done by 2 to 4 people.
With 2 people it seems to be triggered mostly once, but if it 3 or 4 it gets triggered more often.
I made an attempt with the playerTable but it's only locally so that won't help if the script gets called twice.
Anyone has a good suggestion what's going on, or what i could change?