• 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!

[Task] Monster counter

kamilcioo

Veteran OT User
Joined
Jul 25, 2008
Messages
977
Solutions
1
Reaction score
289
Hey, I need some help. My script only counts 1 person who attacks the monster and I wanna make it that it counts kill for everyone who attacked the monster.


Code:
local config = {
     ['cockroach'] = {amount = 20, storage = 20001, startstorage = 20000, startvalue = 1}
   
}
function onKill(cid, target)
     local monster = config[getCreatureName(target):lower()]
     if isPlayer(target) or not monster or isSummon(target) then
         return true
     end

     if getPlayerStorageValue(cid, monster.storage) >= -1 and (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue then
         setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
         doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(getPlayerStorageValue(cid, monster.storage)+1)..' of '..monster.amount..' '..getCreatureName(target)..'s killed.')
     end
     if (getPlayerStorageValue(cid, monster.storage)+1) == monster.amount then
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(getPlayerStorageValue(cid, monster.storage)+1)..' '..getCreatureName(target)..'s and completed the '..getCreatureName(target)..'s mission.')
         setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
     end
     return true
end
 
Last edited:
Code:
local config = {
  ['cockroach'] = {amount = 20, storage = 20001, startstorage = 20000, startvalue = 1}
}

function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
     local creature = Creature(cid)
     local monster = config[creature:getName():lower()]
     if not monster or creature:getMaster() then
         return true
     end

     local damageMap = creature:getDamageMap()
     for pid, damage in pairs(damageMap) do
         local player = Player(pid)
         if player then
             if (player:getStorageValue(monster.storage)+1) < monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
                 player:setStorageValue(monster.storage, player:getStorageValue(monster.storage) +1)
                 player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(player:getStorageValue(monster.storage) +1)..' of '..monster.amount..' '..creature:getName()..'s killed.')
             end
             if (player:getStorageValue(monster.storage)+1) == monster.amount then
                 player:setStorageValue(monster.storage, player:getStorageValue(monster.storage) +1)
                 player:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(player:getStorageValue(monster.storage)+1)..' '..creature:getName()..'s and completed the '..creature:getName()..'s mission.')
             end
         end
     end
     return true
end
Register the script in the monsters instead of in login.lua.
Like this
Code:
<script>
     <event name="Name"/>
</script>
 
Last edited:
I'm getting a bug "Event OnKill not found".
I've tried to add "function onKill(cid, target)", scripts dont give a bug but it doesn't count monsters. Any idea?
 
Add it with type death in creaturescripts.xml.
Also don't forgot to not register it in login.lua but in the monster file.
 
Can you post the monster file how you added it?
And also creaturescripts.xml, make sure to not register it in login.lua, so if it's still registered there, remove it.
 
Back
Top