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

Lua Double exp when you have a summon

Misterion

New Member
Joined
Jan 24, 2014
Messages
52
Reaction score
4
TFS 0.3.7 Tibia 8.6

I'm trying to get the summons do not steal half the exp in my server. I did some research, and found out that this can be resolved at source. The problem is I'm having a lot of difficulties to compile it, so I'm seeking an alternative method to solve this.
My idea is a script that checks if the player have a summon if it had double the experience.
(I'm not good with scripts, but I have a basic idea and try to learn more and more from my mistakes). But I think it would look like this:

Code:
if getCreatureSummons (cid) then
    setPlayerExtraExpRate (cid, 2)

But woe will my doubts:

-Where this script will work, GlobalEvents, creaturescripts or other?

-This my reasoning is right? What is missing in the script?


Thank you for reading
 
Last edited:
No idea, mby use onKill?

Go to data/creaturescripts/creaturescripts.xml and paste this line:
Code:
<event type="kill" name="SummonBonusExp" event="script" value="summonBonusExp.lua"/>

Now go into data/creaturescript/scripts and create new lua and name it: "summonBonusExp" and paste code below:
Code:
function onKill(cid, target)
    if not isMonster(target) or #getCreatureSummons(cid) <= 0 then
        setPlayerExtraExpRate(cid, 1)
        return true
    end
 
    setPlayerExtraExpRate(cid, 2)
    return true
end

Now inside data/creaturescripts/scripts and open login.lua and add this line:
Code:
registerCreatureEvent(cid, "SummonBonusExp")
 
No idea, mby use onKill?

Go to data/creaturescripts/creaturescripts.xml and paste this line:
Code:
<event type="kill" name="SummonBonusExp" event="script" value="summonBonusExp.lua"/>

Now go into data/creaturescript/scripts and create new lua and name it: "summonBonusExp" and paste code below:
Code:
function onKill(cid, target)
    if not isMonster(target) or #getCreatureSummons(cid) <= 0 then
        setPlayerExtraExpRate(cid, 1)
        return true
    end

    setPlayerExtraExpRate(cid, 2)
    return true
end

Now inside data/creaturescripts/scripts and open login.lua and add this line:
Code:
registerCreatureEvent(cid, "SummonBonusExp")

Thanks, my precious!
Well, a error ocurred. The problem is, when I kill a creature, she stays stading, stopped, but dead. The life bar disappears, and nothing more happens. What the heck is that?
Edit: I've noticed that a creature died, after waiting some time, and, we I've logged in with the god, the other ones DISAPPEARED.
 
What error appears in the console?

Code:
[Error - CreatureScript Interface]
data/creaturescripts/scripts/summonBonusExp.lua:onKill
Description:
data/creaturescripts/scripts/summonBonusExp.lua(cat): attempt to call global 'setPl
ayerExtraExpRate' (a nil value)
stack traceback:
        data/creaturescripts/scripts/summonBonusExp.lua(cat): in function <data/cre
aturescripts/scripts/summonBonusExp.lua:1>
 
Well, seems the function to give extra exp rate does not exsist. So no idea then :p
 
Well, seems the function to give extra exp rate does not exsist. So no idea then :p

I found a double exp potion script and got these functions

Code:
configs = {
time = 0.01, ---- TIME IN MINUTES
addrate = 200, -- Exp in %
}

doPlayerSetExperienceRate(cid, (1+(configs.addrate/100))+(getPlayerExtraExpRate(cid)/100))
creatureEvent(doPlayerSetExperienceRate, configs.time *60*1000, cid, 1+(getPlayerExtraExpRate(cid)/100-(configs.addrate/100)))

The fully Script

Code:
<?xml version="1.0" encoding="UTF-8"?><modname="AdvancedExpPotionSystem"enabled="yes"author="MatheusMkalo"forum="XTibia.com"><!-- Configs and Functions --><configname="PotionExpConfigs"><![CDATA[
------ CONFIGURE SEU SCRIPT ------ TRUE ou FALSE
configs = {
time = 1, ---- TIME IN MINUTES
needpa = TRUE,
needlvl = {TRUE, level = 50},
costmana = {TRUE, mana = 300},
addrate = 20, -- Exp in %
removeonuse = TRUE
}
function getTime(s)
local n = math.floor(s / 60)
s = s - (60 * n)
return n, s
end
CreatureEventChecker = function(event, ...) -- Colex
if isCreature(arg[1]) then
event(unpack(arg))
end
end
creatureEvent = function(event, delay, ...) -- Colex
addEvent(CreatureEventChecker, delay, event, unpack(arg))
end
function getPlayerExtraExpRate(cid) -- By MatheusMkalo
return (getPlayerRates(cid)[8]-1)*100
end
]]></config><!-- exppotion.lua --><actionitemid="7440"event="script"><![CDATA[
domodlib('PotionExpConfigs')
if getPlayerStorageValue(cid, 62164) >= 1 then
return doPlayerSendCancel(cid, "You are already taking effect from this item.")
end
if configs.needpa and not isPremium(cid) then
return doPlayerSendCancel(cid, "You need to be a premmium account to use this item.")
end
if configs.needlvl[1] and getPlayerLevel(cid) < configs.needlvl.level then
return doPlayerSendCancel(cid, "You need to be level " .. configs.needlvl.level .. " to use this item.")
end
if configs.costmana[1] then
if getCreatureMana(cid) < configs.costmana.mana then
return doPlayerSendCancel(cid, "You need " .. configs.costmana.mana .. " mana to use this item.")
else
doCreatureAddMana(cid, -configs.costmana.mana)
end
end
if configs.removeonuse then
doRemoveItem(item.uid, 1)
end

for i = configs.time*60, 1, -1 do
local a = math.floor(i/60) .. ":" .. i - (60 * math.floor(i/60))
if #a < 4 then
a = string.sub(a,1,2) .. "0" .. string.sub(a, 3)
end
if i == configs.time*60 then
creatureEvent(doPlayerSendCancel, configs.time*60*1000, cid, "The effect of the exp potion end.")
end
creatureEvent(doPlayerSendCancel, (configs.time*60-i)*1000, cid, "The effect of the exp potion will end in "..a..".")
end
doPlayerSetExperienceRate(cid, (1+(configs.addrate/100))+(getPlayerExtraExpRate(cid)/100))
creatureEvent(doPlayerSetExperienceRate, configs.time *60*1000, cid, 1+(getPlayerExtraExpRate(cid)/100-(configs.addrate/100)))
doPlayerSendTextMessage(cid, 22, "Agora voce ira receber mais exp por matar os mosntros.")
setPlayerStorageValue(cid, 62164, os.time())
creatureEvent(setPlayerStorageValue, configs.time *60*1000, cid, 62164, 0)
return TRUE
]]></action><creaturescripttype="login"name="ExpPotion"event="script"><![CDATA[
domodlib('PotionExpConfigs')
local time = configs.time
if os.time()-getPlayerStorageValue(cid, 62164) < time *60 then
doPlayerSetExperienceRate(cid, (1+(configs.addrate/100))+(getPlayerExtraExpRate(cid)/100))
creatureEvent(doPlayerSetExperienceRate, (time*60-(os.time()-getPlayerStorageValue(cid, 62164))) * 1000, cid, 1+(getPlayerExtraExpRate(cid)/100-(configs.addrate/100)))
creatureEvent(setPlayerStorageValue, (time*60-(os.time()-getPlayerStorageValue(cid, 62164))) * 1000 , cid, 62164, 0)
for i = (time*60-(os.time()-getPlayerStorageValue(cid, 62164))), 1, -1 do
local a = math.floor(i/60) .. ":" .. i - (60 * math.floor(i/60))
if #a < 4 then
a = string.sub(a,1,2) .. "0" .. string.sub(a, 3)
end
if i == (time*60-(os.time()-getPlayerStorageValue(cid, 62164))) then
creatureEvent(doPlayerSendCancel, (time*60-(os.time()-getPlayerStorageValue(cid, 62164)))*1000, cid, "The effect of the exp potion end.")
end
creatureEvent(doPlayerSendCancel, ((time*60-(os.time()-getPlayerStorageValue(cid, 62164)))-i)*1000, cid, "The effect of the exp potion will end in "..a..".")
end
end
return TRUE
]]></creaturescript></mod>

Ideas?
 
Back
Top