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

Help to fix Referral system 1.1 to 0.4

caquinha

Member
Joined
Aug 8, 2016
Messages
248
Solutions
1
Reaction score
24
Anyone could help me to convert this system...

I tried to use:
https://otland.net/threads/znote-aac-tfs-1-1-referral-system.227199/

In my 0.4 server, i made some changes, but not work...

Error:
Code:
[0:23:11.548] [Error - CreatureScript Interface]
[0:23:11.548] data/creaturescripts/scripts/referral.lua:onAdvance
[0:23:11.548] Description:
[0:23:11.548] data/creaturescripts/scripts/referral.lua:6: attempt to call global 'Player' (a nil value)
[0:23:11.548] stack traceback:
[0:23:11.548]    data/creaturescripts/scripts/referral.lua:6: in function <data/creaturescripts/scripts/referral.lua:3>

[0:23:13.396] [Error - CreatureScript Interface]
[0:23:13.396] data/creaturescripts/scripts/referral.lua:onAdvance
[0:23:13.396] Description:
[0:23:13.396] data/creaturescripts/scripts/referral.lua:6: attempt to call global 'Player' (a nil value)
[0:23:13.396] stack traceback:
[0:23:13.396]    data/creaturescripts/scripts/referral.lua:6: in function <data/creaturescripts/scripts/referral.lua:3>

Official script: https://otland.net/threads/znote-aac-tfs-1-1-referral-system.227199/

My Script:

data/creaturescripts/creaturescripts.xml
Code:
<event type="advance" name="Referral" script="referral.lua"/>

data/creaturescripts/scripts/login.lua
Code:
registerCreatureEvent(cid, "Referral")

data/creaturescripts/scripts/referral.lua
Code:
function onAdvance(cid, skill, oldLevel, newLevel)
   local requiredLevel = 150 -- Required level that the referred player must reach
   local bonusPoints = 5 -- The number of points (in Znote) that the referrer will get
   local player = Player(cid)
   if skill == SKILL_LEVEL and newLevel >= requiredLevel then
     local accountId = player:getAccountId()
     -- 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
         db.executeQuery("UPDATE `znote_accounts` SET `points` = (points + " .. bonusPoints .. ") WHERE `account_id` = '" .. result.getDataInt(resultId2, "belongs_to") .. "'")
         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
 
Using it:
Code:
local cfg = {
   requiredLevel = 10,
    bonusPoints = 5
}

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILLVALUE_LEVEL and newLevel >= cfg.requiredLevel then
        local accountId = player:getAccountId()
        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


Nothing even print on console, so i tried to my way:
Looking others scripts i made this chages:
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 = cid:getAccountId()
      
        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


But got this error, could you help me?
Code:
[0:9:25.079] [Error - CreatureScript Interface]
[0:9:25.079] data/creaturescripts/scripts/referral.lua:onAdvance
[0:9:25.079] Description:
[0:9:25.079] data/creaturescripts/scripts/referral.lua:10: attempt to index local 'cid' (a number value)
[0:9:25.079] stack traceback:
[0:9:25.079]    data/creaturescripts/scripts/referral.lua:10: in function <data/creaturescripts/scripts/referral.lua:8>

bump
 
Code:
local cfg = {
   requiredLevel = 10,
    bonusPoints = 5
}

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILLVALUE_LEVEL and newLevel >= cfg.requiredLevel then
        local accountId = player:getAccountId()
        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
should work
its SKILLVALUE_LEVEL not SKILL_LEVEL ; _ ;


Using it:
Code:
local cfg = {
   requiredLevel = 10,
    bonusPoints = 5
}

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILLVALUE_LEVEL and newLevel >= cfg.requiredLevel then
        local accountId = player:getAccountId()
        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


Nothing even print on console, so i tried to my way:
Looking others scripts i made this chages:
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 = cid:getAccountId()
     
        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


But got this error, could you help me?
Code:
[0:9:25.079] [Error - CreatureScript Interface]
[0:9:25.079] data/creaturescripts/scripts/referral.lua:onAdvance
[0:9:25.079] Description:
[0:9:25.079] data/creaturescripts/scripts/referral.lua:10: attempt to index local 'cid' (a number value)
[0:9:25.079] stack traceback:
[0:9:25.079]    data/creaturescripts/scripts/referral.lua:10: in function <data/creaturescripts/scripts/referral.lua:8>
 
Using it:
Code:
local cfg = {
   requiredLevel = 10,
    bonusPoints = 5
}

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILLVALUE_LEVEL and newLevel >= cfg.requiredLevel then
        local accountId = player:getAccountId()
        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


Nothing even print on console, so i tried to my way:
Looking others scripts i made this chages:
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 = cid:getAccountId()
    
        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


But got this error, could you help me?
Code:
[0:9:25.079] [Error - CreatureScript Interface]
[0:9:25.079] data/creaturescripts/scripts/referral.lua:onAdvance
[0:9:25.079] Description:
[0:9:25.079] data/creaturescripts/scripts/referral.lua:10: attempt to index local 'cid' (a number value)
[0:9:25.079] stack traceback:
[0:9:25.079]    data/creaturescripts/scripts/referral.lua:10: in function <data/creaturescripts/scripts/referral.lua:8>


bump this question
 
Back
Top