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

TFS 1.X+ Give player premium points [OFFLINE]

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
782
Solutions
2
Reaction score
42
So im getting this error

attempt to call global 'getPlayerByNameWildcard' (a nil vlaue)
i guess there is no such function in tfs 1.2?

Lua:
function onSay(cid, words, param)

    local t = param:splitTrimmed(",")
  
    if param == '' then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Missing params.")
        return true
    end
  
    local player, balance, pid = getPlayerByName(t[1]), t[2], getPlayerByNameWildcard(t[1])
  
    if t[2] == null then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Missing ammount of points.")
        return true
    end
  
    local accountName = getPlayerAccount(player)
    local accountPoints = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '" .. accountName .. "' LIMIT 1;")
    local points = tonumber(accountPoints:getDataInt("premium_points"))
    local name = getPlayerName(cid)
  
    if(words == "/addpoints") then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You added "..balance.." premium points to "..t[1].." account.")
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, "You got "..balance.." premium points from "..name..".")
        points = (points+balance)
        db.query("UPDATE `accounts` SET `premium_points` = " .. points .. " WHERE `name`='" .. accountName .. "' LIMIT 1;")
    elseif (words == "/removepoints") then
        points = (points-balance)
        if points < 0 then
            doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, ""..name.." removed all your premium points.")
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You removed all "..t[1].." account premium points.")
            db.query("UPDATE `accounts` SET `premium_points` = '0' WHERE `name`='" .. accountName .. "' LIMIT 1;")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You removed "..balance.." premium points to "..t[1].." account.")
            db.query("UPDATE `accounts` SET `premium_points` = " .. points .. " WHERE `name`='" .. accountName .. "' LIMIT 1;")  
            doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, ""..name.." removed "..balance.." premium points from your account.")
        end
    end
  
    return true
end
 
Solution
Lua:
-- <talkaction words="/points" separator=" " script="change premium points.lua" />

function string:firstToUpper()
    return self:gsub("^%l", string.upper)
end

function onSay(player, words, param)
    local split = param:splitTrimmed(",")
    if param == '' then
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, "Missing params.")
        return true
    end

    local command = split[1]
    if not command or not isInArray({"add", "remove"}, command:lower()) then
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong usage, type '/points add, whiteblXK, 500' or '/points remove, whiteblXK, 500'")
        return true
    end
    
    local name, accountId = split[2], nil
    local resultId =...

whiteblXK

Member
Joined
Apr 20, 2011
Messages
311
Solutions
9
Reaction score
23
Location
Poland
Lua:
-- <talkaction words="/points" separator=" " script="change premium points.lua" />

function string:firstToUpper()
    return self:gsub("^%l", string.upper)
end

function onSay(player, words, param)
    local split = param:splitTrimmed(",")
    if param == '' then
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, "Missing params.")
        return true
    end

    local command = split[1]
    if not command or not isInArray({"add", "remove"}, command:lower()) then
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, "Wrong usage, type '/points add, whiteblXK, 500' or '/points remove, whiteblXK, 500'")
        return true
    end
    
    local name, accountId = split[2], nil
    local resultId = db.storeQuery('SELECT `account_id` FROM `players` WHERE `name` = ' .. db.escapeString(name) .. ' LIMIT 1;')
    if resultId ~= false then
        accountId = result.getDataInt(resultId, "account_id")
        result.free(resultId)
    end

    if not accountId then
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, "Player with this name doesn't exsist.")
        return true
    end

    local points = split[3]
    if not points or not isNumber(points) then
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, "Missing ammount of points.")
        return true
    end
    
    local target = Player(name)
    command = command:lower()
    if command == "add" then
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("You have added %s premium points to %s.", points, name:firstToUpper()))
        if target ~= nil then
            doPlayerSendTextMessage(target, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("You have got %s premium points from %s.", points, player:getName()))
        end

        db.query("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. points .. " WHERE `id` = " .. accountId)
    elseif command == "remove" then
        local currentPoints = 0
        local resultId = db.storeQuery('SELECT `premium_points` FROM `accounts` WHERE `id` = ' .. accountId .. ' LIMIT 1;')
        if resultId ~= false then
            currentPoints = result.getDataInt(resultId, "premium_points")
            result.free(resultId)
        end

        local change = math.max(0, currentPoints - points)
        doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("You have removed %s premium points from %s.", change == 0 and "all" or points, name))
        if target ~= nil then
            doPlayerSendTextMessage(target, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("Your %s premium points has been removed by %s.", change == 0 and "all" or points, player:getName()))
        end

        db.query("UPDATE `accounts` SET `premium_points` = " .. change .. " WHERE `id` = " .. accountId)
    end
 
    return true
end
 
Solution

Shadowman321

Member
Joined
Mar 27, 2010
Messages
188
Reaction score
15
OP
OP
Lopaskurwa

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
782
Solutions
2
Reaction score
42
Guess you could try getplayerbyname?
it uses getplayerbyname already
Lua:
local player, balance, pid = getPlayerByName(t[1]), t[2], getPlayerByNameWildcard(t[1])
 

Shadowman321

Member
Joined
Mar 27, 2010
Messages
188
Reaction score
15
Oh, well, why do you need this pid anyway? Its not even used anywhere :D
Code:
local player, balance = getPlayerByName(t[1]), t[2])
This should be fine.

Not sure what the difference is between getPlayerByName and getPlayerByNameWildcard, as docs for tfs are ranging from non existing to poor scraps of some random functions :D
But from some samples, I guess you could ommit this whole pid var and use player instead, as it would probably give you the same results?
 
OP
OP
Lopaskurwa

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
782
Solutions
2
Reaction score
42
Oh, well, why do you need this pid anyway? Its not even used anywhere :D
Code:
local player, balance = getPlayerByName(t[1]), t[2])
This should be fine.

Not sure what the difference is between getPlayerByName and getPlayerByNameWildcard, as docs for tfs are ranging from non existing to poor scraps of some random functions :D
But from some samples, I guess you could ommit this whole pid var and use player instead, as it would probably give you the same results?
Now getting
attempt to call global getPlayerAccount (a nil value)
 
Top