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

Help with a script

Marko999x

999x era
Premium User
Joined
Dec 14, 2017
Messages
2,825
Solutions
82
Reaction score
1,947
Location
Germany
Hello Otland. I need quick help..
I have found that script for learning spell but it seems like it does not work as it should...

even if I write vocation 4 ( KNIGHT ) paladins or mages can still learn the spell for some reasons.. is it possible to fix ? Im using tfs 0.4 + would be nice if it could be edited like so knight and ELITE knight can use that spell :D

Lua:
local spell = "death target"
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not getPlayerLearnedInstantSpell(cid, spell) then
        doPlayerLearnInstantSpell(cid, spell)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    elseif getPlayerVocation(cid) ~= 4 then
        doCreatureSay(cid, "Only the x vocation can learn this spell.", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
    else
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
    end
    return true
end
 
Solution
If statements follow an order. You need to change the order to do checks that will prevent the fixed conditions, like being vocation id 4, so you have to check that first.

What you are doing right now is basically checking if the player knows the spell and teaching him the spell, before checking his vocation.


This should work:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerVocation(cid) ~= 4 then
        doCreatureSay(cid, "Only the x vocation can learn this spell.", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        return true
    end
 
    if not getPlayerLearnedInstantSpell(cid, spell) then
        doPlayerLearnInstantSpell(cid, spell)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR...
If statements follow an order. You need to change the order to do checks that will prevent the fixed conditions, like being vocation id 4, so you have to check that first.

What you are doing right now is basically checking if the player knows the spell and teaching him the spell, before checking his vocation.


This should work:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerVocation(cid) ~= 4 then
        doCreatureSay(cid, "Only the x vocation can learn this spell.", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        return true
    end
 
    if not getPlayerLearnedInstantSpell(cid, spell) then
        doPlayerLearnInstantSpell(cid, spell)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    else
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
    end
    return true
end
 
Solution
If statements follow an order. You need to change the order to do checks that will prevent the fixed conditions, like being vocation id 4, so you have to check that first.

What you are doing right now is basically checking if the player knows the spell and teaching him the spell, before checking his vocation.


This should work:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerVocation(cid) ~= 4 then
        doCreatureSay(cid, "Only the x vocation can learn this spell.", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        return true
    end
 
    if not getPlayerLearnedInstantSpell(cid, spell) then
        doPlayerLearnInstantSpell(cid, spell)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    else
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
    end
    return true
end

Thanks you really much and nice to know thanks
 
Back
Top