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

Reply to thread

Small fix:


In file data\lib\miscellaneous\050-functions.lua at line 21 function doAddExp(cid, amount) throws an error upon use:

[CODE]Lua Script Error: [Action Interface]

data/actions/scripts/quests/test.lua:onUse

attempt to index a number value

stack traceback:

[C]: at 0x557361c10372

[C]: in function 'doSendAnimatedText'

data/lib/miscellaneous/050-functions.lua:23: in function 'doAddExp'[/CODE]


Body of this function looks like so:

[CODE=lua]--Functions by Oskar--

function doAddExp(cid, amount)

    doSendAnimatedText(getCreaturePosition(cid), amount, COLOR_WHITE)

    return doPlayerAddExperience(cid, amount) or false

end[/CODE]


This function is not that critical and it can be deleted because all its references are simply replaceable  with single line:

[CODE=lua]player:addExperience(amount, true)[/CODE]

However this method has a flaw, because it always omit experience stages.


So I made a replacement of that function. It fixes mentioned error and adds additional functionality. It is also compatible with previous one, because it accepts two or more parameters, so no references have to be changed.

[CODE=lua]function doAddExp(cid, amount, useExpStages, customColor, ...)

    local player = cid:getPlayer()

    if not player then

        return false

    else

        if useExpStages then amount = amount * Game.getExperienceStage(player:getLevel()) end

        if not customColor then customColor = TEXTCOLOR_WHITE_EXP end

        Game.sendAnimatedText(amount, getCreaturePosition(cid), customColor)

        return doPlayerAddExp(cid, amount)

    end

end[/CODE]


Function parameters:

cid - hookup to a certain creature. Function will check if it's a player to avoid error at getting its level later on.

amount - base amount of exp given to a certain player. It may be multiplied by current player's experience stage.

useExpStages - do you want to use experience stages with this function. Must be true or false.

customColor - if you want to use other color than white then you can set it here.


Valid colors are:

TEXTCOLOR_BLUE, TEXTCOLOR_GREEN, TEXTCOLOR_LIGHTGREEN, TEXTCOLOR_LIGHTBLUE, TEXTCOLOR_TEAL, TEXTCOLOR_MAYABLUE, TEXTCOLOR_DARKRED, TEXTCOLOR_LIGHTGREY, TEXTCOLOR_SKYBLUE, TEXTCOLOR_PURPLE, TEXTCOLOR_ELECTRICPURPLE, TEXTCOLOR_RED, TEXTCOLOR_PASTELRED, TEXTCOLOR_ORANGE, TEXTCOLOR_YELLOW, TEXTCOLOR_WHITE_EXP, TEXTCOLOR_NONE


Usage Examples:

[CODE=lua]doAddExp(cid, 10)[/CODE]

Most basic usecase. It will give player ten experience points and display white text animation. Works the same as player:addExperience(10, true)


[CODE=lua]doAddExp(cid, 10, true)[/CODE]

It will give player ten experience points multiplied by current player's experience stage.

It will also work with static exp multiplier without stages. White text animation will be displayed as well.


[CODE=lua]doAddExp(cid, 100, false, TEXTCOLOR_ELECTRICPURPLE)[/CODE]

It will give player one hundred experience points and display electric purple text animation.


[CODE=lua]doAddExp(cid, 50, true, TEXTCOLOR_GREEN)[/CODE]

It will add fifty experience points multiplied by current player's experience stage and display dark green text animation.


Hope you'll find it useful.


Back
Top