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

NPC [1.X] Change tokens for points or points for tokens! working with Gesior and Znote

Marko999x

999x era
Premium User
Joined
Dec 14, 2017
Messages
2,816
Solutions
82
Reaction score
1,938
Location
Germany
Add this to global lua

If you using znote:
Lua:
function Player.getZnotePoints(self)
    local query = db.storeQuery("SELECT `points` FROM `znote_accounts` WHERE `id` = " .. self:getAccountId())
    if not query then
        return false
    end

    local value = result.getNumber(query, "points")
    result.free(query)
    return value
end

If you using gesior:
Lua:
function Player.getPremiumPoints(self)
    local query = db.storeQuery("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. self:getAccountId())
    if not query then
        return false
    end

    local value = result.getNumber(query, "premium_points")
    result.free(query)
    return value
end

Npc XML file:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="yourName" script="yourName.lua" walkinterval="0" floorchange="0" speechbubble="1">
    <health now="100" max="100" />
    <look type="289" head="0" body="0" legs="0" feet="0" addons="2" mount="401" />
    <parameters>
        <parameter key="message_greet" value="Hi |PLAYERNAME|!, do you want to {change token} for premium points? or do you want to {change premium} for tokens?" />
        <parameter key="message_walkaway" value="Come back soon!" />
        <parameter key="message_farewell" value="Come back soon!" />
    </parameters>
</npc>

Lua file:
Lua:
local talkState = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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



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 item = 6527
    local player = Player(cid)
    local accountId = player:getAccountId()
    local points = 5
  
    if(msgcontains(msg, 'change token')) then
        if player:getItemCount(item) >= 1 then
            selfSay('you want to change tokens for premium points?.', cid)
            talkState[talkUser] = 1
        else
            selfSay('you dont have any tokens.', cid)
            talkState[talkUser] = 0
        end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
            if not player:removeItem(item, 1) then
                selfSay('Your token must be gone, come back when you found it.', cid)
                talkState[talkUser] = 0
                return true
            end       
            db.query("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. points .. " WHERE `id` = " .. accountId) -- For gesior user
        --    db.query("UPDATE znote_accounts SET points = points + " .. points .. " WHERE account_id = " .. accountId) -- For znote user
            selfSay('You have successful changed 1 token for 5 points.', cid)
            talkState[talkUser] = 0
            player:save()
        end
        if(msgcontains(msg, 'change premium')) then
            selfSay('you sure you want to buy a token for premium points?.', cid)
            talkState[talkUser] = 2
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
            if player:getPremiumPoints() <= points then -- For gesior user
            --if player:getZnotePoints() <= points then -- For znote user
               selfSay('You dont have enough points.', cid)
               return true
            end
            db.query("UPDATE `accounts` SET `premium_points` = `premium_points` - " .. points .. " WHERE `id` = " .. accountId) -- For gesior user
        --    db.query("UPDATE znote_accounts SET points = points - " .. points .. " WHERE account_id = " .. accountId) -- For znote user
            player:addItem(item, 1)
            talkState[talkUser] = 0
            selfSay('You have successful changed 5 premium points for 1 token.', cid)
            player:save()
        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

In the lua file you can edit it if you want it for gesior or znote
 
Sup @Levi999x not sure why I tested this NPC so lately, but I noticed that you can't set the amount of points you want to convert. It only allows to change 1 point into 1 token. How can I ask to the NPC for 28 tokens at once for example? (Hi, change token, 28, yes)

Thanks again for the script,
Regards!
 
Great script, but I encountered an error. I use it together with ZnoteACC, when you exchange online points for in-game chips, there are no limits, even the character with 0 points the npc keeps changing balance and leaving the online points in negative.
Add this to global lua

If you using znote:
Lua:
function Player.getZnotePoints(self)
    local query = db.storeQuery("SELECT `points` FROM `znote_accounts` WHERE `id` = " .. self:getAccountId())
    if not query then
        return false
    end

    local value = result.getNumber(query, "points")
    result.free(query)
    return value
end

If you using gesior:
Lua:
function Player.getPremiumPoints(self)
    local query = db.storeQuery("SELECT `premium_points` FROM `accounts` WHERE `id` = " .. self:getAccountId())
    if not query then
        return false
    end

    local value = result.getNumber(query, "premium_points")
    result.free(query)
    return value
end

Npc XML file:
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="yourName" script="yourName.lua" walkinterval="0" floorchange="0" speechbubble="1">
    <health now="100" max="100" />
    <look type="289" head="0" body="0" legs="0" feet="0" addons="2" mount="401" />
    <parameters>
        <parameter key="message_greet" value="Hi |PLAYERNAME|!, do you want to {change token} for premium points? or do you want to {change premium} for tokens?" />
        <parameter key="message_walkaway" value="Come back soon!" />
        <parameter key="message_farewell" value="Come back soon!" />
    </parameters>
</npc>

Lua file:
Lua:
local talkState = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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



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 item = 6527
    local player = Player(cid)
    local accountId = player:getAccountId()
    local points = 5
 
    if(msgcontains(msg, 'change token')) then
        if player:getItemCount(item) >= 1 then
            selfSay('you want to change tokens for premium points?.', cid)
            talkState[talkUser] = 1
        else
            selfSay('you dont have any tokens.', cid)
            talkState[talkUser] = 0
        end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
            if not player:removeItem(item, 1) then
                selfSay('Your token must be gone, come back when you found it.', cid)
                talkState[talkUser] = 0
                return true
            end      
            db.query("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. points .. " WHERE `id` = " .. accountId) -- For gesior user
        --    db.query("UPDATE znote_accounts SET points = points + " .. points .. " WHERE account_id = " .. accountId) -- For znote user
            selfSay('You have successful changed 1 token for 5 points.', cid)
            talkState[talkUser] = 0
            player:save()
        end
        if(msgcontains(msg, 'change premium')) then
            selfSay('you sure you want to buy a token for premium points?.', cid)
            talkState[talkUser] = 2
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
            if player:getPremiumPoints() <= points then -- For gesior user
            --if player:getZnotePoints() <= points then -- For znote user
               selfSay('You dont have enough points.', cid)
               return true
            end
            db.query("UPDATE `accounts` SET `premium_points` = `premium_points` - " .. points .. " WHERE `id` = " .. accountId) -- For gesior user
        --    db.query("UPDATE znote_accounts SET points = points - " .. points .. " WHERE account_id = " .. accountId) -- For znote user
            player:addItem(item, 1)
            talkState[talkUser] = 0
            selfSay('You have successful changed 5 premium points for 1 token.', cid)
            player:save()
        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

In the lua file you can edit it if you want it for gesior or znote
 
Great script, but I encountered an error. I use it together with ZnoteACC, when you exchange online points for in-game chips, there are no limits, even the character with 0 points the npc keeps changing balance and leaving the online points in negative.

Not sure if this will work for you, but this is the NPC that i'm actually using for change :)
Lua:
local talkState = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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



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 item = 12752
    local player = Player(cid)
    local accountId = player:getAccountId()
    local points = 1
    local pointsecond = 10
    local pointhundred = 100
  
    if(msgcontains(msg, 'change currency')) then
        if player:getItemCount(item) >= 1 then
            selfSay('You want to change currency for premium points?', cid)
            talkState[talkUser] = 1
        else
            selfSay('You dont have any currency.', cid)
            talkState[talkUser] = 0
        end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
            if not player:removeItem(item, 1) then
                selfSay('Your currency must be gone, come back when you found it.', cid)
                talkState[talkUser] = 0
                return true
            end       
            db.query("UPDATE znote_accounts SET points = points + " .. points .. " WHERE account_id = " .. accountId)
            selfSay('You have successful changed 1 greed currency for 1 points.', cid)
            talkState[talkUser] = 0
            player:save()
        end
           if(msgcontains(msg, 'change 10 currency')) then
        if player:getItemCount(item) >= 10 then
            selfSay('You want to change 10 currency for 10 premium points?', cid)
            talkState[talkUser] = 4
        else
            selfSay('You don\'t have 10 currency.', cid)
            talkState[talkUser] = 0
        end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 4) then
            if not player:removeItem(item, 10) then
                selfSay('Your currency must be gone, come back when you found it.', cid)
                talkState[talkUser] = 0
                return true
            end       
            db.query("UPDATE znote_accounts SET points = points + " .. pointsecond .. " WHERE account_id = " .. accountId)
            selfSay('You have successful changed 10 greed currency for 10 points.', cid)
            talkState[talkUser] = 0
            player:save()
        end
                   if(msgcontains(msg, 'change 100 currency')) then
        if player:getItemCount(item) >= 10 then
            selfSay('You want to change 100 currency for 100 premium points?', cid)
            talkState[talkUser] = 6
        else
            selfSay('You don\'t have 100 currency.', cid)
            talkState[talkUser] = 0
        end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 6) then
            if not player:removeItem(item, 100) then
                selfSay('Your currency must be gone, come back when you found it.', cid)
                talkState[talkUser] = 0
                return true
            end       
            db.query("UPDATE znote_accounts SET points = points + " .. pointhundred .. " WHERE account_id = " .. accountId)
            selfSay('You have successful changed 100 greed currency for 100 points.', cid)
            talkState[talkUser] = 0
            player:save()
        end
        if(msgcontains(msg, 'change premium')) then
            selfSay('You sure you want to buy greed currency for premium points?', cid)
            talkState[talkUser] = 2
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
            if player:getZnotePoints() <= points then
               selfSay('You dont have enough points.', cid)
               return true
            end
            db.query("UPDATE znote_accounts SET points = points - " .. points .. " WHERE account_id = " .. accountId)
            player:addItem(item, 1)
            talkState[talkUser] = 0
            selfSay('You have successful changed 1 premium points for 1 greed currency.', cid)
            player:save()
        end
        if(msgcontains(msg, 'change 10 premium')) then
            selfSay('You sure you want to buy 10 greed currency for 10 premium points?', cid)
            talkState[talkUser] = 3
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
            if player:getZnotePoints() <= pointsecond then
               selfSay('You dont have enough points.', cid)
               return true
            end
            db.query("UPDATE znote_accounts SET points = points - " .. pointsecond .. " WHERE account_id = " .. accountId)
            player:addItem(item, 10)
            talkState[talkUser] = 0
            selfSay('You have successful changed 10 premium points for 10 greed currency.', cid)
            player:save()
        end
        if(msgcontains(msg, 'change 100 premium')) then
            selfSay('You sure you want to buy 100 greed currency for 100 premium points?', cid)
            talkState[talkUser] = 5
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 5) then
            if player:getZnotePoints() <= pointhundred then
               selfSay('You dont have enough points.', cid)
               return true
            end
            db.query("UPDATE znote_accounts SET points = points - " .. pointhundred .. " WHERE account_id = " .. accountId)
            player:addItem(item, 100)
            talkState[talkUser] = 0
            selfSay('You have successful changed 100 premium points for 100 greed currency.', cid)
            player:save()
        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Not sure if this will work for you, but this is the NPC that i'm actually using for change :)
Lua:
local talkState = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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



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 item = 12752
    local player = Player(cid)
    local accountId = player:getAccountId()
    local points = 1
    local pointsecond = 10
    local pointhundred = 100
 
    if(msgcontains(msg, 'change currency')) then
        if player:getItemCount(item) >= 1 then
            selfSay('You want to change currency for premium points?', cid)
            talkState[talkUser] = 1
        else
            selfSay('You dont have any currency.', cid)
            talkState[talkUser] = 0
        end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
            if not player:removeItem(item, 1) then
                selfSay('Your currency must be gone, come back when you found it.', cid)
                talkState[talkUser] = 0
                return true
            end      
            db.query("UPDATE znote_accounts SET points = points + " .. points .. " WHERE account_id = " .. accountId)
            selfSay('You have successful changed 1 greed currency for 1 points.', cid)
            talkState[talkUser] = 0
            player:save()
        end
           if(msgcontains(msg, 'change 10 currency')) then
        if player:getItemCount(item) >= 10 then
            selfSay('You want to change 10 currency for 10 premium points?', cid)
            talkState[talkUser] = 4
        else
            selfSay('You don\'t have 10 currency.', cid)
            talkState[talkUser] = 0
        end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 4) then
            if not player:removeItem(item, 10) then
                selfSay('Your currency must be gone, come back when you found it.', cid)
                talkState[talkUser] = 0
                return true
            end      
            db.query("UPDATE znote_accounts SET points = points + " .. pointsecond .. " WHERE account_id = " .. accountId)
            selfSay('You have successful changed 10 greed currency for 10 points.', cid)
            talkState[talkUser] = 0
            player:save()
        end
                   if(msgcontains(msg, 'change 100 currency')) then
        if player:getItemCount(item) >= 10 then
            selfSay('You want to change 100 currency for 100 premium points?', cid)
            talkState[talkUser] = 6
        else
            selfSay('You don\'t have 100 currency.', cid)
            talkState[talkUser] = 0
        end
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 6) then
            if not player:removeItem(item, 100) then
                selfSay('Your currency must be gone, come back when you found it.', cid)
                talkState[talkUser] = 0
                return true
            end      
            db.query("UPDATE znote_accounts SET points = points + " .. pointhundred .. " WHERE account_id = " .. accountId)
            selfSay('You have successful changed 100 greed currency for 100 points.', cid)
            talkState[talkUser] = 0
            player:save()
        end
        if(msgcontains(msg, 'change premium')) then
            selfSay('You sure you want to buy greed currency for premium points?', cid)
            talkState[talkUser] = 2
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
            if player:getZnotePoints() <= points then
               selfSay('You dont have enough points.', cid)
               return true
            end
            db.query("UPDATE znote_accounts SET points = points - " .. points .. " WHERE account_id = " .. accountId)
            player:addItem(item, 1)
            talkState[talkUser] = 0
            selfSay('You have successful changed 1 premium points for 1 greed currency.', cid)
            player:save()
        end
        if(msgcontains(msg, 'change 10 premium')) then
            selfSay('You sure you want to buy 10 greed currency for 10 premium points?', cid)
            talkState[talkUser] = 3
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
            if player:getZnotePoints() <= pointsecond then
               selfSay('You dont have enough points.', cid)
               return true
            end
            db.query("UPDATE znote_accounts SET points = points - " .. pointsecond .. " WHERE account_id = " .. accountId)
            player:addItem(item, 10)
            talkState[talkUser] = 0
            selfSay('You have successful changed 10 premium points for 10 greed currency.', cid)
            player:save()
        end
        if(msgcontains(msg, 'change 100 premium')) then
            selfSay('You sure you want to buy 100 greed currency for 100 premium points?', cid)
            talkState[talkUser] = 5
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 5) then
            if player:getZnotePoints() <= pointhundred then
               selfSay('You dont have enough points.', cid)
               return true
            end
            db.query("UPDATE znote_accounts SET points = points - " .. pointhundred .. " WHERE account_id = " .. accountId)
            player:addItem(item, 100)
            talkState[talkUser] = 0
            selfSay('You have successful changed 100 premium points for 100 greed currency.', cid)
            player:save()
        end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Hello friend, thanks for sharing, but I found a solution a little more viable, even to avoid problems, I only left the function of exchanging the chips for points online on the site, if anyone wants the chips in the game, just buy them at the same website.
 
Back
Top