• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

RevScripts onKill event

darkmu

Active Member
Joined
Aug 26, 2007
Messages
273
Solutions
1
Reaction score
49
Location
Paraná,Brazil
I'm a little rusty, can anyone help me improve this code? What is happening is that if the second onwards kills the monster he is inserting it several times in the table, and I need to block to insert only once.

Lua:
function killMonsterHunter.onKill(creature, target)
    local monster = Monster(target)

    if not monster:isMonster() or monster:getMaster() or monster:isPlayer() then
        return true
    end   
    
    for pid, p in pairs(monster:getDamageMap()) do   
        
        local creature = Creature(pid)
        if creature then               
            local player = Player(creature)
            
            if player then           
                local position = target:getPosition()
                if target:getName():lower() == 'rat' then                   
                    if #MonsterHunter > 0 then                       
                        for i = 1, #MonsterHunter do   
                            
                            if MonsterHunter[i].id ~= player:getGuid() then   
                                local tableProperty = {
                                    id = player:getGuid(),
                                    name = player:getName(),
                                    kills = 0
                                    }
                                table.insert(MonsterHunter, tableProperty)
                            else                               
                                local killerTeam = MonsterHunter[i]
                                killerTeam.kills = killerTeam.kills + 1                                   
                            end                           
                        end
                    else
                        local tableProperty = {
                                id = player:getGuid(),
                                name = player:getName(),
                                kills = 0
                            }
                        table.insert(MonsterHunter, tableProperty)   
                    end                   
                    Game.createMonster('Rat', position, true, true)
                end
            end
        end
    end
    return true
end
 
Top