• Vote in September Mapping Competition to select a winner!
  • 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!

premium points tfs 1.x

theduck

Member
Joined
Dec 6, 2018
Messages
241
Best answers
0
Reaction score
18
I would like every time the player logs in
appears how many premiun points he has
Code:
local points = db.executeQuery('SELECT `premium_points` FROM `accounts` WHERE `id`=' .. player:getAccountId() ..';')
player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"Your Account has " .. points .. " premium points.")
 

Infernum

Support Team
Joined
Feb 14, 2015
Messages
5,582
Best answers
556
Reaction score
3,493
Lua:
local res = db.executeQuery('SELECT `premium_points` FROM `accounts` WHERE id=' .. player:getAccountId() ..';')
if res then
    local points = result.getNumber(res, 'premium_points')
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"Your Account has " .. points .. " premium points.")
end
result.free(res)
 
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
241
Best answers
0
Reaction score
18
Lua:
local res = db.executeQuery('SELECT `premium_points` FROM `accounts` WHERE id=' .. player:getAccountId() ..';')
if res then
    local points = result.getNumber(res, 'premium_points')
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"Your Account has " .. points .. " premium points.")
end
result.free(res)
')' expected near '" .. player:getAccountId() .. "'
 
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
241
Best answers
0
Reaction score
18
You have to put it inside of onLogin.
executeQuery' (a nil value)
stack traceback:
[C]: in function 'executeQuery'

yes I tested at login and globalevents to keep appearing to the player both got error
 
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
241
Best answers
0
Reaction score
18
Change db.executeQuery to db.storeQuery.
Your Account has 2927 premium points.

worked on login
you know how I can do it works on the function
function onThink (interval, lastExecution)
 

Infernum

Support Team
Joined
Feb 14, 2015
Messages
5,582
Best answers
556
Reaction score
3,493
Lua:
function Player.getPremiumPoints(self)
    local res = db.storeQuery('SELECT `premium_points` FROM `accounts` WHERE id=' .. self:getAccountId() ..';')
    local points = 0
    if res then
        points = result.getNumber(res, 'premium_points')
    end
    result.free(res)
    return points
end

function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        local points = player:getPremiumPoints()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format('You have %d premium points.', points))
    end
end
 
Last edited:
OP
T

theduck

Member
Joined
Dec 6, 2018
Messages
241
Best answers
0
Reaction score
18
Lua:
function Player.getPremiumPoints(self)
    local res = db.storeQuery('SELECT `premium_points` FROM `accounts` WHERE id=' .. player:getAccountId() ..';')
    local points = 0
    if res then
        points = result.getNumber(res, 'premium_points')
    end
    result.free(res)
    return points
end

function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        local points = player:getPremiumPoints()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format('You have %d premium points.', points))
    end
end
attempt to index global 'player' (a nil value)
stack traceback:
 
Top