• 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
 
you just need to change 2 lines, its a shame that you have been waiting many days just cus you "would not" try to read the fucking code like the fucking math shit it is

Lol you still mad to that i said?
You arent here just because your EGO?

Hey dude

Change to:
Code:
local accountId = getAccountId(cid)

And remove
Code:
local player = Player(cid)

:eek:

Thank you man, so much!
Now there is no errors when player advanced level, but when i get lvl 10, its not adding bonusPoints

You know why?
 
Same thing here:
PHP:
function onAdvance(cid, skill, oldLevel, newLevel)
   local requiredLevel = 10 -- Required level that the referred player must reach
   local bonusPoints = 5 -- The number of points (in Znote) that the referrer will get
   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
         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

No errors, no adding points...

I'm sorry if it something idiot, i not ask to a lot things, i just think its important to get players
 
Back
Top