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

Lua [TFS 1.4.1] Premium Points Marketplace (MODAL or NPC)

Adorius Black

Advanced OT User
Joined
Mar 31, 2020
Messages
321
Solutions
3
Reaction score
194
Hello! I would like to ask if anyone has a simple script that, for example, opens a modal window after using an item, where items are available for sale for premium points. Alternatively, an NPC that sells items for premium points. Thank you. TFS 1.4.1
 
Solution
I found this NPC that, when you talk to it, a window appears showing items being sold for VIP coins. However, you can modify it to sell items using only premium points. It's easy! If you're using the Gesior website, just look for a few lines, replace the NPC's VIP coin ID, and make some adjustments to make it work perfectly.


I solved it and quickly adapted it into a very simple NPC this way

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
local shopWindow = {}

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function...
I found this NPC that, when you talk to it, a window appears showing items being sold for VIP coins. However, you can modify it to sell items using only premium points. It's easy! If you're using the Gesior website, just look for a few lines, replace the NPC's VIP coin ID, and make some adjustments to make it work perfectly.


I solved it and quickly adapted it into a very simple NPC this way

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
local shopWindow = {}

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

local function removePoints(player, amount)
    if not player then return false end
    local accountId = player:getAccountId()
    return db.query(string.format("UPDATE `accounts` SET `premium_points` = GREATEST(0, `premium_points` - %d) WHERE `id` = %d", amount, accountId))
end

local function getPoints(player)
    if not player then return 0 end
    local accountId = player:getAccountId()
    local resultId = db.storeQuery(string.format("SELECT `premium_points` FROM `accounts` WHERE `id` = %d", accountId))
    
    if resultId then
        local points = result.getDataInt(resultId, "premium_points")
        result.free(resultId)
        return points
    end
    return 0
end

-- Items available for purchase with their premium points cost
local t = {
    [12396] = {price = 400},
    [12575] = {price = 400},
    [7440]  = {price = 200},
    [7443]  = {price = 400},
    [8981]  = {price = 600},
    [5468]  = {price = 250},
    [2346]  = {price = 200}
}

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    local player = Player(cid)
    if not player then return false end

    if not t[item] then
        selfSay("Sorry, I don't sell this item.", cid)
        return false
    end

    local totalCost = t[item].price * amount
    local playerPoints = getPoints(player)

    if playerPoints >= totalCost then
        if removePoints(player, totalCost) then
            if player:addItem(item, amount) then
                selfSay("Here is your item!", cid)
            else
                selfSay("Sorry, you don't have enough space in your inventory.", cid)
                return false
            end
        end
    else
        selfSay(string.format("You don't have enough premium points. You need %d premium points.", totalCost), cid)
        return false
    end
    return true
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
    local shopWindow = {}

    msg = msg:lower()

    if (msgcontains(msg, 'trade') or msgcontains(msg, 'troca')) then
        for itemId, itemInfo in pairs(t) do
            local itemType = ItemType(itemId)
            local itemName = itemType:getName()
            table.insert(shopWindow, {
                id = itemId,
                subType = 0,
                buy = itemInfo.price,
                sell = 0,
                name = itemName
            })
        end
        openShopWindow(cid, shopWindow, onBuy, function() end)
    elseif (msgcontains(msg, 'balance') or msgcontains(msg, 'points') or msgcontains(msg, 'saldo')) then
        local player = Player(cid)
        if player then
            local playerPoints = getPoints(player)
            selfSay(string.format("You currently have %d premium points.", playerPoints), cid)
        end
    else
        selfSay("I don't understand. Say 'trade' to see available items or 'balance' to check your premium points.", cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Solution
Back
Top