Add this to global lua
If you using znote:
If you using gesior:
Npc XML file:
Lua file:
In the lua file you can edit it if you want it for gesior or znote
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