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

CreatureEvent Monster gives % xp

athenso

Average Coder
Joined
May 31, 2011
Messages
155
Solutions
3
Reaction score
23
I used this for a simple "click bush, math.random(1,20) monster spawn" sort of thing.

None of the code is mine, i just put the pieces together.

First you need to add the function(050-function):
Code:
function doPlayerAddPercentLevel(cid, percent)
    local player_lv, player_lv_1 = getExperienceForLevel(getPlayerLevel(cid)), getExperienceForLevel(getPlayerLevel(cid)+1)
    local percent_lv = ((player_lv_1 - player_lv) / 100) * percent
    doPlayerAddExperience(cid, percent_lv)
end

Creature script
Code:
<event type="kill" name="ZombieBush" event="script" value="zombiebush.lua"/>

zombiebush.lua
Code:
local t = {
   monsterName = 'zombie'
}

function onKill(cid, target, flags)
   if getCreatureName(target):lower() == t.monsterName:lower() then
     doPlayerAddPercentLevel(cid, 2)
   end
   return true
end

login
Code:
registerCreatureEvent (cid, "ZombieBush")
 
I appreciate it. I wanted to create another way for players to grind in a sense.

I was hoping for a bit more feedback/possible improvement.
 
Last edited:
I believe more people will comment if you would add server version, a small explanation about the system and maybe a picture.
Well done, keep it up :)

Kind Regards,
Eldin
 
Here is a better way to add more monsters and a certain percentage.
Code:
local t = {
["zombie"] = {percent = 2},
["rat"] = {percent = 5}
}

function onKill(cid, target, flags)
    for name, t in pairs(t) do
        if (name == getCreatureName(target):lower()) then
            doPlayerAddPercentLevel(cid, t.percent)
        end
    end
   return true
end
 
This is really cool man would be good to use on raid bosses or something.
 
Here is a better way to add more monsters and a certain percentage.
Code:
local t = {
["zombie"] = {percent = 2},
["rat"] = {percent = 5}
}

function onKill(cid, target, flags)
    for name, t in pairs(t) do
        if (name == getCreatureName(target):lower()) then
            doPlayerAddPercentLevel(cid, t.percent)
        end
    end
   return true
end
no need to iterate the entire table
 
Tables are a thing I am still learning. I can never seem to find just a blank example
 
Back
Top