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

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

sucibob

Member
Joined
Mar 28, 2017
Messages
128
Reaction score
13
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:
function onAdvance(cid, skill, oldLevel, newLevel)


  local r = {
    [50] = {premmydays = 1, storage = 50010},
    [100] = {premmydays = 3, outfitid = 22, addon = 1},
    [150] = {premmydays = 5, outfitid = 22, addon = 2},
  }

  local requiredLevel = 15

   if skill == SKILL_LEVEL and newLevel >= requiredLevel then
     local accountId = getAccountId(cid)
     -- Fetch the ref_key where account_id = accountId and blocked = 0
     local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
     -- If result is found
     if resultId ~= false then

       -- 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") .. "'")
         -- If result is found
       if resultId2 ~= false then
         -- Update accountId's row blocked value to 1
         db.executeQuery("UPDATE `__cornex_referral_actions` SET `blocked` = 1 WHERE `registered_by` = " .. accountId)
         -- Update points to referrer
         -- ADD REWARD TO REFFERER

         -- REWARD 1 storage
         db.executeQuery("INSERT INTO `player_storage` SET (`player_id`, `key`, `value`) VALUES ('" .. result.getDataInt(resultId2, "belongs_to") .. "', '" .. r.storage .. "', '" .. 1 .. "')")
         -- REWARD 2 addon 22,1
         -- REWARD 3 addon 22,2
         result.free(resultId2)
       else
         print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
       end
       result.free(resultId)

     end
   end
   return true
end

---
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:
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:
function onAdvance(cid, skill, oldLevel, newLevel)
    local r = {
        [50] = {premmydays = 1, storage = 50010},
        [100] = {premmydays = 3, outfitid = 22, addon = 1},
        [150] = {premmydays = 5, outfitid = 22, addon = 2},
    }
    local requiredLevel = 15
    if skill == SKILL_LEVEL and newLevel >= requiredLevel then
        if newLevel - oldLevel== 1 then
            local reward = r[newLevel]
            if reward then
                -- do something here because he reached 50, 100 or 150.
            end
        else
            for i = oldLevel + 1, newLevel do
                local reward = r[i]
                if reward then
                    -- do the same here because he reached 50, 100 or 150. (probably a good idea to create a function? DRY.)
            end
        end

        local accountId = getAccountId(cid)
        -- Fetch the ref_key where account_id = accountId and blocked = 0
        local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
        -- If result is found
        if resultId ~= false then
 
            -- 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") .. "'")
            -- If result is found
            if resultId2 ~= false then
                -- Update accountId's row blocked value to 1
                db.executeQuery("UPDATE `__cornex_referral_actions` SET `blocked` = 1 WHERE `registered_by` = " .. accountId)
                -- Update points to referrer
                -- ADD REWARD TO REFFERER
 
                -- REWARD 1 storage
                db.executeQuery("INSERT INTO `player_storage` SET (`player_id`, `key`, `value`) VALUES ('" .. result.getDataInt(resultId2, "belongs_to") .. "', '" .. r.storage .. "', '" .. 1 .. "')")
                -- REWARD 2 addon 22,1
                -- REWARD 3 addon 22,2
                result.free(resultId2)
            else
                print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
            end
            result.free(resultId)
        end
    end
   return true
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.
 
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:
 
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:

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.
 
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.

1. No need storage for reward items.
2. Need storage for execute function.
3. Make it for me? xD

Lua:
function onAdvance(cid, skill, oldLevel, newLevel) -- Make second script to check offline players, "onLogin" and delete "1" level.
        if skill == SKILL__LEVEL and newLevel == 1 then
    doPlayerSetStorageValue(uid, 5555, 1)
    doPlayerSetStorageValue(uid, 5556, 1)
    doPlayerSetStorageValue(uid, 5557, 1)
  
        if skill == SKILL__LEVEL and newLevel == 50 and getPlayerStorageValue(uid, 5555) then -- 50.99 onLogin check.
    doPlayerAddItem(cid, 2121)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "50 Level? U are monster!")
    doPlayerSetStorageValue(uid, 5555, -1)
  
        elseif skill == SKILL__LEVEL and newLevel == 100 and getPlayerStorageValue(uid, 5556) then -- 100.149 onLogin check.
    doPlayerAddItem(cid, 2121)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "The Beast!")
    doPlayerSetStorageValue(uid, 5556, -1)

        elseif skill == SKILL__LEVEL and newLevel == 150 and getPlayerStorageValue(uid, 5557) then -- 150.999 onLogin check.
    doPlayerAddItem(cid, 2121)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Meow, meow~!")
    doPlayerSetStorageValue(uid, 5557, -1)

        return true
    end
end
 
Last edited:
I asked about how to use array to check lvls
To get information from here:
Code:
    [50] = {premmydays = 1, storage = 50010},
    [100] = {premmydays = 3, outfitid = 22, addon = 1},
    [150] = {premmydays = 5, outfitid = 22, addon = 2},

[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:
     local accountId = getAccountId(cid)
     -- Fetch the ref_key where account_id = accountId and blocked = 0
     local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
     -- If result is found
     if resultId ~= false then


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 :(
 
I asked about how to use array to check lvls
To get information from here:
Code:
    [50] = {premmydays = 1, storage = 50010},
    [100] = {premmydays = 3, outfitid = 22, addon = 1},
    [150] = {premmydays = 5, outfitid = 22, addon = 2},

[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:
     local accountId = getAccountId(cid)
     -- Fetch the ref_key where account_id = accountId and blocked = 0
     local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
     -- If result is found
     if resultId ~= false then


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 :(

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:
<action itemid="8000" event="script" value="other/recoBox50.lua"/>
<action itemid="8001" event="script" value="other/recoBox100.lua"/>
<action itemid="8002" event="script" value="other/recoBox150.lua"/>
recoBox50.lua
Lua:
-- RECO BOX 50
function onUse(cid, item, frompos, item2, topos)
doPlayerAddPremiumDays(cid, 3) -- Premmium days value.
doPlayerAddOutfit(cid, 1, 3) -- First number outfit ID, second addons.
doRemoveItem(cid, item.uid, 1) -- This remove RECO BOX after using.
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:
    local r = {
        [50] = {premmydays = 1, storage = 50010},
        [100] = {premmydays = 3, outfitid = 22, addon = 1},
        [150] = {premmydays = 5, outfitid = 22, addon = 2},
    }
if (r[50]) then
 
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:
<action itemid="8000" event="script" value="other/recoBox50.lua"/>
<action itemid="8001" event="script" value="other/recoBox100.lua"/>
<action itemid="8002" event="script" value="other/recoBox150.lua"/>
recoBox50.lua
Lua:
-- RECO BOX 50
function onUse(cid, item, frompos, item2, topos)
doPlayerAddPremiumDays(cid, 3) -- Premmium days value.
doPlayerAddOutfit(cid, 1, 3) -- First number outfit ID, second addons.
doRemoveItem(cid, item.uid, 1) -- This remove RECO BOX after using.
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:
    local r = {
        [50] = {premmydays = 1, storage = 50010},
        [100] = {premmydays = 3, outfitid = 22, addon = 1},
        [150] = {premmydays = 5, outfitid = 22, addon = 2},
    }
if (r[50]) then

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
 
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:
if getGlobalStorage(getCreatureName(cid)) = 1 then
  -- Do Referral Bonus
end
 
@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:
function onAdvance(cid, skill, oldLevel, newLevel)
  local r = {
    [50] = {premmydays = 1, storage = 50010},
    [100] = {premmydays = 3, addon = 1},
    [150] = {premmydays = 5, addon = 2},
  }
  local requiredLevel = 15
  if skill == SKILL_LEVEL and newLevel >= requiredLevel then
    local accountId = getAccountId(cid)
    -- Fetch the ref_key where account_id = accountId and blocked = 0
    local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
    if resultId ~= false then -- If result is found
      if getGlobalStorage(getCreatureName(cid)) == 1 then -- PLAYER WHO REFFER ONLINE
        -- lvl == 50
          setPlayerStorageValue(cid,50010,1)
          doPlayerAddPremiumDays(cid, 1)
        -- lvl == 100
          doPlayerAddOutfit(cid, 336, 1)
          doPlayerAddOutfit(cid, 335, 1)
          doPlayerAddPremiumDays(cid, 3)
        -- lvl == 150
          doPlayerAddOutfit(cid, 336, 2)
          doPlayerAddOutfit(cid, 335, 2)
          doPlayerAddPremiumDays(cid, 5)
      else -- PLAYER WHO REFFER OFFLINE
        -- 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") .. "'")
        -- If result is found
        if resultId2 ~= false then
          -- Update accountId's row blocked value to 1
          db.executeQuery("UPDATE `__cornex_referral_actions` SET `blocked` = 1 WHERE `registered_by` = " .. accountId)
          -- Update points to referrer
          -- ADD REWARD TO REFFERER

          -- REWARD 1 storage
          db.executeQuery("INSERT INTO `player_storage` SET (`player_id`, `key`, `value`) VALUES ('" .. result.getDataInt(resultId2, "belongs_to") .. "', '" .. r.storage .. "', '" .. 1 .. "')")
          -- REWARD 2 addon 22,1
          -- REWARD 3 addon 22,2
          result.free(resultId2)
        else
          print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
        end
        result.free(resultId)
      end
    end
  end
  return true
end

And do i going to the right way?
Srry, i never did something big like this...
 
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:
referral_rewards = {
   --[Reward_Level] = {premmydays = #, storage = #},
   [50] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
   [100] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}},
   [150] = {premmydays = 5, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}},
}

function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
   if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
       if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
           return true
       else
           doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
       end
   end
   doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
   local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
   if outfits then -- If there are Outfits to add
       for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
           doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
       end
   end
   return true
end



function onAdvance(cid, skill, oldLevel, newLevel)
   if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
   ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
       local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
       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
           return true
       end
       doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
   -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       local accountId = getAccountId(cid)
       -- Fetch the ref_key where account_id = accountId and blocked = 0
       local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
       if resultId ~= false then -- This means the player has a referral
           local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
           if resultId2 ~= false then -- This means we have found the player's GUID
               local playerGUID = result.getDataInt(resultId2, "belongs_to")
               local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
               if isPlayer(referredPlayer) then -- Player is online
                   doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
               else -- Player is Offline
                   local str = "guid "..playerGUID -- Creates String to be used in global storage
                   local referralStorage = getGlobalStorage(str) -- Checks to see if Storage already Set
                   if referralStorage == -1 then -- Has never received a referral reward
                       referralStorage = {} -- Setting up table
                   end
                   if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
                       referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
                   else
                       referralStorage[newLevel] = 1 -- If no, create new pending referral
                   end
                   setGlobalStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
               end
               result.free(resultId2)
           else
               print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
           end
           result.free(resultId)
       end
   end
   return true
end

function onLogin(cid)
   local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
   local str = "guid "..playerGUID -- Creates the string to check storage
   local referralStorage = getGlobalStorage(str)
   if referralStorage ~= -1 then
       referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
       for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
           for a = 1, tid do
               doPlayerReferralRewards(cid, i) -- Gives player each referral
           end
       end
       setGlobalStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
   end
   return true
end

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.
 
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:
referral_rewards = {
   --[Reward_Level] = {premmydays = #, storage = #},
   [50] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
   [100] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}},
   [150] = {premmydays = 5, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}},
}

function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
   if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
       if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
           return true
       else
           doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
       end
   end
   doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
   local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
   if outfits then -- If there are Outfits to add
       for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
           doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
       end
   end
   return true
end



function onAdvance(cid, skill, oldLevel, newLevel)
   if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
   ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
       local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
       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
           return true
       end
       doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
   -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       local accountId = getAccountId(cid)
       -- Fetch the ref_key where account_id = accountId and blocked = 0
       local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
       if resultId ~= false then -- This means the player has a referral
           local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
           if resultId2 ~= false then -- This means we have found the player's GUID
               local playerGUID = result.getDataInt(resultId2, "belongs_to")
               local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
               if isPlayer(referredPlayer) then -- Player is online
                   doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
               else -- Player is Offline
                   local str = "guid "..playerGUID -- Creates String to be used in global storage
                   local referralStorage = getGlobalStorage(str) -- Checks to see if Storage already Set
                   if referralStorage == -1 then -- Has never received a referral reward
                       referralStorage = {} -- Setting up table
                   end
                   if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
                       referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
                   else
                       referralStorage[newLevel] = 1 -- If no, create new pending referral
                   end
                   setGlobalStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
               end
               result.free(resultId2)
           else
               print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
           end
           result.free(resultId)
       end
   end
   return true
end

function onLogin(cid)
   local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
   local str = "guid "..playerGUID -- Creates the string to check storage
   local referralStorage = getGlobalStorage(str)
   if referralStorage ~= -1 then
       referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
       for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
           for a = 1, tid do
               doPlayerReferralRewards(cid, i) -- Gives player each referral
           end
       end
       setGlobalStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
   end
   return true
end

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.


THANK YOU SO MUCH!

---

I'm reciving this errors when any player login:
Code:
[9:4:54.507] Axe has logged in.

[9:4:54.508] [Error - CreatureScript Interface]
[9:4:54.508] data/creaturescripts/scripts/referral.lua:onLogin
[9:4:54.508] Description:
[9:4:54.508] data/creaturescripts/scripts/referral.lua:73: attempt to call global 'getGlobalStorage' (a nil value)
[9:4:54.508] stack traceback:
[9:4:54.508]    data/creaturescripts/scripts/referral.lua:73: in function <data/creaturescripts/scripts/referral.lua:70>
[9:4:54.549] Axe has logged out.

I'm doing something wrong?

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


So my script is:
Code:
referral_rewards = {
   --[Reward_Level] = {premmydays = #, storage = #},
   [50] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
   [100] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}}},
   [150] = {premmydays = 5, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}}},
}
function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
   if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
       if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
           return true
       else
           doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
       end
   end
   doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
   local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
   if outfits then -- If there are Outfits to add
       for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
           doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
       end
   end
   return true
end
function onAdvance(cid, skill, oldLevel, newLevel)
   if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
   ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
       local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
       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
           return true
       end
       doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
   -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       local accountId = getAccountId(cid)
       -- Fetch the ref_key where account_id = accountId and blocked = 0
       local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
       if resultId ~= false then -- This means the player has a referral
           local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
           if resultId2 ~= false then -- This means we have found the player's GUID
               local playerGUID = result.getDataInt(resultId2, "belongs_to")
               local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
               if isPlayer(referredPlayer) then -- Player is online
                   doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
               else -- Player is Offline
                   local str = "guid "..playerGUID -- Creates String to be used in global storage
                   local referralStorage = getGlobalStorage(str) -- Checks to see if Storage already Set
                   if referralStorage == -1 then -- Has never received a referral reward
                       referralStorage = {} -- Setting up table
                   end
                   if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
                       referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
                   else
                       referralStorage[newLevel] = 1 -- If no, create new pending referral
                   end
                   setGlobalStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
               end
               result.free(resultId2)
           else
               print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
           end
           result.free(resultId)
       end
   end
   return true
end
function onLogin(cid)
   local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
   local str = "guid "..playerGUID -- Creates the string to check storage
   local referralStorage = getGlobalStorage(str)
   if referralStorage ~= -1 then
       referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
       for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
           for a = 1, tid do
               doPlayerReferralRewards(cid, i) -- Gives player each referral
           end
       end
       setGlobalStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
   end
   return true
end

Code:
    <event type="advance" name="advReferral" script="referral.lua"/>
   <event type="login" name="lgiReferral" script="referral.lua"/>

And on login.lua
Code:
registerCreatureEvent(cid, "lgiReferral")
 
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:
referral_rewards = {
   --[Reward_Level] = {premmydays = #, storage = #},
   [50] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
   [100] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}}},
   [150] = {premmydays = 5, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}}},
}

function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
   if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
       if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
           return true
       else
           doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
       end
   end
   doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
   local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
   if outfits then -- If there are Outfits to add
       for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
           doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
       end
   end
   return true
end



function onAdvance(cid, skill, oldLevel, newLevel)
   if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
   ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
       local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
       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
           return true
       end
       doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
   -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       local accountId = getAccountId(cid)
       -- Fetch the ref_key where account_id = accountId and blocked = 0
       local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
       if resultId ~= false then -- This means the player has a referral
           local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
           if resultId2 ~= false then -- This means we have found the player's GUID
               local playerGUID = result.getDataInt(resultId2, "belongs_to")
               local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
               if isPlayer(referredPlayer) then -- Player is online
                   doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
               else -- Player is Offline
                   local str = "guid "..playerGUID -- Creates String to be used in global storage
                   local referralStorage = getStorage(str) -- Checks to see if Storage already Set
                   if referralStorage == -1 then -- Has never received a referral reward
                       referralStorage = {} -- Setting up table
                   end
                   if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
                       referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
                   else
                       referralStorage[newLevel] = 1 -- If no, create new pending referral
                   end
                   setStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
               end
               result.free(resultId2)
           else
               print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
           end
           result.free(resultId)
       end
   end
   return true
end

function onLogin(cid)
   local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
   local str = "guid "..playerGUID -- Creates the string to check storage
   local referralStorage = getStorage(str)
   if referralStorage ~= -1 then
       referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
       for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
           for a = 1, tid do
               doPlayerReferralRewards(cid, i) -- Gives player each referral
           end
       end
       setStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
   end
   return true
end
 
Let me know if it works :)
Not work bro

Using
Code:
referral_rewards = {
   --[Reward_Level] = {premmydays = #, storage = #},
   -- [80], [100], [150]
   [3] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
   [4] = {premmydays = 2, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}}},
   [5] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}}},
}
function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
   if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
       if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
           return true
       else
           doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
       end
   end
   doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
   local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
   if outfits then -- If there are Outfits to add
       for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
           doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
       end
   end
   return true
end
function onAdvance(cid, skill, oldLevel, newLevel)
   if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
   ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
       local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
       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
           return true
       end
       doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
   -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       local accountId = getAccountId(cid)
       -- Fetch the ref_key where account_id = accountId and blocked = 0
       local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
       if resultId ~= false then -- This means the player has a referral
           local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
           if resultId2 ~= false then -- This means we have found the player's GUID
               local playerGUID = result.getDataInt(resultId2, "belongs_to")
               local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
               if isPlayer(referredPlayer) then -- Player is online
                   doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
               else -- Player is Offline
                   local str = "guid "..playerGUID -- Creates String to be used in global storage
                   local referralStorage = getStorage(str) -- Checks to see if Storage already Set
                   if referralStorage == -1 then -- Has never received a referral reward
                       referralStorage = {} -- Setting up table
                   end
                   if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
                       referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
                   else
                       referralStorage[newLevel] = 1 -- If no, create new pending referral
                   end
                   setStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
               end
               result.free(resultId2)
           else
               print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
           end
           result.free(resultId)
       end
   end
   return true
end
function onLogin(cid)
   local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
   local str = "guid "..playerGUID -- Creates the string to check storage
   local referralStorage = getStorage(str)
   if referralStorage ~= -1 then
       referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
       for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
           for a = 1, tid do
               doPlayerReferralRewards(cid, i) -- Gives player each referral
           end
       end
       setStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
   end
   return true
end

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
 
Not work bro

Using
Code:
referral_rewards = {
   --[Reward_Level] = {premmydays = #, storage = #},
   -- [80], [100], [150]
   [3] = {premmydays = 1, storage = false, outfit = false}, --Storage is only needed if you want them to only receive this reward on their first referal.
   [4] = {premmydays = 2, storage = false, outfit = {[1] = {o = 335, a = 1}, [2] = {o = 336, a = 1}}},
   [5] = {premmydays = 3, storage = false, outfit = {[1] = {o = 335, a = 2}, [2] = {o = 336, a = 2}}},
}
function doPlayerReferralRewards(referredPlayer, newLevel) -- Created New Function to save space and make things easier
   if referral_rewards[newLevel].storage then -- Check if they can only receive reward from 1 player
       if getPlayerStorageValue(referredPlayer, referral_rewards[newLevel].storage) == 1 then -- Player already received this reward
           return true
       else
           doPlayerSetStorageValue(referredPlayer, referral_rewards[newLevel].storage, 1) -- Player has not yet received reward (Marking it now)
       end
   end
   doPlayerAddPremiumDays(referredPlayer, referral_rewards[newLevel].premmydays) -- Adding Premium Days
   local outfits = referral_rewards[newLevel].outfit -- Getting Outfit Table
   if outfits then -- If there are Outfits to add
       for _, tid in ipairs(outfits) do -- Go through Table to add all outfits
           doPlayerAddOutfit(referredPlayer, tid.o, tid.a) -- Adds each outfit and addon
       end
   end
   return true
end
function onAdvance(cid, skill, oldLevel, newLevel)
   if skill == SKILL_LEVEL and referral_rewards[newLevel] ~= nil then -- This will check if there is an entry for this level
   ----Anti-Abuse Storage Value ------------------------------------------------------------------------------------------------------------------------------------------------
       local currentReferralLevel = getPlayerStorageValue(cid, "Referral") -- Checks the highest level this account has reached.
       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
           return true
       end
       doPlayerSetStorageValue(cid, "Referral", newLevel) -- Sets the highest level reached to this newLevel
   -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       local accountId = getAccountId(cid)
       -- Fetch the ref_key where account_id = accountId and blocked = 0
       local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
       if resultId ~= false then -- This means the player has a referral
           local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
           if resultId2 ~= false then -- This means we have found the player's GUID
               local playerGUID = result.getDataInt(resultId2, "belongs_to")
               local referredPlayer = getPlayerByGUID(playerGUID) -- Attempts to get the player if he is online
               if isPlayer(referredPlayer) then -- Player is online
                   doPlayerReferralRewards(referredPlayer, newLevel) -- Do Referral Function
               else -- Player is Offline
                   local str = "guid "..playerGUID -- Creates String to be used in global storage
                   local referralStorage = getStorage(str) -- Checks to see if Storage already Set
                   if referralStorage == -1 then -- Has never received a referral reward
                       referralStorage = {} -- Setting up table
                   end
                   if referralStorage[newLevel] ~= nil then -- Checking if you have a pending Referral Bonus Already
                       referralStorage[newLevel] = referralStorage[newLevel] + 1 -- If you do, add to current pending referrals
                   else
                       referralStorage[newLevel] = 1 -- If no, create new pending referral
                   end
                   setStorage(str, table.serialize(referralStorage)) -- Sets the global storage for use upon login
               end
               result.free(resultId2)
           else
               print("Missing ref_key in `__cornex_referral` where ref_key = " .. result.getDataString(resultId, "ref_key"))
           end
           result.free(resultId)
       end
   end
   return true
end
function onLogin(cid)
   local playerGUID = getPlayerGUID(cid) -- Gets the Player's GUID
   local str = "guid "..playerGUID -- Creates the string to check storage
   local referralStorage = getStorage(str)
   if referralStorage ~= -1 then
       referralStorage = table.unserialize(referralStorage) -- Unserialize stored table for use
       for i, tid in pairs(referralStorage) do -- Loop through table to give all pending referrals
           for a = 1, tid do
               doPlayerReferralRewards(cid, i) -- Gives player each referral
           end
       end
       setStorage(str, -1) -- Sets the storage to -1 to show you have received all pending referrals
   end
   return true
end

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

Can you post the Rewards Table you used? Or did you just use mine?
 
Last edited:
Can you post the Rewards Table you used? Or did you just use mine?

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
 
Back
Top