• 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
 
2f5BQSi
2f5J0Gg
 
Real reason to why @StreamSide came in my topics to troll...
Because i said the true for him
On this topic, i was looking for help, i solved and share with forum...

when you raise the magical number "1337" at bumps, a chest gonna popup with the answer, keep trying.


Maybe...
Thanks god not everyone here is like you ;)
Here in forum have people with skills and good hearth who give help and learn with people here...

People like @Shyzoul who show the way to fix this scripts

here guys (thanks to him):
tfs 0.4
Code:
function onThink(interval, lastExecution)
  local averageServerPing = 0
  local playerCount = 0

  for _, cid in ipairs(getPlayersOnline()) do
  local playerPing = playerGetLastPong(cid) - playerGetLastPing(cid)
  averageServerPing = (playerPing + averageServerPing)
  print(playerPing)
  playerCount =_
  end
  averageServerPing = (averageServerPing / playerCount)
  print(averageServerPing)
  if averageServerPing > 2000 then
  doBroadcastMessage("DDos attack! Everyone will be kicked")

  for _, cid in ipairs(getPlayersOnline()) do
  addEvent(function(cid)
  doRemoveCreature(cid)
  end, 1000, cid)
  end
  end
  return TRUE
end

tfs 1.0
Code:
function onThink(interval, lastExecution)
  local averageServerPing = 0
  local playerCount = 0

  for _, cid in ipairs(getPlayersOnline()) do
  local playerPing = player:getLastPong() - player:getLastPing()
  averageServerPing = (playerPing + averageServerPing)
  print(playerPing)
  playerCount =_
  end
  averageServerPing = (averageServerPing / playerCount)
  print(averageServerPing)
  if averageServerPing > 2000 then
  doBroadcastMessage("DDos attack! Everyone will be kicked")

  for _, cid in ipairs(getPlayersOnline()) do
  addEvent(function(cid)
  doRemoveCreature(cid)
  end, 1000, cid)
  end
  end
  return TRUE
end

I'm here to help and be helped, you are here to feet your ego
 
Last edited:
is funny how you never gonna understand what I'm trying to say

I'm sorry then...
So what are u trying to say?
Just left 2 scripts to i done everything
I search a lot, don't find, need to fix
When i fix by myserlf i post the code, because if someone got the problem after, they can fix looking in my topic...
Things like this there is a lot people waiting for, just look on topic how many guys ask for 0.4 script
https://otland.net/threads/znote-aac-tfs-1-1-referral-system.227199/


What i supposed to do?
 
I can solve for a few dollars.

;)
"If you're in an open-source community to make money, you're at the wrong place."

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

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILL_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
            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
            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") .. "'")
                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
 
"If you're in an open-source community to make money, you're at the wrong place."

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

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILL_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
            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
            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") .. "'")
                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

Thank you a lot!

But it's not working, i got lvl 10 in a new character reffered, but no errors on console and no add points...
Still showing:
Accounts registered with your key: 1
Players reached level 150 with your key: 0
on website
 
Thank you a lot!

But it's not working, i got lvl 10 in a new character reffered, but no errors on console and no add points...
Still showing:
Accounts registered with your key: 1
Players reached level 150 with your key: 0
on website
Code:
local cfg = {
    requiredLevel = 10,
    bonusPoints = 5
}

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILL_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
            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
            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
tell me what this prints
also did you start the character off at level 10? or did you actually level it up
 
Code:
local cfg = {
    requiredLevel = 10,
    bonusPoints = 5
}

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILL_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
            local resultId2 = db.storeQuery("SELECT `belongs_to` FROM `__cornex_referral` WHERE `referral_key` = '" .. result.getDataString(resultId, "ref_key") .. "'")
            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
tell me what this prints
also did you start the character off at level 10? or did you actually level it up


Don't print nothing on console
I'm adding
PHP:
/addskill Referenciado,level
 
Code:
local cfg = {
   requiredLevel = 10,
    bonusPoints = 5
}

function onAdvance(player, skill, oldlevel, newlevel)
    print('working?')
    if skill == SKILL_LEVEL and newLevel >= cfg.requiredLevel then
        print('working 2?')
        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
 
Code:
local cfg = {
   requiredLevel = 10,
    bonusPoints = 5
}

function onAdvance(player, skill, oldlevel, newlevel)
    print('working?')
    if skill == SKILL_LEVEL and newLevel >= cfg.requiredLevel then
        print('working 2?')
        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

Printing
Code:
[12:13:41.433] Referenciado has logged in.
working?
 
Printing
Code:
[12:13:41.433] Referenciado has logged in.
working?
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 ; _ ;
 
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>
 
Back
Top