function Player:onGainExperience(source, exp, rawExp)
if not source or source:isPlayer() then
return exp
end
-- Soul regeneration
local vocation = self:getVocation()
if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
self:addCondition(soulCondition)
end
-- Experience Stage Multiplier
local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
exp = exp * expStage
baseExp = rawExp * expStage
if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
displayRate = expStage...
data/scripts/necklaceExp.lua
local ev = EventCallback
function ev.onGainExperience(player, source, exp, rawExp)
local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)
if necklace and necklace:getId() == 2661 then
exp = exp * 1.25
end
return exp
end
Thaks for the script, but i have this error. could you help me plzyou can use something like this if you want:
data/scripts/necklaceExp.lua
Lua:local ev = EventCallback function ev.onGainExperience(player, source, exp, rawExp) local necklace = player:getSlotItem(CONST_SLOT_NECKLACE) if necklace and necklace:getId() == 2661 then exp = exp * 1.25 end return exp end
this way, when you have the necklace equipped, than you receive 25% more experience
You should have mentioned that you are using the OTServ Br engine, that engine does not have the EventCallback systemThaks for the script, but i have this error. could you help me plz
oh srry im a noobie about creating an otserver, could you help me a script with Otserv Br engine?You should have mentioned that you are using the OTServ Br engine, that engine does not have the event call system
the code is only compatible with official TFS 1.3
function PlayernGainExperience(source, exp, rawExp)Share yourPlayer:onGainExperience
code from:
/data/events/scripts/player.lua
And perhaps I can help you convert Sarah's suggestion to your code base
function Player:onGainExperience(source, exp, rawExp)
if not source or source:isPlayer() then
return exp
end
-- identify the necklace slot.
local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)
-- if the necklace is our "extra XP item"
if necklace and necklace:getId() == 2661 then
-- Then give the player extra exp.
exp = exp * 1.25
end
return exp
end
onGainExperience
has no functionality for adding extra exp for stages or stamina. Are you sure that you copied the whole function?function Player:onGainExperience(source, exp, rawExp)
if not source or source:isPlayer() then
return exp
end
-- Soul regeneration
local vocation = self:getVocation()
if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
self:addCondition(soulCondition)
end
-- Experience Stage Multiplier
local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
exp = exp * expStage
baseExp = rawExp * expStage
if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
displayRate = expStage
else
displayRate = 1
end
-- Prey Bonus
for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
if (self:getPreyCurrentMonster(slot) == source:getName()
and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100))
break
end
if (self:getPreyTimeLeft(slot) / 60) > 0 then
preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check
end
end
-- Store Bonus
useStaminaXp(self) -- Use store boost stamina
local Boost = self:getExpBoostStamina()
local stillHasBoost = Boost > 0
local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0
self:setStoreXpBoost(storeXpBoostAmount)
if (storeXpBoostAmount > 0) then
exp = exp + (baseExp * (storeXpBoostAmount/100)) -- Exp Boost
end
-- Stamina Bonus
if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
useStamina(self)
local staminaMinutes = self:getStamina()
if staminaMinutes > 2400 and self:isPremium() then
exp = exp * 1.5
self:setStaminaXpBoost(150)
elseif staminaMinutes <= 840 then
exp = exp * 0.5 --TODO destroy loot of people with 840- stamina
self:setStaminaXpBoost(50)
else
self:setStaminaXpBoost(100)
end
end
-- Boosted creature
if source:getName():lower() == (Game.getBoostedCreature()):lower() then
exp = exp * 2
end
-- Necklace Extra EXP boost
local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)
-- if the necklace is our "extra XP item"
if necklace and necklace:getId() == 2661 then
-- Then give the player extra EXP.
exp = exp * 1.25 -- 25% extra EXP.
end
-- Event scheduler
if SCHEDULE_EXP_RATE ~= 100 then
exp = (exp * SCHEDULE_EXP_RATE)/100
end
self:setBaseXpGain(displayRate * 100)
return exp
end
data/events/events.xml
and change<event class="Player" method="onGainExperience" enabled="0" />
<event class="Player" method="onGainExperience" enabled="1" />
I put the first script in \data\scripts\amulet.luaOkay, let's try this:
Lua:function Player:onGainExperience(source, exp, rawExp) if not source or source:isPlayer() then return exp end -- identify the necklace slot. local necklace = player:getSlotItem(CONST_SLOT_NECKLACE) -- if the necklace is our "extra XP item" if necklace and necklace:getId() == 2661 then -- Then give the player extra exp. exp = exp * 1.25 end return exp end
However, youronGainExperience
has no functionality for adding extra exp for stages or stamina. Are you sure that you copied the whole function?
This is how the function looks in OTServBR latest version:
otservbr-global/data/events/scripts/player.lua at main · opentibiabr/otservbr-global
OTServBR-Global datapack was migrated to Canary repository: https://github.com/opentibiabr/canary - opentibiabr/otservbr-globalgithub.com
In case you missed the remaining functionality, i'll add this code-snippet for you to try as well:
Lua:function Player:onGainExperience(source, exp, rawExp) if not source or source:isPlayer() then return exp end -- Soul regeneration local vocation = self:getVocation() if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000) self:addCondition(soulCondition) end -- Experience Stage Multiplier local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP)) exp = exp * expStage baseExp = rawExp * expStage if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then displayRate = expStage else displayRate = 1 end -- Prey Bonus for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do if (self:getPreyCurrentMonster(slot) == source:getName() and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100)) break end if (self:getPreyTimeLeft(slot) / 60) > 0 then preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check end end -- Store Bonus useStaminaXp(self) -- Use store boost stamina local Boost = self:getExpBoostStamina() local stillHasBoost = Boost > 0 local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0 self:setStoreXpBoost(storeXpBoostAmount) if (storeXpBoostAmount > 0) then exp = exp + (baseExp * (storeXpBoostAmount/100)) -- Exp Boost end -- Stamina Bonus if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then useStamina(self) local staminaMinutes = self:getStamina() if staminaMinutes > 2400 and self:isPremium() then exp = exp * 1.5 self:setStaminaXpBoost(150) elseif staminaMinutes <= 840 then exp = exp * 0.5 --TODO destroy loot of people with 840- stamina self:setStaminaXpBoost(50) else self:setStaminaXpBoost(100) end end -- Boosted creature if source:getName():lower() == (Game.getBoostedCreature()):lower() then exp = exp * 2 end -- Necklace Extra EXP boost local necklace = player:getSlotItem(CONST_SLOT_NECKLACE) -- if the necklace is our "extra XP item" if necklace and necklace:getId() == 2661 then -- Then give the player extra EXP. exp = exp * 1.25 -- 25% extra EXP. end -- Event scheduler if SCHEDULE_EXP_RATE ~= 100 then exp = (exp * SCHEDULE_EXP_RATE)/100 end self:setBaseXpGain(displayRate * 100) return exp end
Don't forget to go intodata/events/events.xml
and change
<event class="Player" method="onGainExperience" enabled="0" />
to:
<event class="Player" method="onGainExperience" enabled="1" />
Which enables the LUA function for your server
edit:
Credits for the extra experience functionality goes to
Sarah Wesker
function Player:onGainExperience(source, exp, rawExp)
if not source or source:isPlayer() then
return exp
end
-- Soul regeneration
local vocation = self:getVocation()
if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
self:addCondition(soulCondition)
end
-- Experience Stage Multiplier
local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP))
exp = exp * expStage
baseExp = rawExp * expStage
if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then
displayRate = expStage
else
displayRate = 1
end
-- Prey Bonus
for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do
if (self:getPreyCurrentMonster(slot) == source:getName()
and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then
exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100))
break
end
if (self:getPreyTimeLeft(slot) / 60) > 0 then
preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check
end
end
-- Store Bonus
useStaminaXp(self) -- Use store boost stamina
local Boost = self:getExpBoostStamina()
local stillHasBoost = Boost > 0
local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0
self:setStoreXpBoost(storeXpBoostAmount)
if (storeXpBoostAmount > 0) then
exp = exp + (baseExp * (storeXpBoostAmount/100)) -- Exp Boost
end
-- Stamina Bonus
if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
useStamina(self)
local staminaMinutes = self:getStamina()
if staminaMinutes > 2400 and self:isPremium() then
exp = exp * 1.5
self:setStaminaXpBoost(150)
elseif staminaMinutes <= 840 then
exp = exp * 0.5 --TODO destroy loot of people with 840- stamina
self:setStaminaXpBoost(50)
else
self:setStaminaXpBoost(100)
end
end
-- Boosted creature
if source:getName():lower() == (Game.getBoostedCreature()):lower() then
exp = exp * 2
end
-- Necklace Extra EXP boost
local necklace = self:getSlotItem(CONST_SLOT_NECKLACE)
-- if the necklace is our "extra XP item"
if necklace and necklace:getId() == 2661 then
-- Then give the player extra EXP.
exp = exp * 1.25 -- 25% extra EXP.
end
-- Event scheduler
if SCHEDULE_EXP_RATE ~= 100 then
exp = (exp * SCHEDULE_EXP_RATE)/100
end
self:setBaseXpGain(displayRate * 100)
return exp
end
Thanks it works!!!Try this
Lua:function Player:onGainExperience(source, exp, rawExp) if not source or source:isPlayer() then return exp end -- Soul regeneration local vocation = self:getVocation() if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000) self:addCondition(soulCondition) end -- Experience Stage Multiplier local expStage = getRateFromTable(experienceStages, self:getLevel(), configManager.getNumber(configKeys.RATE_EXP)) exp = exp * expStage baseExp = rawExp * expStage if Game.getStorageValue(GlobalStorage.XpDisplayMode) > 0 then displayRate = expStage else displayRate = 1 end -- Prey Bonus for slot = CONST_PREY_SLOT_FIRST, CONST_PREY_SLOT_THIRD do if (self:getPreyCurrentMonster(slot) == source:getName() and self:getPreyBonusType(slot) == CONST_BONUS_XP_BONUS) then exp = exp + math.floor(exp * (self:getPreyBonusValue(slot) / 100)) break end if (self:getPreyTimeLeft(slot) / 60) > 0 then preyTimeLeft(self, slot) -- slot consumption, outside of the mosnter check end end -- Store Bonus useStaminaXp(self) -- Use store boost stamina local Boost = self:getExpBoostStamina() local stillHasBoost = Boost > 0 local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0 self:setStoreXpBoost(storeXpBoostAmount) if (storeXpBoostAmount > 0) then exp = exp + (baseExp * (storeXpBoostAmount/100)) -- Exp Boost end -- Stamina Bonus if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then useStamina(self) local staminaMinutes = self:getStamina() if staminaMinutes > 2400 and self:isPremium() then exp = exp * 1.5 self:setStaminaXpBoost(150) elseif staminaMinutes <= 840 then exp = exp * 0.5 --TODO destroy loot of people with 840- stamina self:setStaminaXpBoost(50) else self:setStaminaXpBoost(100) end end -- Boosted creature if source:getName():lower() == (Game.getBoostedCreature()):lower() then exp = exp * 2 end -- Necklace Extra EXP boost local necklace = self:getSlotItem(CONST_SLOT_NECKLACE) -- if the necklace is our "extra XP item" if necklace and necklace:getId() == 2661 then -- Then give the player extra EXP. exp = exp * 1.25 -- 25% extra EXP. end -- Event scheduler if SCHEDULE_EXP_RATE ~= 100 then exp = (exp * SCHEDULE_EXP_RATE)/100 end self:setBaseXpGain(displayRate * 100) return exp end
Trying to use that but don't really works and i have no error :/ tfs 1.5 8.0 by nekiroyou can use something like this if you want:
data/scripts/necklaceExp.lua
Lua:local ev = EventCallback function ev.onGainExperience(player, source, exp, rawExp) local necklace = player:getSlotItem(CONST_SLOT_NECKLACE) if necklace and necklace:getId() == 2661 then exp = exp * 1.25 end return exp end
this way, when you have the necklace equipped, than you receive 25% more experience