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

Script help.

Ufonica

New Member
Joined
Aug 3, 2018
Messages
55
Reaction score
0
Hello again,

I have been having a small problem with a promotion script i have made, everything works perfectly fine for it however when players log out and log back in they lose the promotion.

Is there anyway for me to be able to fix this in login.lua.

Client version is 8.6 and the tfs is 0.4

Thanks in advance.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local cfg = {
level = 1, --- level to use items
vocs = { 5, 6, 7, 8 }, --- put here vocation must use items 
storage = 452473991 --- set any empty storage
}
if(getPlayerStorageValue(cid, cfg.storage) == -1) then
if(getPlayerLevel(cid) >= cfg.level) then
if(isInArray(cfg.vocs, getPlayerVocation(cid)) == true) then
setPlayerPromotionLevel(cid, getPlayerPromotionLevel(cid) + 1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have been promoted to " .. getVocationInfo(getPlayerVocation(cid)).name .. ".")
doSendMagicEffect(getCreaturePosition(cid), 55)
setPlayerStorageValue(cid, cfg.storage, 1)
doRemoveItem(item.uid, 1)

else
doCreatureSay(cid, "Only players with first promotion may get their Second promotion.", TALKTYPE_ORANGE_1)
end
else
doCreatureSay(cid, "Sorry, only characters of level " .. cfg.level .. " or above can buy Second Promotion.", TALKTYPE_ORANGE_1)
end
else
doCreatureSay(cid, "You have already purchased the Second Promotion.", TALKTYPE_ORANGE_1)
end
return
end
 
Last edited by a moderator:
You’re welcome. :) Let’s see if this works instead:

Lua:
local t = {
    levelReq = 20,
    vocations = {5, 6, 7, 8},
    storage = 45247
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerStorageValue(cid, t.storage) >= 1 then
        doCreatureSay(cid, "Sorry, you have already used this item.", TALKTYPE_ORANGE_1)
        return false
    end
    if getPlayerLevel(cid) < t.levelReq then
        doCreatureSay(cid, "Sorry, your level is not high enough.", TALKTYPE_ORANGE_1)
        return false
    end
    if not isInArray(t.vocations, getPlayerVocation(cid)) then
        doCreatureSay(cid, "Sorry, you must have the first promotion.", TALKTYPE_ORANGE_1)
        return false
    end
   
    doPlayerSetVocation(cid, getPlayerVocation(cid) + 4)
    setPlayerStorageValue(cid, t.storage, 1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations! You have been promoted to " .. getVocationInfo(getPlayerVocation(cid)).name .. ".")
    doSendMagicEffect(getCreaturePosition(cid), 55)
    doRemoveItem(item.uid, 1)
    doPlayerSave(cid)
    return true
end
 
Last edited:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<vocations>
    <vocation id="0" name="None" description="none" needpremium="0" gaincap="5" gainhp="5" gainmana="5" gainhpticks="6" gainhpamount="1" gainmanaticks="6" gainmanaamount="1" manamultiplier="4.0" attackspeed="1" soulmax="100" gainsoulticks="120" fromvoc="0" attackable="no">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.0" magDamage="1.0" magHealingDamage="1.0" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.5" club="2.0" sword="2.0" axe="2.0" distance="2.0" shielding="1.5" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="1" name="Sorcerer" description="a sorcerer" needpremium="0" gaincap="10" gainhp="5" gainmana="30" gainhpticks="6" gainhpamount="5" gainmanaticks="3" gainmanaamount="5" manamultiplier="1.1" attackspeed="1" soulmax="100" gainsoulticks="120" fromvoc="1">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.0" magDamage="1.0" magHealingDamage="1.0" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.5" club="2.0" sword="2.0" axe="2.0" distance="2.0" shielding="1.5" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="2" name="Druid" description="a druid" needpremium="0" gaincap="10" gainhp="5" gainmana="30" gainhpticks="6" gainhpamount="5" gainmanaticks="3" gainmanaamount="5" manamultiplier="1.1" attackspeed="1" soulmax="100" gainsoulticks="120" fromvoc="2">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.0" magDamage="1.0" magHealingDamage="1.0" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.5" club="1.8" sword="1.8" axe="1.8" distance="1.8" shielding="1.5" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="3" name="Paladin" description="a paladin" needpremium="0" gaincap="20" gainhp="10" gainmana="15" gainhpticks="4" gainhpamount="5" gainmanaticks="4" gainmanaamount="5" manamultiplier="1.4" attackspeed="1" soulmax="100" gainsoulticks="120" fromvoc="3">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.0" magDamage="1.0" magHealingDamage="1.0" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.2" club="1.2" sword="1.2" axe="1.2" distance="1.1" shielding="1.1" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="4" name="Knight" description="a knight" needpremium="0" gaincap="25" gainhp="15" gainmana="5" gainhpticks="3" gainhpamount="5" gainmanaticks="6" gainmanaamount="5" manamultiplier="3.0" attackspeed="1" soulmax="100" gainsoulticks="120" fromvoc="4">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.0" magDamage="1.0" magHealingDamage="1.0" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.1" club="1.1" sword="1.1" axe="1.1" distance="1.4" shielding="1.1" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="5" name="Master Sorcerer" description="a master sorcerer" needpremium="1" gaincap="10" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="10" gainmanaticks="2" gainmanaamount="10" manamultiplier="1.1" attackspeed="1" soulmax="200" gainsoulticks="15" fromvoc="1" lessloss="30">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.2" magDamage="1.2" magHealingDamage="1.1" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.5" club="2.0" sword="2.0" axe="2.0" distance="2.0" shielding="1.5" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="6" name="Elder Druid" description="an elder druid" needpremium="1" gaincap="10" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="10" gainmanaticks="2" gainmanaamount="10" manamultiplier="1.1" attackspeed="1" soulmax="200" gainsoulticks="15" fromvoc="2" lessloss="30">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.2" magDamage="1.2" magHealingDamage="1.1" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.5" club="1.8" sword="1.8" axe="1.8" distance="1.8" shielding="1.5" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="7" name="Royal Paladin" description="a royal paladin" needpremium="1" gaincap="20" gainhp="10" gainmana="15" gainhpticks="3" gainhpamount="10" gainmanaticks="3" gainmanaamount="10" manamultiplier="1.4" attackspeed="1" soulmax="200" gainsoulticks="15" fromvoc="3" lessloss="30">
        <formula meleeDamage="1.0" distDamage="1.3" wandDamage="1.0" magDamage="1.1" magHealingDamage="1.0" defense="1.1" magDefense="1.2" armor="1.2"/>
        <skill fist="1.2" club="1.2" sword="1.2" axe="1.2" distance="1.1" shielding="1.1" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="8" name="Elite Knight" description="an elite knight" needpremium="1" gaincap="25" gainhp="15" gainmana="5" gainhpticks="2" gainhpamount="10" gainmanaticks="4" gainmanaamount="10" manamultiplier="3.0" attackspeed="1" soulmax="200" gainsoulticks="15" fromvoc="4" lessloss="30">
        <formula meleeDamage="1.2" distDamage="1.0" wandDamage="1.0" magDamage="1.0" magHealingDamage="1.0" defense="1.0" magDefense="1.1" armor="1.3"/>
        <skill fist="1.1" club="1.1" sword="1.1" axe="1.1" distance="1.4" shielding="1.1" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="9" name="Wizard" description="an wizard" needpremium="1" gaincap="10" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="10" gainmanaticks="2" gainmanaamount="10" manamultiplier="1.1" attackspeed="1" soulmax="200" gainsoulticks="15" fromvoc="5" lessloss="30">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.3" magDamage="1.3" magHealingDamage="1.1" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.5" club="2.0" sword="2.0" axe="2.0" distance="2.0" shielding="1.5" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="10" name="Priest" description="an priest" needpremium="1" gaincap="10" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="10" gainmanaticks="2" gainmanaamount="10" manamultiplier="1.1" attackspeed="1" soulmax="200" gainsoulticks="15" fromvoc="6" lessloss="30">
        <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.3" magDamage="1.3" magHealingDamage="1.1" defense="1.0" magDefense="1.0" armor="1.0"/>
        <skill fist="1.5" club="1.8" sword="1.8" axe="1.8" distance="1.8" shielding="1.5" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="11" name="Archer" description="an archer" needpremium="1" gaincap="20" gainhp="10" gainmana="15" gainhpticks="3" gainhpamount="10" gainmanaticks="3" gainmanaamount="10" manamultiplier="1.4" attackspeed="1" soulmax="200" gainsoulticks="15" fromvoc="7" lessloss="30">
        <formula meleeDamage="1.0" distDamage="1.4" wandDamage="1.0" magDamage="1.2" magHealingDamage="1.2" defense="1.2" magDefense="1.3" armor="1.3"/>
        <skill fist="1.2" club="1.2" sword="1.2" axe="1.2" distance="1.1" shielding="1.1" fishing="1.1" experience="1.0"/>
    </vocation>
    <vocation id="12" name="Warrior" description="an warrior" needpremium="1" gaincap="25" gainhp="15" gainmana="5" gainhpticks="2" gainhpamount="10" gainmanaticks="4" gainmanaamount="10" manamultiplier="3.0" attackspeed="1" soulmax="200" gainsoulticks="15" fromvoc="8" lessloss="30">
        <formula meleeDamage="1.3" distDamage="1.0" wandDamage="1.0" magDamage="1.1" magHealingDamage="1.0" defense="1.5" magDefense="1.5" armor="1.5"/>
        <skill fist="1.1" club="1.1" sword="1.1" axe="1.1" distance="1.4" shielding="1.1" fishing="1.1" experience="1.0"/>
    </vocation>
</vocations>
 
It won't work like that. You either change a vocation and it has fromvoc with the same id, meaning it's a completely new vocation or you just set a promotion level.

The way it works in 0.4 is:
- During save, you save a promotion level and a base vocation
- During load, you assign a base vocation and then add a promotion which automatically changes the vocation. It chooses the first vocation that has the fromVoc matching to what you already have.
 
This is what I would do:
* First check if promotion level is really not saving. Use the first script that changes promotion to "2" and then check the database, table 'players' and look for a field 'promotion' for your character.
* Logout, check the database, login check the database.
* If it's "2" in all cases then it's saving properly and the issue might be with your vocations.xml file - probably fromVoc not configured properly.
* If it's not 2, I would check the source code - do you have those?
 
Hmm, must be a bug with the source. I’m not sure.

There’s one more trick you can do to make this work. Within the script, where the doPlayerSetVocation line is, you can replace that line with an instruction that updates the database directly where the vocation is set.

Lua:
db.executeQuery
 

Similar threads

Back
Top