TFS 0.X Would be possible to add a storage and a addon to players offline?

Discussion in 'Support' started by sucibob, May 27, 2018.

  1. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Would be possible to add a storage and a addon to players offline?

    That is my DB.sql
    hastebin

    I think storages are saved on: SELECT * FROM `player_storage`
    So i did this, i think it gonna work:
    db.executeQuery("INSERT INTO `player_storage` SET (`player_id`, `key`, `value`) VALUES ('" .. result.getDataInt(resultId2, "belongs_to") .. "', '" .. r.storage .. "', '" .. 1 .. "')")
    It's right btw?

    How the fuck it's save the players addon, i couldnt find it in no where
    in players there is lookType, but i think that is the outfit player is using, not addon save stuff

    How to add a addon for a player offline and a storage?

    Full code:
    Code (Text):
    1.  
    2. function onAdvance(cid, skill, oldLevel, newLevel)
    3.  
    4.  
    5.   local r = {
    6.     [50] = {premmydays = 1, storage = 50010},
    7.     [100] = {premmydays = 3, outfitid = 22, addon = 1},
    8.     [150] = {premmydays = 5, outfitid = 22, addon = 2},
    9.   }
    10.  
    11.   local requiredLevel = 15
    12.  
    13.    if skill == SKILL_LEVEL and newLevel >= requiredLevel then
    14.      local accountId = getAccountId(cid)
    15.      -- Fetch the ref_key where account_id = accountId and blocked = 0
    16.      local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    17.      -- If result is found
    18.      if resultId ~= false then
    19.  
    20.        -- Fetch the referrer's account_id based on ref_key from previous query result
    21.        local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
    22.          -- If result is found
    23.        if resultId2 ~= false then
    24.          -- Update accountId's row blocked value to 1
    25.          db.executeQuery("UPDATE `__cornex_referral_actions` SET `blocked` = 1 WHERE `registered_by` = " .. accountId)
    26.          -- Update points to referrer
    27.          -- ADD REWARD TO REFFERER
    28.  
    29.          -- REWARD 1 storage
    30.          db.executeQuery("INSERT INTO `player_storage` SET (`player_id`, `key`, `value`) VALUES ('" .. result.getDataInt(resultId2, "belongs_to") .. "', '" .. r.storage .. "', '" .. 1 .. "')")
    31.          -- REWARD 2 addon 22,1
    32.          -- REWARD 3 addon 22,2
    33.          result.free(resultId2)
    34.        else
    35.          print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
    36.        end
    37.        result.free(resultId)
    38.  
    39.      end
    40.    end
    41.    return true
    42. end
    43.  
    ---
    btw- 2 things too:
    1) How to change:
    local requiredLevel = 15
    if skill == SKILL_LEVEL and newLevel >= requiredLevel then

    To lvl in r
    I mean [50], [100], [150]

    2) How should i change to have 3 rewards, not only one, because it set the value to 1, no add more one, and after add 1 time, its over to the others
     
    Last edited: May 27, 2018
  2. gudan garam

    gudan garam Active Member

    Joined:
    Feb 13, 2011
    Messages:
    238
    Likes Received:
    60
    Best Answers:
    8
    Ok, so all I did was the first question you asked, how to do check if he is reaching certain levels as you said 50, 100 or 150, but the other question I didn't understand (How should i change to have 3 rewards, not only one, because it set the value to 1, no add more one, and after add 1 time, its over to the others), sorry.

    Also I don't understand why u want to add storage values and addons to an offline player and trying to do it on the onAdvance function (the player must be online, right?)

    Anyways, here is how I did that:

    Code (Text):
    1. function onAdvance(cid, skill, oldLevel, newLevel)
    2.     local r = {
    3.         [50] = {premmydays = 1, storage = 50010},
    4.         [100] = {premmydays = 3, outfitid = 22, addon = 1},
    5.         [150] = {premmydays = 5, outfitid = 22, addon = 2},
    6.     }
    7.     local requiredLevel = 15
    8.     if skill == SKILL_LEVEL and newLevel >= requiredLevel then
    9.         if newLevel - oldLevel== 1 then
    10.             local reward = r[newLevel]
    11.             if reward then
    12.                 -- do something here because he reached 50, 100 or 150.
    13.             end
    14.         else
    15.             for i = oldLevel + 1, newLevel do
    16.                 local reward = r[i]
    17.                 if reward then
    18.                     -- do the same here because he reached 50, 100 or 150. (probably a good idea to create a function? DRY.)
    19.             end
    20.         end
    21.  
    22.         local accountId = getAccountId(cid)
    23.         -- Fetch the ref_key where account_id = accountId and blocked = 0
    24.         local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    25.         -- If result is found
    26.         if resultId ~= false then
    27.  
    28.             -- Fetch the referrer's account_id based on ref_key from previous query result
    29.             local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
    30.             -- If result is found
    31.             if resultId2 ~= false then
    32.                 -- Update accountId's row blocked value to 1
    33.                 db.executeQuery("UPDATE `__cornex_referral_actions` SET `blocked` = 1 WHERE `registered_by` = " .. accountId)
    34.                 -- Update points to referrer
    35.                 -- ADD REWARD TO REFFERER
    36.  
    37.                 -- REWARD 1 storage
    38.                 db.executeQuery("INSERT INTO `player_storage` SET (`player_id`, `key`, `value`) VALUES ('" .. result.getDataInt(resultId2, "belongs_to") .. "', '" .. r.storage .. "', '" .. 1 .. "')")
    39.                 -- REWARD 2 addon 22,1
    40.                 -- REWARD 3 addon 22,2
    41.                 result.free(resultId2)
    42.             else
    43.                 print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
    44.             end
    45.             result.free(resultId)
    46.         end
    47.     end
    48.    return true
    49. end
    EDIT --
    Just want to remember that I didn't implement any code that gives the player the rewards, I only made the logic and commented it where you should do it.
     
    sucibob likes this.
  3. Ascuas Funkeln

    Ascuas Funkeln Rakkedo Game

    Joined:
    Apr 14, 2013
    Messages:
    74
    Likes Received:
    41
    Best Answers:
    3
    Make script onLogin and onThink/onAdvance.
    Setup check storage value in script, and make script thats setup storage for all variable.
    So, if they login or level up they will automaticaly get all rewards depends on level, you dont need storages for rewards and you will dont need interfere in database.
    People complicate the scripts too much, and this is problem :eek:
     
    sucibob likes this.
  4. gudan garam

    gudan garam Active Member

    Joined:
    Feb 13, 2011
    Messages:
    238
    Likes Received:
    60
    Best Answers:
    8
    Ye you are right, no storage needed, if they keep getting the same level over and over again we should give them the reward everytime, no checks needed, right? xD

    Setup check storage value in script, and make script thats setup storage for all variable.
    ?

    So, if they login or level up they will automaticaly get all rewards depends on level, you dont need storages for rewards and you will dont need interfere in database.
    If he wants to add a storage value to an offline player he'll have to do it through database.

    Make script onLogin and onThink/onAdvance.
    Show us what you mean.
     
    sucibob likes this.
  5. Ascuas Funkeln

    Ascuas Funkeln Rakkedo Game

    Joined:
    Apr 14, 2013
    Messages:
    74
    Likes Received:
    41
    Best Answers:
    3
    1. No need storage for reward items.
    2. Need storage for execute function.
    3. Make it for me? xD

    Code (Lua):
    1. function onAdvance(cid, skill, oldLevel, newLevel) -- Make second script to check offline players, "onLogin" and delete "1" level.
    2.         if skill == SKILL__LEVEL and newLevel == 1 then
    3.     doPlayerSetStorageValue(uid, 5555, 1)
    4.     doPlayerSetStorageValue(uid, 5556, 1)
    5.     doPlayerSetStorageValue(uid, 5557, 1)
    6.  
    7.         if skill == SKILL__LEVEL and newLevel == 50 and getPlayerStorageValue(uid, 5555) then -- 50.99 onLogin check.
    8.     doPlayerAddItem(cid, 2121)
    9.     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "50 Level? U are monster!")
    10.     doPlayerSetStorageValue(uid, 5555, -1)
    11.  
    12.         elseif skill == SKILL__LEVEL and newLevel == 100 and getPlayerStorageValue(uid, 5556) then -- 100.149 onLogin check.
    13.     doPlayerAddItem(cid, 2121)
    14.     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "The Beast!")
    15.     doPlayerSetStorageValue(uid, 5556, -1)
    16.  
    17.         elseif skill == SKILL__LEVEL and newLevel == 150 and getPlayerStorageValue(uid, 5557) then -- 150.999 onLogin check.
    18.     doPlayerAddItem(cid, 2121)
    19.     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Meow, meow~!")
    20.     doPlayerSetStorageValue(uid, 5557, -1)
    21.  
    22.         return true
    23.     end
    24. end
     
    Last edited: May 30, 2018
    sucibob likes this.
  6. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    I asked about how to use array to check lvls
    To get information from here:
    Code (Text):
    1.  
    2.     [50] = {premmydays = 1, storage = 50010},
    3.     [100] = {premmydays = 3, outfitid = 22, addon = 1},
    4.     [150] = {premmydays = 5, outfitid = 22, addon = 2},
    5.  
    [50], [100], [150]



    And about 3 rewards instead of 1 reward
    It's not so simple to add storage for a player, because the verification is about the player account
    Code (Text):
    1.  
    2.      local accountId = getAccountId(cid)
    3.      -- Fetch the ref_key where account_id = accountId and blocked = 0
    4.      local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    5.      -- If result is found
    6.      if resultId ~= false then
    7.  

    And the last and more important, the player who recive the rewards is not the player who get the level
    Is the player who invite this player to play in server, so may be he can be offline...

    So i have to add a storage and a addon for a player offline, and i never saw and found nothing like this here on forum

    I need some help :(
     
  7. Ascuas Funkeln

    Ascuas Funkeln Rakkedo Game

    Joined:
    Apr 14, 2013
    Messages:
    74
    Likes Received:
    41
    Best Answers:
    3
    U wanna make something like reward for recommendation?
    Look, you can again make this in easier way.

    Prepare something like recommendation boxes.
    Example for level 50.
    action.xml
    Code (Text):
    1.  
    2. <action itemid="8000" event="script" value="other/recoBox50.lua"/>
    3. <action itemid="8001" event="script" value="other/recoBox100.lua"/>
    4. <action itemid="8002" event="script" value="other/recoBox150.lua"/>
    5.  
    recoBox50.lua
    Code (Lua):
    1. -- RECO BOX 50
    2. function onUse(cid, item, frompos, item2, topos)
    3. doPlayerAddPremiumDays(cid, 3) -- Premmium days value.
    4. doPlayerAddOutfit(cid, 1, 3) -- First number outfit ID, second addons.
    5. doRemoveItem(cid, item.uid, 1) -- This remove RECO BOX after using.
    6. end
    If player use this box then get the rewards, and you can send the Recommendation Boxes as reward to player depot.
    If they recommend player, then script send to his depot a box (You must write this also xD)

    Anyway, thats read array information, (better make more easier for customize withotu this arrays)
    Code (Text):
    1.     local r = {
    2.         [50] = {premmydays = 1, storage = 50010},
    3.         [100] = {premmydays = 3, outfitid = 22, addon = 1},
    4.         [150] = {premmydays = 5, outfitid = 22, addon = 2},
    5.     }
    6. if (r[50]) then
     
    sucibob likes this.
  8. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    The problem is:
    The player who invite the other one may be offline


    doPlayerAddPremiumDays(cid, 3) -- Premmium days value.
    doPlayerAddOutfit(cid, 1, 3) -- First number outfit ID, second addons.
    doPlayerSetStorageValue(uid, 5555, 1)
    Are functions to use on players online

    And on this system the player who get the reward, is the player who invite the other one to play the server:
    -- Fetch the referrer's account_id based on ref_key from previous query result local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")

    So sometimes this rewards have to be to players online/offline
     
  9. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
  10. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
  11. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
  12. Flatlander

    Flatlander Species Developer

    Joined:
    Feb 17, 2009
    Messages:
    2,457
    Likes Received:
    1,294
    Best Answers:
    2
    First, if you update SQL while a player is online, when they log out (or next save) it will over-write it.

    So you need a:
    "If player is online -> Update storage value and addon normally"
    "If player is offline -> Update using SQL"

    But, I also don't suggest updating the SQL this way anyway.


    I would:
    "If player is online -> Update storage and addon normally"
    "If player is offline -> setGlobalStorage(PLAYER_NAME, 1)"


    Then with an onLogin script:
    Code (Text):
    1.  
    2. if getGlobalStorage(getCreatureName(cid)) = 1 then
    3.   -- Do Referral Bonus
    4. end
    5.  
     
    supergt and sucibob like this.
  13. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    @Flatlander could you help me to finish it?
    Because it should add bonus to player who advance level, not player who reffer the player who advance level

    Code (Text):
    1.  
    2. function onAdvance(cid, skill, oldLevel, newLevel)
    3.   local r = {
    4.     [50] = {premmydays = 1, storage = 50010},
    5.     [100] = {premmydays = 3, addon = 1},
    6.     [150] = {premmydays = 5, addon = 2},
    7.   }
    8.   local requiredLevel = 15
    9.   if skill == SKILL_LEVEL and newLevel >= requiredLevel then
    10.     local accountId = getAccountId(cid)
    11.     -- Fetch the ref_key where account_id = accountId and blocked = 0
    12.     local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    13.     if resultId ~= false then -- If result is found
    14.       if getGlobalStorage(getCreatureName(cid)) == 1 then -- PLAYER WHO REFFER ONLINE
    15.         -- lvl == 50
    16.           setPlayerStorageValue(cid,50010,1)
    17.           doPlayerAddPremiumDays(cid, 1)
    18.         -- lvl == 100
    19.           doPlayerAddOutfit(cid, 336, 1)
    20.           doPlayerAddOutfit(cid, 335, 1)
    21.           doPlayerAddPremiumDays(cid, 3)
    22.         -- lvl == 150
    23.           doPlayerAddOutfit(cid, 336, 2)
    24.           doPlayerAddOutfit(cid, 335, 2)
    25.           doPlayerAddPremiumDays(cid, 5)
    26.       else -- PLAYER WHO REFFER OFFLINE
    27.         -- Fetch the referrer's account_id based on ref_key from previous query result
    28.         local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
    29.         -- If result is found
    30.         if resultId2 ~= false then
    31.           -- Update accountId's row blocked value to 1
    32.           db.executeQuery("UPDATE `__cornex_referral_actions` SET `blocked` = 1 WHERE `registered_by` = " .. accountId)
    33.           -- Update points to referrer
    34.           -- ADD REWARD TO REFFERER
    35.  
    36.           -- REWARD 1 storage
    37.           db.executeQuery("INSERT INTO `player_storage` SET (`player_id`, `key`, `value`) VALUES ('" .. result.getDataInt(resultId2, "belongs_to") .. "', '" .. r.storage .. "', '" .. 1 .. "')")
    38.           -- REWARD 2 addon 22,1
    39.           -- REWARD 3 addon 22,2
    40.           result.free(resultId2)
    41.         else
    42.           print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
    43.         end
    44.         result.free(resultId)
    45.       end
    46.     end
    47.   end
    48.   return true
    49. end
    50.  
    And do i going to the right way?
    Srry, i never did something big like this...
     
  14. Flatlander

    Flatlander Species Developer

    Joined:
    Feb 17, 2009
    Messages:
    2,457
    Likes Received:
    1,294
    Best Answers:
    2
    Ok I will help and make this referal system for you.

    But I will make the code easy to read and understand so you can learn from it:
    Code (Text):
    1.  
    2. referral_rewards = {
    3.    --[Reward_Level] = {premmydays = #, storage = #},
    4.    [50] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
    5.    [100] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}},
    6.    [150] = {premmydays = 5, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}},
    7. }
    8.  
    9. function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
    10.    if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
    11.        if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
    12.            return true
    13.        else
    14.            doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
    15.        end
    16.    end
    17.    doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
    18.    local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
    19.    if outfits then -- If there are Outfits to add
    20.        for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
    21.            doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
    22.        end
    23.    end
    24.    return true
    25. end
    26.  
    27.  
    28.  
    29. function onAdvance(cid, skill, oldLevel, newLevel)
    30.    if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
    31.    ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
    32.        local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
    33.        if currentReferralLevel >= newLevel then -- This will make sure one player cannot keep giving rewards if they kill themselves then re-level over and over again
    34.            return true
    35.        end
    36.        doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
    37.    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    38.        local accountId = getAccountId(cid)
    39.        -- Fetch the ref_key where account_id = accountId and blocked = 0
    40.        local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    41.        if resultId ~= false then -- This means the player has a referral
    42.            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
    43.            if resultId2 ~= false then -- This means we have found the player's GUID
    44.                local playerGUID = result.getDataInt(resultId2, "belongs_to")
    45.                local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
    46.                if isPlayer(referredPlayer) then -- Player is online
    47.                    doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
    48.                else -- Player is Offline
    49.                    local str = "guid "..playerGUID -- Creates String to be used in global storage
    50.                    local referralStorage = getGlobalStorage(str) -- Checks to see if Storage already Set
    51.                    if referralStorage == -1 then -- Has never received a referral reward
    52.                        referralStorage = {} -- Setting up table
    53.                    end
    54.                    if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
    55.                        referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
    56.                    else
    57.                        referralStorage[newLevel] = 1 -- If no, create new pending referral
    58.                    end
    59.                    setGlobalStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
    60.                end
    61.                result.free(resultId2)
    62.            else
    63.                print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
    64.            end
    65.            result.free(resultId)
    66.        end
    67.    end
    68.    return true
    69. end
    70.  
    71. function onLogin(cid)
    72.    local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
    73.    local str = "guid "..playerGUID -- Creates the string to check storage
    74.    local referralStorage = getGlobalStorage(str)
    75.    if referralStorage ~= -1 then
    76.        referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
    77.        for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
    78.            for a = 1, tid do
    79.                doPlayerReferralRewards(cid, i) -- Gives player each referral
    80.            end
    81.        end
    82.        setGlobalStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
    83.    end
    84.    return true
    85. end
    86.  
    I think this should all work (I have not tested it) let me know if you have any questions or if there are any errors.

    You'll need to create 2 creaturescripts for this.
    one onAdvance creaturescript and one onLogin Creaturescript going to this same file.
     
    supergt and sucibob like this.
  15. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0

    THANK YOU SO MUCH!

    ---

    I'm reciving this errors when any player login:
    Code (Text):
    1.  
    2. [9:4:54.507] Axe has logged in.
    3.  
    4. [9:4:54.508] [Error - CreatureScript Interface]
    5. [9:4:54.508] data/creaturescripts/scripts/referral.lua:onLogin
    6. [9:4:54.508] Description:
    7. [9:4:54.508] data/creaturescripts/scripts/referral.lua:73: attempt to call global 'getGlobalStorage' (a nil value)
    8. [9:4:54.508] stack traceback:
    9. [9:4:54.508]    data/creaturescripts/scripts/referral.lua:73: in function <data/creaturescripts/scripts/referral.lua:70>
    10. [9:4:54.549] Axe has logged out.
    11.  
    12.  
    I'm doing something wrong?

    Because i close some }, that i think you forgotten to close (idk if i did right)
    In here:
    Code (Text):
    1.  
    2.    [50] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
    3.    [100] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}}},
    4.    [150] = {premmydays = 5, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}}},
    5.  

    So my script is:
    Code (Text):
    1.  
    2. referral_rewards = {
    3.    --[Reward_Level] = {premmydays = #, storage = #},
    4.    [50] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
    5.    [100] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}}},
    6.    [150] = {premmydays = 5, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}}},
    7. }
    8. function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
    9.    if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
    10.        if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
    11.            return true
    12.        else
    13.            doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
    14.        end
    15.    end
    16.    doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
    17.    local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
    18.    if outfits then -- If there are Outfits to add
    19.        for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
    20.            doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
    21.        end
    22.    end
    23.    return true
    24. end
    25. function onAdvance(cid, skill, oldLevel, newLevel)
    26.    if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
    27.    ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
    28.        local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
    29.        if currentReferralLevel >= newLevel then -- This will make sure one player cannot keep giving rewards if they kill themselves then re-level over and over again
    30.            return true
    31.        end
    32.        doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
    33.    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    34.        local accountId = getAccountId(cid)
    35.        -- Fetch the ref_key where account_id = accountId and blocked = 0
    36.        local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    37.        if resultId ~= false then -- This means the player has a referral
    38.            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
    39.            if resultId2 ~= false then -- This means we have found the player's GUID
    40.                local playerGUID = result.getDataInt(resultId2, "belongs_to")
    41.                local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
    42.                if isPlayer(referredPlayer) then -- Player is online
    43.                    doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
    44.                else -- Player is Offline
    45.                    local str = "guid "..playerGUID -- Creates String to be used in global storage
    46.                    local referralStorage = getGlobalStorage(str) -- Checks to see if Storage already Set
    47.                    if referralStorage == -1 then -- Has never received a referral reward
    48.                        referralStorage = {} -- Setting up table
    49.                    end
    50.                    if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
    51.                        referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
    52.                    else
    53.                        referralStorage[newLevel] = 1 -- If no, create new pending referral
    54.                    end
    55.                    setGlobalStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
    56.                end
    57.                result.free(resultId2)
    58.            else
    59.                print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
    60.            end
    61.            result.free(resultId)
    62.        end
    63.    end
    64.    return true
    65. end
    66. function onLogin(cid)
    67.    local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
    68.    local str = "guid "..playerGUID -- Creates the string to check storage
    69.    local referralStorage = getGlobalStorage(str)
    70.    if referralStorage ~= -1 then
    71.        referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
    72.        for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
    73.            for a = 1, tid do
    74.                doPlayerReferralRewards(cid, i) -- Gives player each referral
    75.            end
    76.        end
    77.        setGlobalStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
    78.    end
    79.    return true
    80. end
    81.  
    Code (Text):
    1.  
    2.     <event type="advance" name="advReferral" script="referral.lua"/>
    3.    <event type="login" name="lgiReferral" script="referral.lua"/>
    4.  
    And on login.lua
    Code (Text):
    1.  
    2. registerCreatureEvent(cid, "lgiReferral")
    3.  
     
  16. Flatlander

    Flatlander Species Developer

    Joined:
    Feb 17, 2009
    Messages:
    2,457
    Likes Received:
    1,294
    Best Answers:
    2
    It sounds like your version of TFS might use "getStorage" and "setStorage" instead of "getGlobalStorage" and "setGlobalStorage"


    Below I have replaced everything with the new API getStorage and setStorage, let me know if it works.

    Also nice catch on the brackets, I closed the ones I missed in the below revised code.

    Code (Text):
    1.  
    2. referral_rewards = {
    3.    --[Reward_Level] = {premmydays = #, storage = #},
    4.    [50] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
    5.    [100] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}}},
    6.    [150] = {premmydays = 5, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}}},
    7. }
    8.  
    9. function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
    10.    if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
    11.        if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
    12.            return true
    13.        else
    14.            doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
    15.        end
    16.    end
    17.    doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
    18.    local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
    19.    if outfits then -- If there are Outfits to add
    20.        for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
    21.            doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
    22.        end
    23.    end
    24.    return true
    25. end
    26.  
    27.  
    28.  
    29. function onAdvance(cid, skill, oldLevel, newLevel)
    30.    if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
    31.    ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
    32.        local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
    33.        if currentReferralLevel >= newLevel then -- This will make sure one player cannot keep giving rewards if they kill themselves then re-level over and over again
    34.            return true
    35.        end
    36.        doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
    37.    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    38.        local accountId = getAccountId(cid)
    39.        -- Fetch the ref_key where account_id = accountId and blocked = 0
    40.        local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    41.        if resultId ~= false then -- This means the player has a referral
    42.            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
    43.            if resultId2 ~= false then -- This means we have found the player's GUID
    44.                local playerGUID = result.getDataInt(resultId2, "belongs_to")
    45.                local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
    46.                if isPlayer(referredPlayer) then -- Player is online
    47.                    doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
    48.                else -- Player is Offline
    49.                    local str = "guid "..playerGUID -- Creates String to be used in global storage
    50.                    local referralStorage = getStorage(str) -- Checks to see if Storage already Set
    51.                    if referralStorage == -1 then -- Has never received a referral reward
    52.                        referralStorage = {} -- Setting up table
    53.                    end
    54.                    if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
    55.                        referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
    56.                    else
    57.                        referralStorage[newLevel] = 1 -- If no, create new pending referral
    58.                    end
    59.                    setStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
    60.                end
    61.                result.free(resultId2)
    62.            else
    63.                print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
    64.            end
    65.            result.free(resultId)
    66.        end
    67.    end
    68.    return true
    69. end
    70.  
    71. function onLogin(cid)
    72.    local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
    73.    local str = "guid "..playerGUID -- Creates the string to check storage
    74.    local referralStorage = getStorage(str)
    75.    if referralStorage ~= -1 then
    76.        referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
    77.        for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
    78.            for a = 1, tid do
    79.                doPlayerReferralRewards(cid, i) -- Gives player each referral
    80.            end
    81.        end
    82.        setStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
    83.    end
    84.    return true
    85. end
    86.  
     
    supergt likes this.
  17. Flatlander

    Flatlander Species Developer

    Joined:
    Feb 17, 2009
    Messages:
    2,457
    Likes Received:
    1,294
    Best Answers:
    2
    Let me know if it works :)
     
    sucibob likes this.
  18. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Not work bro

    Using
    Code (Text):
    1.  
    2. referral_rewards = {
    3.    --[Reward_Level] = {premmydays = #, storage = #},
    4.    -- [80], [100], [150]
    5.    [3] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
    6.    [4] = {premmydays = 2, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}}},
    7.    [5] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}}},
    8. }
    9. function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
    10.    if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
    11.        if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
    12.            return true
    13.        else
    14.            doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
    15.        end
    16.    end
    17.    doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
    18.    local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
    19.    if outfits then -- If there are Outfits to add
    20.        for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
    21.            doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
    22.        end
    23.    end
    24.    return true
    25. end
    26. function onAdvance(cid, skill, oldLevel, newLevel)
    27.    if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
    28.    ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
    29.        local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
    30.        if currentReferralLevel >= newLevel then -- This will make sure one player cannot keep giving rewards if they kill themselves then re-level over and over again
    31.            return true
    32.        end
    33.        doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
    34.    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    35.        local accountId = getAccountId(cid)
    36.        -- Fetch the ref_key where account_id = accountId and blocked = 0
    37.        local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    38.        if resultId ~= false then -- This means the player has a referral
    39.            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
    40.            if resultId2 ~= false then -- This means we have found the player's GUID
    41.                local playerGUID = result.getDataInt(resultId2, "belongs_to")
    42.                local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
    43.                if isPlayer(referredPlayer) then -- Player is online
    44.                    doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
    45.                else -- Player is Offline
    46.                    local str = "guid "..playerGUID -- Creates String to be used in global storage
    47.                    local referralStorage = getStorage(str) -- Checks to see if Storage already Set
    48.                    if referralStorage == -1 then -- Has never received a referral reward
    49.                        referralStorage = {} -- Setting up table
    50.                    end
    51.                    if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
    52.                        referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
    53.                    else
    54.                        referralStorage[newLevel] = 1 -- If no, create new pending referral
    55.                    end
    56.                    setStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
    57.                end
    58.                result.free(resultId2)
    59.            else
    60.                print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
    61.            end
    62.            result.free(resultId)
    63.        end
    64.    end
    65.    return true
    66. end
    67. function onLogin(cid)
    68.    local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
    69.    local str = "guid "..playerGUID -- Creates the string to check storage
    70.    local referralStorage = getStorage(str)
    71.    if referralStorage ~= -1 then
    72.        referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
    73.        for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
    74.            for a = 1, tid do
    75.                doPlayerReferralRewards(cid, i) -- Gives player each referral
    76.            end
    77.        end
    78.        setStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
    79.    end
    80.    return true
    81. end
    82.  
    I've create a new account, coppy the reffer code, created another one to be reffered by the first one
    So i got lvl 3 with reffer account offline
    Did not added 1 premmy day, and did not added player storage 40010

    Then i login the reffer and got lvl 4 on reffered account
    Did not added 2 premmy days and first warmaster addon

    To the last teest i logout the reffer account and got lvl 5 on reffered account
    Did not added 3 premmy days and second warmaster addon
     
  19. Flatlander

    Flatlander Species Developer

    Joined:
    Feb 17, 2009
    Messages:
    2,457
    Likes Received:
    1,294
    Best Answers:
    2
    Can you post the Rewards Table you used? Or did you just use mine?
     
    Last edited: Jul 29, 2018
    sucibob likes this.
  20. sucibob

    sucibob Member

    Joined:
    Mar 28, 2017
    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    I've used yours

    Should i change on
    [3] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.

    To
    [3] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.

    Or will not work?
    50010
     

Share This Page

Loading...