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

Vocation specific healing spell

tozikrulz

New Member
Joined
Jun 10, 2009
Messages
46
Reaction score
1
I'm trying to make a spell that heals knights health more than the other vocations but i can't seem to get it working (this worked before i added the knights variation)
Please tell me where i've gone wrong and how to fix it please, thank you in advance.

Code:
function onCastSpell(cid, var)

local minhealth = (getPlayerLevel(cid) * 11.0) + (getPlayerMagLevel(cid) * 4)
local maxhealth = (getPlayerLevel(cid) * 13.0) + (getPlayerMagLevel(cid) * 4)
local minmana = (getPlayerLevel(cid) * 6.5) + (getPlayerMagLevel(cid) * 4)
local maxmana = (getPlayerLevel(cid) * 7.5) + (getPlayerMagLevel(cid) * 4)
local randommana = math.ceil(math.random(minmana,maxmana))
local randomhealth = math.ceil(math.random(minhealth,maxhealth))
local playerVoc = getPlayerVocation(cid)

if playerVoc == 4 or playerVoc == 8 or playerVoc == 12 then
doCreatureAddMana(cid, randommana)
doCreatureAddHealth(cid, randomhealth)
doSendMagicEffect(getCreaturePosition(cid), 49)
doSendAnimatedText(getCreaturePosition(cid), randommana, COLOR_YELLOW)

elseif playerVoc == 1 or playerVoc == 5 or playerVoc == 9 or playerVoc == 2 or playerVoc == 6 or playerVoc == 10  or playerVoc == 3 or playerVoc == 7 or playerVoc == 11 then
doCreatureAddMana(cid, randommana)
doCreatureAddHealth(cid, randommana)
doSendMagicEffect(getCreaturePosition(cid), 49)
doSendAnimatedText(getCreaturePosition(cid), randommana, COLOR_YELLOW)
return true
end
end
 
If you are going to be comparing multiple numbers against 1 value always use isInArray.
Example:
Code:
if isInArray({4, 8, 12}, playerVoc) then
    -- do something
end
Also don't call the same function over and over, call it once and store it.
Code:
local level = getPlayerLevel(cid)
local magicLevel = getPlayerMagLevel(cid)
local position = getCreaturePosition(cid)

Use indentation in your code.. its makes it easier to read, find errors if any like the one you are having it also allows you to see the level of execution.
 
Last edited:
Code:
function onCastSpell(cid, var)
    local level = getPlayerLevel(cid)
    local magicLevel = getPlayerMagLevel(cid)
    local position = getCreaturePosition(cid)
    local playerVocation = getPlayerVocation(cid)
    local mp, hp = 0, 0

    local minHealth = (level * 11.0) + (magicLevel * 4)
    local maxHealth = (level * 13.0) + (magicLevel * 4)
    local minMana = (level * 6.5) + (magicLevel * 4)
    local maxMana = (level * 7.5) + (magicLevel * 4)
    local randomMana = math.ceil(math.random(minMana, maxMana))
    local randomHealth = math.ceil(math.random(minHealth, maxHealth))


    if isInArray({4, 8, 12}, playerVocation) then
        mp = randomMana
        hp = randomHealth
    elseif isInArray({1,5,9,2,6,10,3,7,11}, playerVocation) then
        mp = randomMana
        hp = randomMana
    end

    doCreatureAddMana(cid, mp)
    doCreatureAddHealth(cid, hp)
    doSendMagicEffect(position, 49)
    doSendAnimatedText(position, randomMana, COLOR_YELLOW)
    return true
end
See how much easier that is to read?
 
Back
Top