• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[SOLVED] [CreatureScripts] BonusExp for Killing Monsters [1.0]

Eldin

Eldin Projects
Joined
Jun 12, 2008
Messages
1,334
Reaction score
615
Location
Sweden
Okey, Another script! :)
Im trying to add a script for my 1.0 server that Points people towards right hunting grounds.
This script will give a player some bonus exp if he or she kills a creature within the right lvls.
(I set Bug high as im trying it on the bug)

Creaturescripts.xml
Code:
 <event type="kill" name="BonusExp" script="BonusExp.lua"/>

BonusExp.lua
Code:
function isWithinRange(number, minN, maxN)
 if maxN == nil then
 maxN = math.huge
 end
 
 if number >= minN and number <= maxN then
 return true
 end
 return false
end
 
check = {extraexp, extraprcnt}
 
 
function onKill(cid, target)
monsters = {
 {name = "Bug", normexp = 18, minlvl = 1, maxlvl = 10, extraexp = 1000},
 {name = "Dragon", normexp = 4200, minlvl = 30, maxlvl = 60, extraexp = 500*getPlayerLevel(cid)},
 {name = "Rat", normexp = 5, minlvl = 1, extraprcnt = 10}
}

 for i, a in pairs(monsters) do
 if a.name == getCreatureName(target) then
 if isWithinRange(getPlayerLevel(cid), a.minlvl, a.maxlvl) == true then
 if a.extraexp then
 doPlayerAddExp(cid, a.extraexp)
 end
 if a.extraprcnt then
 doPlayerAddExp(cid, a.normexp/a.extraprcnt)
 end
 a.extraexp = a.extraexp or 0
 a.extraprcnt = a.extraprcnt or 0
 doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "For killing a monster over your level, you gained " .. a.extraexp + (a.normexp/a.extraprcnt) .. " extra experience points.")
 end
 end
 end
 return 1
end

I got no errors in the logg and I tryed to re-check all the "doPlayerAddExp" etc for 1.0.
The Problem right now is that I DONT get any BONUSEXP when killing as for example a Bug.
A text wont appear either.

Here is the original Script:
http://otland.net/threads/bonus-exp-when-killing-difficult-monsters.141638/

Thanks in advance!

Kind Regards,
Eldin.
 
try this:
Code:
local monsters =
{
   ["Dragon"] =
   {
     level = {30,60},
     normExp = 4200,
     bonusExp = normExp*0.1 -- to get a percent worth, means 10% of the actual exp as bonus exp
   },
   ["Bug"] =
   {
     level = {1,10},
     normExp = 18,
     bonusExp = 5
   },
   ["Rat"] =
   {
     level = {1,5},
     normExp = 5,
     bonusExp = 2
   }
}
 


function onKill(cid, target)
local mon = monsters[getCreatureName(target)]
   if mon then
     if getPlayerLevel(cid) >= mon.level[1] and getPlayerLevel(cid) <= mon.level[2] then
       doPlayerAddExp(cid, mon.bonusExp)
     end
   end
   return true
end
 
Last edited:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Bonus Exp" version="1.0" author="norrow" contact="otland.net" enabled="yes">
    <config name="cfg"><![CDATA[
        cfgBExp = {
            bonusMin = 5, -- min % of bonus
            bonusMax = 15, -- max % of bonus
            bonusChance = 50 -- chance to get bonus
        }
    ]]></config>
    <!-- Bonus Experience (registering event) -->
    <event type="login" name="PlayerLogin" event="script"><![CDATA[
    function onLogin(cid)
        registerCreatureEvent(cid, "BonusExp")
    return TRUE
    end
    ]]></event>
    <!-- Bonus Experience -->
    <event type="kill" name="BonusExp" event="script">  <![CDATA[
    domodlib('cfg') 
    function onKill(cid, target)
        if math.random(1, 100) <= cfgBExp.bonusChance then
            local bexp = getMonsterInfo(getCreatureName(target)).experience  *math.random(cfgBExp.bonusMin, cfgBExp.bonusMax)/100
            local bexpC = math.ceil(bexp)
            doPlayerAddExperience(cid, bexpC)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, bexpC .." bonus experience!")
        end
    return TRUE
    end
    ]]></event>
</mod>
 
Evil Hero Script:

Code:
local monsters =
{
  ["Dragon"] =
  {
  level = {30,60},
  normExp = 4200,
  bonusExp = normExp*0.1 -- to get a percent worth, means 10% of the actual exp as bonus exp
  },
  ["Bug"] =
  {
  level = {1,10},
  normExp = 18,
  bonusExp = 1000
  },
  ["Rat"] =
  {
  level = {1,5},
  normExp = 5,
  bonusExp = 2
  }
}
 
function onKill(cid target)
local mon = monsters[getCreatureName(target)]
  if mon then
  if getPlayerLevel(cid) >= mon.level[1] and getPlayerLevel(cid) <= mon.level[2] then
  doPlayerAddExp(cid, mon.bonusExp)
  end
  end
  return true
end

ERROR:
Code:
[Warning - Event: : checkScript] Can not load script: script/BonusExp.lua
data/creaturescripts/scripts/BonusExp.lua:23: ')' expected near 'target'

Kind Regards,
Eldin.
 
I should have noticed that aswell, too much wine, uhm... ^^

New Error:
BonusExpError1_zps2e4f560c.jpg


Goes faster with Picture then Writing as I cant copy.

Kind Regards,
Eldin.
 
Will be on maximum an hour more, "DJ"ing, then sleep atleast 8 hours.
Im updating and staying ready :)

I do appriciate it alot, thank you for atleast trying.

/Eldin
 
there we go:
Code:
local monsters =
{
   ["Dragon"] =
   {
     level = {30,60},
     normExp = 4200,
     bonusExp = "percent", -- to get a percent worth.
     mult = 0.1 -- would mean 10% of the actual exp of the monster.
   },
   ["Bug"] =
   {
     level = {1,10},
     normExp = 18,
     bonusExp = 5
   },
   ["Rat"] =
   {
     level = {1,5},
     normExp = 5,
     bonusExp = 2
   }
}


function onKill(cid, target)
local mon = monsters[getCreatureName(target)]
   if mon then
     if getPlayerLevel(cid) >= mon.level[1] and getPlayerLevel(cid) <= mon.level[2] then
       doPlayerAddExp(cid, mon.bonusExp == "percent" and mon.normExp*mon.mult or mon.bonusExp)
     end
   end
   return true
end
 
No bug error in the logg but it aint working, or, no bonuses appear. I set the bug bonusExp to 1000 to avoid any misstake at all, the character is lvl 6.

Kind Regards,
Eldin.
 
add this
Code:
print(1)
after
Code:
function onKill(cid, target)
and
Code:
print(2)
after
Code:
if mon then

just to verify if it does even execute the script or not at all.
watch your console if you see 1 or 2 after you kill a monster.
 
Added, no new error:

Code:
local monsters =
{
  ["Dragon"] =
  {
  level = {30,60},
  normExp = 4200,
  bonusExp = "percent", -- to get a percent worth.
  mult = 0.1 -- would mean 10% of the actual exp of the monster.
  },
  ["Bug"] =
  {
  level = {1,10},
  normExp = 18,
  bonusExp = 1000
  },
  ["Rat"] =
  {
  level = {1,5},
  normExp = 5,
  bonusExp = 2
  }
}


function onKill(cid, target)
print(1)
local mon = monsters[getCreatureName(target)]
  if mon then
  print(2)
  if getPlayerLevel(cid) >= mon.level[1] and getPlayerLevel(cid) <= mon.level[2] then
  doPlayerAddExp(cid, mon.bonusExp == "percent" and mon.normExp*mon.mult or mon.bonusExp)
  end
  end
  return true
end
 
You have everything correctly registered or? (login.lua and the xml file)
If yes then I pretty much know what this causes...
I'm not familiar with 1.0 but it's based on 0.2 and that version doesn't support buffers on creatureevents.
That pretty much means you have to combine all your onKill scripts into a single one, sounds weird but it's the only solution I know of tbh.
 
Yes I do, posted exactly what I got in the first post.
Something for Tal to add then ;)

Probably means my "onKill" - "MonsterCounter" wont work because of the same reason then.
I guess thats it :)

I would like to Thank You ALOT for the time you spent to help, really appriciate it.

Kind Regards,
Eldin.
 
You didn't mention that you registered it in login.lua (in your first post)
Code:
registerCreatureEvent(cid, "BonusExp")
if you probably forgot that who knows :p
if not just post me all of the 3 different onKill scripts and I'll combine them for you.
 
This is my new Login, so I dont Think I need to register it anymore as im used too ^^
Code:
function onLogin(cid)
  local player = Player(cid)
  local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
  if player:getLastLoginSaved() <= 0 then
  loginStr = loginStr .. " Please proceed."
  player:sendOutfitWindow()
  else
  if loginStr ~= "" then
  player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
  end

  loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
  end
  player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

  local welcomeText = "Welcome " .. getCreatureName(cid) .. ", to the world of " .. configManager.getString(configKeys.SERVER_NAME) .. ".\n\nNeed any help? Open the Help Channel!"
  local text = "GENERAL INFORMATION:\n-Amulet of Loss will be set for free if you don't wear one.\n-You will NOT loose anything during Deaths Up to lvl 20.\n-Items will be added for free when gaining levels up to lvl 20.\n-You can only enter ProtectionZones and Temples in your own Race-Town.\n-Potions have 4 seconds ExhaustTime, combine with Runes for best Strategy.\n\nLIST OF COMMANDS:\n!online -> Shows players Online.\n!serverinfo -> Shows general server information.\n!kills -> Shows your Kills.\n!deathlist \"playername -> Shows that Players DeathList.\n!buyhouse -> Buy a House by standing infront of the door to that house.\n!leavehouse -> Leave your house.\nOpen Chat-Channels, The Race Chats can ONLY be seen by THAT RACE.\n\n-Visit www.otland.net and search for RaceWars for more information."

  doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, text)

  if getPlayerStorageValue(cid, 19622) < 1 then
  broadcastMessage(welcomeText, MESSAGE_STATUS_WARNING)
  setPlayerStorageValue(cid, 19622, 1)
  end

  player:registerEvent("PlayerDeath")
  return true
end

------------------------------------------------------------
The next one that aint working is:

creaturesctips.xml
Code:
<event type="kill" name="MonsterCounter" script="MonsterCounter.lua"/>

MonsterCounter.lua

Code:
function onKill(cid, target)
if (isCreature(target)) then
setPlayerStorageValue(cid, getCreatureByName(target) + 1)
end
return true
end

talkactions.xml
Code:
<talkaction words="!monsters" script="monsters.lua"/>

and monsters.lua
Code:
function onSay(cid, words, param)
if (param == "") then
return false
end

t = param:split(",")
t[1] = monster


if (isCreature(monster)) then
if getPlayerStorageValue(monster) > 0 then
local amount = getPlayerStorageValue(param)
local text = "You have killed " .. amount .. " " .. param .."!"

doShowTextDialog(cid, 2175, text)
else
doPlayerSendCancel(cid, "You have not killed any of these monsters.")
return false
end

else
doPlayerSendCancel(cid, "You need to type a monster name.")
return false
end
end

When I try to say ---- !monsters "bug ---- it simply says it cant find a monster with that name.
Made a thread about it, cant find it now, looks like someone deleted it.

Kind Regards,
Eldin.
 
add:
Code:
player:registerEvent("BonusExp")
after:
Code:
player:registerEvent("PlayerDeath")

You still have to register them else they wont work at all :p
that's also why the others aren't working aswell.

The monsters talkactions wont work that way, will make you one but it's to late today, will do it tomorrow :)
 
Back
Top