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:
Official script: https://otland.net/threads/znote-aac-tfs-1-1-referral-system.227199/
My Script:
data/creaturescripts/creaturescripts.xml
data/creaturescripts/scripts/login.lua
data/creaturescripts/scripts/referral.lua
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