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

Lua Help NPC promote bugged

luccagomes

New Member
Joined
Jul 30, 2015
Messages
153
Reaction score
1
I can buy, he give me, all is ok in game, but if i relog, i lose my promtion
Any know fix?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="The King" script="data/npc/scripts/promote.lua" walkinterval="2000" floorchange="0">
   <mana now="800" max="800"/>
   <health now="200" max="200"/>
   <look type="332" head="21" body="87" legs="107" feet="95"/>
</npc>

Code:
local config = {
   promote1 = 20000, -- preço da primeira promotion
   promote2 = 10000000, -- preço da segunda promotion
   rookPromote1 = {13, 10000}, -- {id da vocação, preço}
   rookPromote2 = {14, 5000000} -- {id da vocação, preço}
}

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid)   end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end

function creatureSayCallback(cid, type, msg)
   msg = string.lower(msg)
   local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   
   if not npcHandler:isFocused(cid) then
     return false
   end

   local price
   if (getPlayerVocation(cid) >= 1 and getPlayerVocation(cid) <= 4) then
     price = 20000
   elseif (getPlayerVocation(cid) >= 5 and getPlayerVocation(cid) <= 8) then
     price = 10000000
   elseif (getPlayerVocation(cid) == 0) then
     price = 10000
   elseif (getPlayerVocation(cid) == 13) then
     price = 5000000
   end
   
   if msgcontains(msg, 'hi') then
     selfSay('Hello ' .. getPlayerName(cid) .. '! I sell promotions.')

     elseif msgcontains(msg, 'promotion') or msgcontains(msg, 'promote') then
     if (getPlayerLevel(cid) < 20 ) then
       npcHandler:say("You need level 20 to be promoted!", cid)
       return true
     end
     if getPlayerVocation(cid) == 0 or getPlayerVocation(cid) == config.rookPromote1[1] then
       npcHandler:say('Do you want to buy promotion for ' .. price .. ' gold coins?', cid)
       talkState[talkUser] = 2
     elseif getPlayerVocation(cid) > 8  and getPlayerVocation(cid) < config.rookPromote1[1] then
       selfSay('Sorry, you are already promoted.')
       talkState[talkUser] = 0
     elseif not isPremium(cid) and ((getPlayerVocation(cid) > 4 and getPlayerVocation(cid) < config.rookPromote1[1]) or getPlayerVocation(cid) == config.rookPromote1[1]) then
       selfSay('Sorry, you must be premium to buy promotion.')
       talkState[talkUser] = 0
     else
       selfSay('Do you want to buy promotion for ' .. price .. ' gold coins?')
       talkState[talkUser] = 1
     end

   elseif talkState[talkUser] == 1 then
     if msgcontains(msg, 'yes') then
       if doPlayerRemoveMoney(cid, price) then
         doPlayerSetVocation(cid, getPlayerVocation(cid) + 4)
         selfSay('You are now promoted!')
       else
         selfSay('Sorry, you do not have enough money.')
       end
     end
     talkState[talkUser] = 0

   elseif talkState[talkUser] == 2 then
     if getPlayerVocation(cid) == 0 then
       if doPlayerRemoveMoney(cid, config.rookPromote1[2]) then
         doPlayerSetVocation(cid, config.rookPromote1[1])
         selfSay('You are now promoted!')
       else
         selfSay('Sorry, you do not have enough money.')
       end
     elseif getPlayerVocation(cid) == config.rookPromote1[1] then
       if doPlayerRemoveMoney(cid, config.rookPromote2[2]) then
         doPlayerSetVocation(cid, config.rookPromote2[1])
         selfSay('You are now promoted!')
       else
         selfSay('Sorry, you do not have enough money.')
       end
     end
     talkState[talkUser] = 0

   elseif msgcontains(msg, 'bye') then
     selfSay('Good bye, ' .. getPlayerName(cid) .. '!')
     talkState[talkUser] = 0
   end   
   return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Assuming your script works..
check vocations. xml and ensure the previous vocation is correct for the promotions.
 
Assuming your script works..
check vocations. xml and ensure the previous vocation is correct for the promotions.

vocations.xml is ok too :eek:
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="2" gainhpamount="2" gainmanaticks="1" gainmanaamount="4" manamultiplier="4.0" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="0" attackable="yes">
     <formula meleeDamage="1.5" distDamage="1.5" 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="4.0" fishing="2.2" experience="1.0"/>
   </vocation>
   <vocation id="1" name="Sorcerer" description="a sorcerer" needpremium="0" gaincap="10" gainhp="5" gainmana="30" gainhpticks="3" gainhpamount="2" gainmanaticks="2" gainmanaamount="4" manamultiplier="1.1" attackspeed="2000" 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="5.0" sword="5.0" axe="5.0" distance="5.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="3" gainhpamount="2" gainmanaticks="2" gainmanaamount="4" manamultiplier="1.1" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="2">
     <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.0" magDamage="0.8" magHealingDamage="1.2" defense="1.0" magDefense="1.0" armor="1.0"/>
     <skill fist="1.5" club="5.0" sword="5.0" axe="5.0" distance="5.0" 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="3" gainhpamount="3" gainmanaticks="2" gainmanaamount="3" manamultiplier="1.4" attackspeed="2000" 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.5" club="5.0" sword="5.0" axe="5.0" distance="1.1" shielding="1.4" 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="4" gainmanaticks="2" gainmanaamount="2" manamultiplier="3.0" attackspeed="2000" 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.5" club="1.1" sword="1.1" axe="1.1" distance="5.0" shielding="1.1" fishing="1.1" experience="1.0"/>
   </vocation>
   <!-- promote FREE -->
   <vocation id="5" name="Master Sorcerer" description="a master sorcerer" needpremium="0" gaincap="10" gainhp="5" gainmana="30" gainhpticks="3" gainhpamount="3" gainmanaticks="2" gainmanaamount="5" manamultiplier="1.1" attackspeed="2000" 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="5.0" sword="5.0" axe="5.0" distance="5.0" shielding="1.5" fishing="1.1" experience="1.0"/>
   </vocation>
   <vocation id="6" name="Elder Druid" description="a elder druid" needpremium="0" gaincap="10" gainhp="5" gainmana="30" gainhpticks="3" gainhpamount="3" gainmanaticks="2" gainmanaamount="5" manamultiplier="1.1" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="2">
     <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.0" magDamage="0.8" magHealingDamage="1.2" defense="1.0" magDefense="1.0" armor="1.0"/>
     <skill fist="1.5" club="5.0" sword="5.0" axe="5.0" distance="5.0" shielding="1.5" fishing="1.1" experience="1.0"/>
   </vocation>
   <vocation id="7" name="Royal Paladin" description="a royal paladin" needpremium="0" gaincap="20" gainhp="10" gainmana="15" gainhpticks="3" gainhpamount="4" gainmanaticks="2" gainmanaamount="4" manamultiplier="1.4" attackspeed="2000" 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.5" club="5.0" sword="5.0" axe="5.0" distance="1.1" shielding="1.4" fishing="1.1" experience="1.0"/>
   </vocation>
   <vocation id="8" name="Elite Knight" description="a elite knight" needpremium="0" gaincap="25" gainhp="15" gainmana="5" gainhpticks="3" gainhpamount="5" gainmanaticks="2" gainmanaamount="3" manamultiplier="3.0" attackspeed="2000" 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.5" club="1.1" sword="1.1" axe="1.1" distance="5.0" shielding="1.1" fishing="1.1" experience="1.0"/>
   </vocation>
   <!-- promote VIP -->
   <vocation id="9" name="Epic Sorcerer" description="a epic sorcerer" needpremium="1" gaincap="10" gainhp="5" gainmana="30" gainhpticks="3" gainhpamount="4" gainmanaticks="2" gainmanaamount="8" manamultiplier="1.1" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="5">
     <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="5.0" sword="5.0" axe="5.0" distance="5.0" shielding="1.5" fishing="1.1" experience="1.0"/>
   </vocation>
   <vocation id="10" name="Epic Druid" description="a epic druid" needpremium="1" gaincap="10" gainhp="5" gainmana="30" gainhpticks="3" gainhpamount="4" gainmanaticks="2" gainmanaamount="8" manamultiplier="1.1" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="6">
     <formula meleeDamage="1.0" distDamage="1.0" wandDamage="1.0" magDamage="0.8" magHealingDamage="1.2" defense="1.0" magDefense="1.0" armor="1.0"/>
     <skill fist="1.5" club="5.0" sword="5.0" axe="5.0" distance="5.0" shielding="1.5" fishing="1.1" experience="1.0"/>
   </vocation>
   <vocation id="11" name="Epic Paladin" description="a epic paladin" needpremium="1" gaincap="20" gainhp="10" gainmana="15" gainhpticks="3" gainhpamount="6" gainmanaticks="2" gainmanaamount="6" manamultiplier="1.4" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="7">
     <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="5.0" sword="5.0" axe="5.0" distance="1.1" shielding="1.4" fishing="1.1" experience="1.0"/>
   </vocation>
   <vocation id="12" name="Epic Knight" description="a epic knight" needpremium="1" gaincap="25" gainhp="15" gainmana="5" gainhpticks="3" gainhpamount="8" gainmanaticks="2" gainmanaamount="4" manamultiplier="3.0" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="8">
     <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.1" sword="1.1" axe="1.1" distance="5.0" shielding="1.1" fishing="1.1" experience="1.0"/>
   </vocation>
   <!-- ROOK promotes -->
   <!-- free -->
   <vocation id="13" name="Rooker" description="rooker" needpremium="0" gaincap="5" gainhp="5" gainmana="5" gainhpticks="2" gainhpamount="3" gainmanaticks="1" gainmanaamount="5" manamultiplier="4.0" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="0" attackable="yes">
     <formula meleeDamage="1.5" distDamage="1.5" 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="4.0" fishing="2.2" experience="1.0"/>
   </vocation>
   <!-- VIP -->
   <vocation id="14" name="Rookgaardian" description="rookgaardian" needpremium="1" gaincap="5" gainhp="5" gainmana="5" gainhpticks="2" gainhpamount="4" gainmanaticks="1" gainmanaamount="8" manamultiplier="4.0" attackspeed="2000" soulmax="100" gainsoulticks="120" fromvoc="13" attackable="yes">
     <formula meleeDamage="1.5" distDamage="1.5" 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="4.0" fishing="2.2" experience="1.0"/>
   </vocation>
</vocations>
 
the last 4 'vip' promotions are incorrect.
If you test i bet you'll find the first promotion works fine, but the second promotion goes back to the previous promotion.
Change the last four vocs, fromvoc to 1,2,3,4 as well.
Edit--
On my phone didnt see the rookgaardian as well. You'll need to change that one to 0.
 
Last edited:
the last 4 'vip' promotions are incorrect.
If you test i bet you'll find the first promotion works fine, but the second promotion goes back to the previous promotion.
Change the last four vocs, fromvoc to 1,2,3,4 as well.
Edit--
On my phone didnt see the rookgaardian as well. You'll need to change that one to 0.

how?
 
Code:
fromvoc="5"> -- epic S
fromvoc="6"> -- epic D
fromvoc="7"> -- epic P
fromvoc="8"> -- epic K
fromvoc="13"> -- rookG
Change to...
Code:
fromvoc="1"> -- epic S
fromvoc="2"> -- epic D
fromvoc="3"> -- epic P
fromvoc="4"> -- epic K
fromvoc="0"> -- rookG
 
Code:
fromvoc="5"> -- epic S
fromvoc="6"> -- epic D
fromvoc="7"> -- epic P
fromvoc="8"> -- epic K
fromvoc="13"> -- rookG
Change to...
Code:
fromvoc="1"> -- epic S
fromvoc="2"> -- epic D
fromvoc="3"> -- epic P
fromvoc="4"> -- epic K
fromvoc="0"> -- rookG

I have changed, but when i relog i lost my promotions!!! WHY? ;(
 
Assuming your script works..
check vocations. xml and ensure the previous vocation is correct for the promotions.
Why when i relog i lost my promotion?
I've looked through your script, and your not actually promoting the characters, your instead changing their vocation.
Since your doing it that way, simply set the 'fromvoc' = to the vocationID

Code:
vocation id="0" . . .  fromvoc="0">
vocation id="1" . . .  fromvoc="1">
vocation id="2" . . .  fromvoc="2">
.
.
.
vocation id="14" . . .  fromvoc="14">
 
I've looked through your script, and your not actually promoting the characters, your instead changing their vocation.
Since your doing it that way, simply set the 'fromvoc' = to the vocationID

Code:
vocation id="0" . . .  fromvoc="0">
vocation id="1" . . .  fromvoc="1">
vocation id="2" . . .  fromvoc="2">
.
.
.
vocation id="14" . . .  fromvoc="14">

I think it's fuck my vocations
ZnHOzym.png
 
elseif talkState[talkUser] == 1 then if msgcontains(msg, 'yes') then if doPlayerRemoveMoney(cid, price) then doPlayerSetVocation(cid, getPlayerVocation(cid) + 4) selfSay('You are now promoted!') else selfSay('Sorry, you do not have enough money.') end end talkState[talkUser] = 0

One problem dealing with it not saving the promotion when relogging is that it doesn't seem like you'r using a storage value so your database doesn't permanently change their vocation. Using a storage value after buying a promotion to store the player as being promoted permanently in the database would make it so when you relog after buying the promotion, the database sees the storage value that the player has been promoted, and will keep him promoted after relogging. Without anything storing the promotion in the database would lead to the promotion disappearing after relogging.

If you'r just using the 4 standard vocations that lead to the 4 standard promotions and no other further promotions (like "epic master sorcerer" as a second promotion), the "Vocation 4294967295 not found." error could be fixed by checking vocations.xml for the ID of each vocation and any other files that deal with vocations that could cause a conflict of the same two vocations having different ID's, causing the server to not know what the vocation is.
 
Back
Top