TFS 0.X Quest gives skills not working

Discussion in 'Support' started by juansanchez, Dec 6, 2018.

  1. juansanchez

    juansanchez Member

    Joined:
    Apr 2, 2015
    Messages:
    173
    Likes Received:
    14
    Best Answers:
    0
    Hey guys, i have this quest on my server that is supossed to give skills to players.
    Mages get Magic Level, Knights and Paladins Skills.
    I have a working script but it is way too glitchy.. Whenever a player does the quest, it does not give the right amount of skills, if someone is using some kind of equipment that gives skills, the quest will add skill on top of that, and if for example, a knight uses "utito tempo" right before using the chest, they'll get the skill set to whatever skill they go to when they use utito tempo + the amount of skill that the quest should give. (Skill 100, utito tempo goes to 130, quest gives 12, they go to 142 [Example]).
    Also, whenever a player clicks on the chest, the server lags.
    Code (Lua):
    1.  
    2. function onUse(cid, item, frompos, item2, topos)
    3.     local pS = getPlayerStorageValue(cid, 2357)
    4.     local pV = getPlayerVocation(cid)
    5.     if pS > 0 then
    6.         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce ja fez a quest.")
    7.         doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    8.     else
    9.         if pV == 5 or pV == 6 or pV == 12 then
    10.             setPlayerStorageValue(cid, 2357, 1)
    11.             doPlayerAddMagLevel(cid, 6)
    12.             doSendMagicEffect(getPlayerPosition(cid), 28)
    13.             doSendAnimatedText(getPlayerPosition(cid), "Magic Up", TEXTCOLOR_BLUE)
    14.         elseif pV == 7 then
    15.             setPlayerStorageValue(cid, 2357, 1)
    16.             doPlayerAddSkill(cid, SKILL_DISTANCE, doPlayerAddSkill(cid, SKILL_DISTANCE, 12))
    17.             doSendMagicEffect(getPlayerPosition(cid), 28)
    18.             doSendAnimatedText(getPlayerPosition(cid), "Distance Up", TEXTCOLOR_BLUE)
    19.         elseif pV == 10 then
    20.             setPlayerStorageValue(cid, 2357, 1)
    21.             doPlayerAddSkill(cid, SKILL_CLUB, doPlayerAddSkill(cid, SKILL_CLUB, 12))
    22.             doSendMagicEffect(getPlayerPosition(cid), 28)
    23.             doSendAnimatedText(getPlayerPosition(cid), "Club Up", TEXTCOLOR_BLUE)
    24.         elseif pV == 14 then
    25.             setPlayerStorageValue(cid, 2357, 1)
    26.             doPlayerAddSkill(cid, SKILL_FIST, doPlayerAddSkill(cid, SKILL_FIST, 12))
    27.             doSendMagicEffect(getPlayerPosition(cid), 28)
    28.             doSendAnimatedText(getPlayerPosition(cid), "Fist Up", TEXTCOLOR_BLUE)
    29.         elseif pV == 8 then
    30.             setPlayerStorageValue(cid, 2357, 1)
    31.      
    32.             local highest = "SKILL_CLUB"
    33.             if getPlayerSkillLevel(cid, SKILL_SWORD) > getPlayerSkillLevel(cid, highest) then
    34.                 highest = "SKILL_SWORD"
    35.             end
    36.             if getPlayerSkillLevel(cid, SKILL_AXE) > getPlayerSkillLevel(cid, highest) then
    37.                 highest = "SKILL_AXE"
    38.             end
    39.             if highest == "SKILL_CLUB" then
    40.                 doPlayerAddSkill(cid, SKILL_CLUB, doPlayerAddSkill(cid, SKILL_CLUB, 12))
    41.                 doSendMagicEffect(getPlayerPosition(cid), 28)
    42.                 doSendAnimatedText(getPlayerPosition(cid), "Club Up", TEXTCOLOR_BLUE)
    43.             elseif highest == "SKILL_SWORD" then
    44.                 doPlayerAddSkill(cid, SKILL_SWORD, doPlayerAddSkill(cid, SKILL_SWORD, 12))
    45.                 doSendMagicEffect(getPlayerPosition(cid), 28)
    46.                 doSendAnimatedText(getPlayerPosition(cid), "Sword Up", TEXTCOLOR_BLUE)
    47.             else
    48.                 doPlayerAddSkill(cid, SKILL_AXE, doPlayerAddSkill(cid, SKILL_AXE, 12))
    49.                 doSendMagicEffect(getPlayerPosition(cid), 28)
    50.                 doSendAnimatedText(getPlayerPosition(cid), "Axe Up", TEXTCOLOR_BLUE)
    51.             end
    52.         else
    53.             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce nao tem a vocacao necessaria.")
    54.             doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    55.         end
    56.     end
    57.     return true
    58. end
    59.  
    That's the script. I did find another one, that seems to use database to add the skills, which i believe is better. However when i try to use it, it gives me this error:

    [20:58:56.702] [Error - Test Interface]
    [20:58:56.704] data/actions/scripts/lagartos.lua
    [20:58:56.707] Description:
    [20:58:56.708] (internalGetPlayerInfo) Player not found when requesting player info #18
    [20:58:56.710] [Error - Test Interface]
    [20:58:56.711] data/actions/scripts/lagartos.lua
    [20:58:56.711] Description:
    [20:58:56.715] (internalGetPlayerInfo) Player not found when requesting player info #6
    [20:58:56.718] [Error - Test Interface]
    [20:58:56.720] data/actions/scripts/lagartos.lua
    [20:58:56.721] Description:
    [20:58:56.721] (internalGetPlayerInfo) Player not found when requesting player info #6
    [20:58:56.723] [Error - Test Interface]
    [20:58:56.729] data/actions/scripts/lagartos.lua
    [20:58:56.730] Description:
    [20:58:56.731] (internalGetPlayerInfo) Player not found when requesting player info #6
    [20:58:56.731] [Error - Event::checkScript] Event onUse not found (data/actions/scripts/lagartos.lua)

    Here's the script:

    Code (Text):
    1.  
    2. local playerid = getPlayerGUID(cid)
    3. local ml = 6
    4. local skillnew = 12
    5. if isInArray({5,6}, getPlayerVocation(cid)) then
    6. db.executeQuery("UPDATE `players` SET `maglevel` = `maglevel` + ".. newml .." WHERE `players`.`id`= ".. playerid .."")
    7. elseif isInArray({8}, getPlayerVocation(cid)) then
    8. local club = getPlayerSkillLevel(cid, SKILL_CLUB)
    9. local sword = getPlayerSkillLevel(cid, SKILL_SWORD)
    10. local axe = getPlayerSkillLevel(cid, SKILL_AXE)
    11. db.executeQuery("UPDATE `player_skills` SET `value` = " .. (axe + skillnew) .. ", `count` = 0 WHERE `skillid` = 3 and `player_id` = " .. playerid .. ";")
    12. db.executeQuery("UPDATE `player_skills` SET `value` = " .. (sword + skillnew) .. ", `count` = 0 WHERE `skillid` = 2 and `player_id` = " .. playerid .. ";")
    13. db.executeQuery("UPDATE `player_skills` SET `value` = " .. (club + skillnew) .. ", `count` = 0 WHERE `skillid` = 1 and `player_id` = " .. playerid .. ";")
    14. elseif isInArray({7}, getPlayerVocation(cid)) then
    15. local distance = getPlayerSkillLevel(cid, SKILL_DISTANCE)
    16. db.executeQuery("UPDATE `player_skills` SET `value` = " .. (distance + skillnew) .. ", `count` = 0 WHERE `skillid` = 4 and `player_id` = " .. playerid .. ";")
    17. end
    18.  
    Bottomline is, can anyone help me either fix the first one, or make the second one work?
    Longstory short: Gives skill, can't use spells to boost skill nor itens. If the player could logout when the skill is added (i believe it's via the db this happens).

    Tfs 0.3.6 10.10

    Sorry for the long post.​
     
    Last edited: Dec 6, 2018
  2. Loney

    Loney Premium User Premium User

    Joined:
    Jul 23, 2012
    Messages:
    1,785
    Likes Received:
    105
    Best Answers:
    0
  3. juansanchez

    juansanchez Member

    Joined:
    Apr 2, 2015
    Messages:
    173
    Likes Received:
    14
    Best Answers:
    0
    I remember that thread. That guy helped me with the first script i have. But at the time i didn't know about the glitches.
     
  4. Ascuas Funkeln

    Ascuas Funkeln Rakkedo Game

    Joined:
    Apr 14, 2013
    Messages:
    93
    Likes Received:
    44
    Best Answers:
    4
    Code (Lua):
    1. function onUse(cid, item, frompos, item2, topos)
    2.     local pS = getPlayerStorageValue(cid, 2357)
    3.     local pV = getPlayerVocation(cid)
    4.     if pS > 0 then
    5.         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce ja fez a quest.")
    6.         doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    7.     else
    8.         if pV == 5 or 6 or 12 then
    9.             setPlayerStorageValue(cid, 2357, 1)
    10.             doPlayerAddMagLevel(cid, 6)
    11.             doSendMagicEffect(getPlayerPosition(cid), 28)
    12.             doSendAnimatedText(getPlayerPosition(cid), "Magic Up", TEXTCOLOR_BLUE)
    13.         elseif pV == 7 then
    14.             setPlayerStorageValue(cid, 2357, 1)
    15.             doPlayerAddSkill(cid, SKILL_DISTANCE, 12)
    16.             doSendMagicEffect(getPlayerPosition(cid), 28)
    17.             doSendAnimatedText(getPlayerPosition(cid), "Distance Up", TEXTCOLOR_BLUE)
    18.         elseif pV == 10 then
    19.             setPlayerStorageValue(cid, 2357, 1)
    20.             doPlayerAddSkill(cid, SKILL_CLUB, 12)
    21.             doSendMagicEffect(getPlayerPosition(cid), 28)
    22.             doSendAnimatedText(getPlayerPosition(cid), "Club Up", TEXTCOLOR_BLUE)
    23.         elseif pV == 14 then
    24.             setPlayerStorageValue(cid, 2357, 1)
    25.             doPlayerAddSkill(cid, SKILL_FIST, 12)
    26.             doSendMagicEffect(getPlayerPosition(cid), 28)
    27.             doSendAnimatedText(getPlayerPosition(cid), "Fist Up", TEXTCOLOR_BLUE)
    28.         elseif pV == 8 then
    29.             setPlayerStorageValue(cid, 2357, 1)
    30.        
    31.             local highest = "SKILL_CLUB"
    32.             if getPlayerSkillLevel(cid, SKILL_SWORD) > getPlayerSkillLevel(cid, highest) then
    33.                 highest = "SKILL_SWORD"
    34.             end
    35.             if getPlayerSkillLevel(cid, SKILL_AXE) > getPlayerSkillLevel(cid, highest) then
    36.                 highest = "SKILL_AXE"
    37.             end
    38.             if highest == "SKILL_CLUB" then
    39.                 doPlayerAddSkill(cid, SKILL_CLUB, 12)
    40.                 doSendMagicEffect(getPlayerPosition(cid), 28)
    41.                 doSendAnimatedText(getPlayerPosition(cid), "Club Up", TEXTCOLOR_BLUE)
    42.             elseif highest == "SKILL_SWORD" then
    43.                 doPlayerAddSkill(cid, SKILL_SWORD, 12)
    44.                 doSendMagicEffect(getPlayerPosition(cid), 28)
    45.                 doSendAnimatedText(getPlayerPosition(cid), "Sword Up", TEXTCOLOR_BLUE)
    46.             else
    47.                 doPlayerAddSkill(cid, SKILL_AXE, 12)
    48.                 doSendMagicEffect(getPlayerPosition(cid), 28)
    49.                 doSendAnimatedText(getPlayerPosition(cid), "Axe Up", TEXTCOLOR_BLUE)
    50.             end
    51.         else
    52.             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce nao tem a vocacao necessaria.")
    53.             doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    54.         end
    55.     end
    56.     return true
    57. end
     
  5. juansanchez

    juansanchez Member

    Joined:
    Apr 2, 2015
    Messages:
    173
    Likes Received:
    14
    Best Answers:
    0
    It gives Magic Level to all vocations.

    I did manage to force the logout and addskill using:
    Code (Text):
    1.  
    2. doRemoveCreature(cid)
    3. db.executeQuery("UPDATE `player_skills` SET `value` = " .. (sword + 12) .. ", `count` = 0 WHERE `skillid` = 2 and `player_id` = " .. pid .. ";")
    4.  
    However, if i use utito tempo, even though sword is the highest skill, it gives me axe skill and i get this error:

    Code (Text):
    1.  
    2. [18:25:54.993] [Error - Action Interface]
    3. [18:25:54.995] data/actions/scripts/lagartos.lua:onUse
    4. [18:25:54.998] Description:
    5. [18:25:54.999] data/lib/050-function.lua:396: 'for' limit must be a number
    6. [18:25:55.002] stack traceback:
    7. [18:25:55.005]  data/lib/050-function.lua:396: in function 'doPlayerAddSkill'
    8. [18:25:55.006]  data/actions/scripts/lagartos.lua:53: in function <data/actions/scripts/lagartos.lua:1>
    9.  
     
  6. Stigma

    Stigma Support Team Support Team

    Joined:
    Feb 14, 2015
    Messages:
    4,323
    Likes Received:
    2,027
    Best Answers:
    351
    How to display CODE properly in your post
    please don't format your code with centered text, it's impossible to read
     
  7. juansanchez

    juansanchez Member

    Joined:
    Apr 2, 2015
    Messages:
    173
    Likes Received:
    14
    Best Answers:
    0
    Sorry, i didn't think of that. I fixed it now.

    @Update

    I fixed parts of it. Now the player logs out and gets the right amount of skills.
    However, it still glitches when they use any spells that buffs skills or itens.

    And now knights don't recieve any skills.

    Code (Lua):
    1.  
    2. function onUse(cid, item, frompos, item2, topos)
    3.     local pS = getPlayerStorageValue(cid, 2400)
    4.     local pV = getPlayerVocation(cid)
    5.     if pS > 0 then
    6.         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce ja fez a quest.")
    7.         doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    8.     else
    9.         if pV == 5 or pV == 6 or pV == 12 then
    10.             setPlayerStorageValue(cid, 2400, 1)
    11.             local pid = getPlayerGUID(cid)
    12.             doRemoveCreature(cid)
    13.             db.executeQuery("UPDATE `players` SET `maglevel` = `maglevel` + 6 WHERE `id` = "..pid..";")
    14.         elseif pV == 7 then
    15.             setPlayerStorageValue(cid, 2400, 1)
    16.             local pid = getPlayerGUID(cid)
    17.             local distance = getPlayerSkillLevel(cid, SKILL_DISTANCE)
    18.             doRemoveCreature(cid)
    19.             db.executeQuery("UPDATE `player_skills` SET `value` = " .. (distance + 12) .. ", `count` = 0 WHERE `skillid` = 4 and `player_id` = " .. pid .. ";")
    20.         elseif pV == 10 then
    21.             setPlayerStorageValue(cid, 2400, 1)
    22.             local pid = getPlayerGUID(cid)
    23.             local club = getPlayerSkillLevel(cid, SKILL_CLUB)
    24.             doRemoveCreature(cid)
    25.             db.executeQuery("UPDATE `player_skills` SET `value` = " .. (club + 12) .. ", `count` = 0 WHERE `skillid` = 1 and `player_id` = " .. pid .. ";")
    26.         elseif pV == 14 then
    27.             setPlayerStorageValue(cid, 2400, 1)
    28.             local pid = getPlayerGUID(cid)
    29.             local fist = getPlayerSkillLevel(cid, SKILL_FIST)
    30.             doRemoveCreature(cid)
    31.             db.executeQuery("UPDATE `player_skills` SET `value` = " .. (fist + 12) .. ", `count` = 0 WHERE `skillid` = 0 and `player_id` = " .. pid .. ";")
    32.         elseif pV == 8 or pV == 18 then
    33.             setPlayerStorageValue(cid, 2400, 1)
    34.        
    35.             local highest = "SKILL_CLUB"
    36.             if getPlayerSkillLevel(cid, SKILL_SWORD) > getPlayerSkillLevel(cid, highest) then
    37.                 highest = "SKILL_SWORD"
    38.             end
    39.             if getPlayerSkillLevel(cid, SKILL_AXE) > getPlayerSkillLevel(cid, highest) then
    40.                 highest = "SKILL_AXE"
    41.             end
    42.             if highest == "SKILL_CLUB" then
    43.                 local pid = getPlayerGUID(cid)
    44.                 local club = getPlayerSkillLevel(cid, SKILL_CLUB)
    45.                 doRemoveCreature(cid)
    46.                 db.executeQuery("UPDATE `player_skills` SET `value` = " .. (club + 12) .. ", `count` = 0 WHERE `skillid` = 1 and `player_id` = " .. pid .. ";")
    47.             elseif highest == "SKILL_SWORD" then
    48.                 if getCreatureCondition (cid, CONDITION_ATTRIBUTES) == FALSE then
    49.                 local pid = getPlayerGUID(cid)
    50.                 local sword = getPlayerSkillLevel(cid, SKILL_SWORD)
    51.                 doRemoveCreature(cid)
    52.                 db.executeQuery("UPDATE `player_skills` SET `value` = " .. (sword + 12) .. ", `count` = 0 WHERE `skillid` = 2 and `player_id` = " .. pid .. ";")
    53.             else
    54.                 local pid = getPlayerGUID(cid)
    55.                 local xe = getPlayerSkillLevel(cid, SKILL_CLUB)
    56.                 doRemoveCreature(cid)
    57.                 db.executeQuery("UPDATE `player_skills` SET `value` = " .. (axe + 12) .. ", `count` = 0 WHERE `skillid` = 3 and `player_id` = " .. pid .. ";")
    58.             end
    59.         else
    60.             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Voce nao tem a vocacao necessaria.")
    61.             doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    62.         end
    63.     end
    64.     return true
    65. end
    66. end
    67.  
     
  8. Ramirow

    Ramirow Active Member

    Joined:
    Aug 22, 2009
    Messages:
    394
    Likes Received:
    128
    Best Answers:
    5
    The only way to do it is by using querys? I don't have such an old server to try, but I think this function existed on it:
    Code (Text):
    1.  
    2. getPlayerRequiredSkillTries(cid, skillId, skillLevel)
    3.  
    I suppose that would give you the required tries for X level, so you could try something like this for example:
    Code (Text):
    1. if highest == "SKILL_CLUB" then
    2.     local pid = getPlayerGUID(cid)
    3.     local club = getPlayerSkillLevel(cid, SKILL_CLUB)
    4.     local clubTries = getPlayerRequiredSkillTries(cid, SKILL_CLUB, club + 12)
    5.    
    6.     doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    7.  
     
  9. juansanchez

    juansanchez Member

    Joined:
    Apr 2, 2015
    Messages:
    173
    Likes Received:
    14
    Best Answers:
    0
    Query is better, because if i add that many skills to a player, the server freezes while adding the skills. Tried your way, knights still don't recieve any skill.
     
  10. Tadelho

    Tadelho Member

    Joined:
    Aug 12, 2007
    Messages:
    38
    Likes Received:
    2
    Best Answers:
    1
    @juansanchez In TFS 0.4~ there is a function called 'getPlayerSkillLevel' wich should receives 3 parameters: cid (the creatureid that should be checked), skill (the skill to be checked), and a parameter to ignore or consider modifiers (from itens/spells) in this skills. You can ignore modifiers setting this last parameter as "true" or consider it setting as "false". In case of magic level, it's 'getPlayerMagLevel' with only 2 parameters: cid, true/false.

    So, you can make a simple script to check the skill of the player and then add more skills upon it.
    For example:

    Code (Lua):
    1. getPlayerSkillLevel(cid, SKILL_SWORD, true)
    Here you're checking the "natural" sword skill of a player, you can start from here. But, of course, in your case the code must be a lot bigger with a lot of other verifications...

    But, hey, another possible temporary solution is simply checking if the player has any buff/debuff in his skills and disable the quest to buffed players. Something like:

    Code (Lua):
    1. if getPlayerSkillLevel(cid, Skill, true) == getPlayerSkillLevel(cid, Skill, false) and getPlayerMagLevel(cid, true) == getPlayerMagLevel(cid, false) then
    2. (insert the bonus code here)
    3. else
    4. doSendPlayerCancel(cid,'You can not receive a bonus awhile your skills or magic level are modified.')
    5. end
     
    Last edited: Dec 9, 2018 at 9:37 PM
  11. mdwilliams

    mdwilliams Premium User Premium User

    Joined:
    Nov 15, 2007
    Messages:
    591
    Likes Received:
    110
    Best Answers:
    0
    I used these functions for my simple war ot release back in the day, but it did cause lag and I do recall the results not being as expected - it wasn't because of equipment or spells (I was applying these on first login only). I can't remember what the problem ended up being, but it was in the coding of these functions.

    Code (Lua):
    1. doPlayerAddSpentMana(cid, (getPlayerRequiredMana(cid,x))) // doPlayerAddMagLevel(cid, x)
    2. doPlayerAddSkillTry(cid, SKILL_DISTANCE, getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, x))
    3. doPlayerAddSkillTry(cid, SKILL_SHIELD, getPlayerRequiredSkillTries(cid, SKILL_SHIELD, x))
    4. doPlayerAddSkillTry(cid, SKILL_AXE, getPlayerRequiredSkillTries(cid, SKILL_AXE, x))
    5. doPlayerAddSkillTry(cid, SKILL_SWORD, getPlayerRequiredSkillTries(cid, SKILL_SWORD, x))
    6. doPlayerAddSkillTry(cid, SKILL_CLUB, getPlayerRequiredSkillTries(cid, SKILL_CLUB, x))
    Oh I forgot about this, I helped some guy fix it back in 2012 - maybe this will help you:
    Solved - doPlayerAddMagLevel(cid, getPlayerMagLevel(cid) * (-1) + 70) is not working...
     
    Last edited: Dec 9, 2018 at 8:25 AM
  12. juansanchez

    juansanchez Member

    Joined:
    Apr 2, 2015
    Messages:
    173
    Likes Received:
    14
    Best Answers:
    0
    This function doesn't exist: "attempt to call global 'getPlayerSkillValue' (a nil value)" At least not on my 0.3.6.
     
  13. Tadelho

    Tadelho Member

    Joined:
    Aug 12, 2007
    Messages:
    38
    Likes Received:
    2
    Best Answers:
    1
    Ops, actually it's "getPlayerSkillLevel()". Try it now.
     

Share This Page

Loading...