• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Znote Referral system problems

willdu

Active Member
Joined
Mar 11, 2017
Messages
91
Reaction score
25
I'm using this reffer system: [Znote AAC][TFS 1.1] Referral system (https://otland.net/threads/znote-aac-tfs-1-1-referral-system.227199/#post-2405828)
For znote AAC, but for 0.4

I was trying to instead of add points, send some items for player in a parcel, but my knowledge are limited and i couldnt make it to work
So i need some helps:

1- The server is crashing everytime when the player invited get a level
2- Would be possible to add 3 options of levels?
I mean
Code:
    requiredLevel = 13,
    bonusPoints = 5

Code:
    requiredLevel = 50,
    bonusPoints = 100

Code:
    requiredLevel = 100,
    bonusPoints = 300

And on that part SET blocked = 1
Change to 1,2,3...

Script now
Code:
local cfg = {
    stor = 250888,
    requiredLevel = 13,
    bonusPoints = 5
}
local town_id = 1
local refferPointItemID = 2159

function getPlayerNameByGUID(guid)
local name = 0
      local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
      if(resultId:getID() ~= -1) then
          name = resultId.getDataString(resultId, "name")
          resultId:free()
      end
      return name
end

function onAdvance(cid, skill, oldLevel, newLevel)
    --if (newLevel == cfg.requiredLevel and skill == SKILL__LEVEL) and getPlayerStorageValue(cid, cfg.stor) < 1 then
    if (newLevel >= cfg.requiredLevel and skill == SKILL__LEVEL) then
        local accountId = getPlayerAccountId(cid)

        --local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
        local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. "")
        if resultId then
            print(resultId)
            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
            print(resultId2)
            if resultId2 then
                db.executeQuery("UPDATE `__cornex_referral_actions` SET `blocked` = 1 WHERE `registered_by` = " .. accountId)
                --db.executeQuery("UPDATE `znote_accounts` SET `points` = (points + " .. cfg.bonusPoints .. ") WHERE `account_id` = '" .. result.getDataInt(resultId2, "belongs_to") .. "'")
                local chest = doCreateItemEx(2595)
                doAddContainerItem(chest, refferPointItemID, cfg.bonusPoints)
                local targetaccountid = result.getDataInt(resultId2, "belongs_to")
                doPlayerSendMailByName(getPlayerNameByGUID(targetaccountid), chest, town_id)

                print('-> account id: ' .. result.getDataInt(resultId2, "belongs_to"))
                print('-> added ' .. cfg.bonusPoints .. ' points.')
                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

obs 1
i've coment this line and used that above to test in the same account, more easer
Code:
    --if (newLevel == cfg.requiredLevel and skill == SKILL__LEVEL) and getPlayerStorageValue(cid, cfg.stor) < 1 then
    if (newLevel >= cfg.requiredLevel and skill == SKILL__LEVEL) then

obs 2
same thing as obs 1, to test in the same account
Code:
        --local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
        local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. "")

Original script (working with points):
Code:
local cfg = {
    stor = 250888,
    requiredLevel = 13,
    bonusPoints = 5
}


function onAdvance(cid, skill, oldLevel, newLevel)
    if (newLevel == cfg.requiredLevel and skill == SKILL__LEVEL) and getPlayerStorageValue(cid, cfg.stor) < 1 then
        local accountId = getPlayerAccountId(cid)
   
        local resultId = db.storeQuery("SELECT `ref_key` FROM `__cornex_referral_actions` WHERE `registered_by` = " .. accountId .. " AND `blocked` = 0")
        if resultId then
            print(resultId)
            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
            print(resultId2)
            if resultId2 then
                db.executeQuery("UPDATE `__cornex_referral_actions` SET `blocked` = 1 WHERE `registered_by` = " .. accountId)
                db.executeQuery("UPDATE `znote_accounts` SET `points` = (points + " .. cfg.bonusPoints .. ") WHERE `account_id` = '" .. result.getDataInt(resultId2, "belongs_to") .. "'")
                print('-> account id: ' .. result.getDataInt(resultId2, "belongs_to"))
                print('-> added ' .. cfg.bonusPoints .. ' points.')
                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
 
Back
Top