local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local amount = {}
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
npcHandler:addModule(FocusModule:new())
local function greetCallback(cid)
amount[cid] = nil
return true
end
local function isValidPointsAmount(points)
if isNumber(points) == TRUE and points > 0 and points < 999999999...
But thats the hardest partAdd this item, edit it to your requirements and make the npc sell this item.![]()
Premium points on Use
Hello, i was looking for a action script, on use x item, give x premium points, i tried this one but not working, also i tried to modifiy it but nthing! Im using TFS 1.1 https://otland.net/threads/onuse-item-add-x-points.170538/otland.net
First optionBut thats the hardest partto check how much he have x gold and send it x amount point i know how to check if he have 10gold and give 1k point if he does but then how to do calculations if he have like 60 gold or 500gold it should give 6k points or 50k points you know like automatic calculation. You know what i mean
First option is something that isnt advanced and is low level solution because he can have any amount of gold so imagine adding from 10gold to a like 10k gold in config, thats actually stupidFirst option
Create few items, one that gives 1000 points, one for 5000, one for 10000 etc and set adequate price at npc.
Second option
Make the npc ask how much gold player wants to exchange to points first. Save it in variable and check if player:removeMoney.
Have no idea about second option how to make it, thats what i asked in my post because i knew that you can make something like this, but have no clue and you posted exact same stuff i had in mind, not sure how it helped in any wayFirst option
Create few items, one that gives 1000 points, one for 5000, one for 10000 etc and set adequate price at npc.
Second option
Make the npc ask how much gold player wants to exchange to points first. Save it in variable and check if player:removeMoney.
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local amount = {}
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
npcHandler:addModule(FocusModule:new())
local function greetCallback(cid)
amount[cid] = nil
return true
end
local function isValidPointsAmount(points)
if isNumber(points) == TRUE and points > 0 and points < 999999999 then
return TRUE
end
return FALSE
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, 'premium points') then
if player:getLevel() < 150 then
npcHandler:say('You need 150 level to exchange gold for points.', cid)
npcHandler.topic[cid] = 0
end
if string.match(msg,'%d+') then
amount[cid] = math.max(1, getCount(msg))
if amount[cid] < 100 then
npcHandler:say('You cannot buy less than 100 premium points.', cid)
npcHandler.topic[cid] = 0
return false
end
npcHandler:say('Would you like to buy ' .. amount[cid] .. ' premium points for ' .. amount[cid] / 10 .. ' gold coins?', cid)
npcHandler.topic[cid] = 2
return true
else
npcHandler:say('Please tell me how many premium points you would like to buy.', cid)
npcHandler.topic[cid] = 1
return true
end
elseif npcHandler.topic[cid] == 1 then
amount[cid] = math.max(1, getCount(msg))
if amount[cid] < 100 then
npcHandler:say('You cannot buy less than 100 premium points.', cid)
npcHandler.topic[cid] = 0
return false
end
if isValidPointsAmount(amount[cid]) then
npcHandler:say('Would you like to buy ' .. amount[cid] .. ' premium points for ' .. amount[cid] / 10 .. ' gold coins?', cid)
npcHandler.topic[cid] = 2
return true
end
elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 2 then
if player:getMoney() >= tonumber(amount[cid] / 10) then
player:removeMoney(amount[cid] / 10)
db.query('UPDATE accounts SET premium_points = premium_points+'.. amount[cid] ..' WHERE id = ' .. getAccountNumberByPlayerName(getCreatureName(cid)))
npcHandler:say('Alright, I have added the amount of ' .. amount[cid] .. ' premium points to your account.', cid)
else
npcHandler:say('You do not have enough gold.', cid)
end
npcHandler.topic[cid] = 0
end
end
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
LUA:local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local amount = {} 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 npcHandler:addModule(FocusModule:new()) local function greetCallback(cid) amount[cid] = nil return true end local function isValidPointsAmount(points) if isNumber(points) == TRUE and points > 0 and points < 999999999 then return TRUE end return FALSE end local function creatureSayCallback(cid, type, msg) if not npcHandler:isFocused(cid) then return false end local player = Player(cid) if msgcontains(msg, 'premium points') then if player:getLevel() < 150 then npcHandler:say('You need 150 level to exchange gold for points.', cid) npcHandler.topic[cid] = 0 end if string.match(msg,'%d+') then amount[cid] = math.max(1, getCount(msg)) if amount[cid] < 100 then npcHandler:say('You cannot buy less than 100 premium points.', cid) npcHandler.topic[cid] = 0 return false end npcHandler:say('Would you like to buy ' .. amount[cid] .. ' premium points for ' .. amount[cid] / 10 .. ' gold coins?', cid) npcHandler.topic[cid] = 2 return true else npcHandler:say('Please tell me how many premium points you would like to buy.', cid) npcHandler.topic[cid] = 1 return true end elseif npcHandler.topic[cid] == 1 then amount[cid] = math.max(1, getCount(msg)) if amount[cid] < 100 then npcHandler:say('You cannot buy less than 100 premium points.', cid) npcHandler.topic[cid] = 0 return false end if isValidPointsAmount(amount[cid]) then npcHandler:say('Would you like to buy ' .. amount[cid] .. ' premium points for ' .. amount[cid] / 10 .. ' gold coins?', cid) npcHandler.topic[cid] = 2 return true end elseif msgcontains(msg, 'yes') then if npcHandler.topic[cid] == 2 then if msgcontains(msg, 'yes') then if player:getMoney() >= tonumber(amount[cid] / 10) then player:removeMoney(amount[cid] / 10) db.query('UPDATE accounts SET premium_points = premium_points+'.. amount[cid] ..' WHERE id = ' .. getAccountNumberByPlayerName(getCreatureName(cid))) npcHandler:say('Alright, I have added the amount of ' .. amount[cid] .. ' premium points to your account.', cid) else npcHandler:say('You do not have enough gold.', cid) end npcHandler.topic[cid] = 0 end end end end npcHandler:setCallback(CALLBACK_GREET, greetCallback) npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
Here you are. Tested on 1.x.
Not really because probably later i will edit this code for premium days too not only for premium points so then this code wont be that customizableDoes the player have to do 10 gold increments? Can the player do like 15 gold for 1500 points?
Thought that isNumber function is by default on TFS 1.x (I might be wrong as I have tested in on some datapack I had on my machine), just add it somewhere in your global.lua or to your NPC file.![]()
Gyazo
gyazo.com
function isNumber(str)
return tonumber(str) ~= nil
end
Your code could have been more advanced with local configThought that isNumber function is by default on TFS 1.x (I might be wrong as I have tested in on some datapack I had on my machine), just add it somewhere in your global.lua or to your NPC file.
LUA:function isNumber(str) return tonumber(str) ~= nil end
Note, in this code 100 premium points equals 10 gold coins and so on, just as you asked in this thread but it's super easy to modify it as you wish in the future.
Your code could have been more advanced with local configBut w/e. Btw cant figure out how to make 1 premium point = 1000 gold. What i get is 0.001 gold value
![]()
I have made exactly what you have asked, 10 gold for 1000 points and so on what kind of more advanced local config you want? Anyway I have added one more config value which is premiumPointsPrice (cost of one premium point)Tfs 1.x
Need npc that trades 10gold to 1000 premium points so if you have like 40gold you would get 4000 premium points and etc. And level requirement min 150lvl
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local amount = {}
local premiumPointsPrice = 10 -- cost of one premium point
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
npcHandler:addModule(FocusModule:new())
local function greetCallback(cid)
amount[cid] = nil
return true
end
local function isValidPointsAmount(points)
if isNumber(points) == TRUE and points > 0 and points < 999999999 then
return TRUE
end
return FALSE
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, 'premium points') then
if player:getLevel() < 150 then
npcHandler:say('You need 150 level to exchange gold for points.', cid)
npcHandler.topic[cid] = 0
end
if string.match(msg,'%d+') then
amount[cid] = math.max(1, getCount(msg))
if amount[cid] < 100 then
npcHandler:say('You cannot buy less than 100 premium points.', cid)
npcHandler.topic[cid] = 0
return false
end
npcHandler:say('Would you like to buy ' .. amount[cid] .. ' premium points for ' .. amount[cid] * premiumPointsPrice .. ' gold coins?', cid)
npcHandler.topic[cid] = 2
return true
else
npcHandler:say('Please tell me how many premium points you would like to buy.', cid)
npcHandler.topic[cid] = 1
return true
end
elseif npcHandler.topic[cid] == 1 then
amount[cid] = math.max(1, getCount(msg))
if amount[cid] < 100 then
npcHandler:say('You cannot buy less than 100 premium points.', cid)
npcHandler.topic[cid] = 0
return false
end
if isValidPointsAmount(amount[cid]) then
npcHandler:say('Would you like to buy ' .. amount[cid] .. ' premium points for ' .. amount[cid] * premiumPointsPrice .. ' gold coins?', cid)
npcHandler.topic[cid] = 2
return true
end
elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 2 then
if player:getMoney() >= tonumber(amount[cid] * premiumPointsPrice) then
player:removeMoney(amount[cid] * premiumPointsPrice)
db.query('UPDATE accounts SET premium_points = premium_points+'.. amount[cid] ..' WHERE id = ' .. getAccountNumberByPlayerName(getCreatureName(cid)))
npcHandler:say('Alright, I have added the amount of ' .. amount[cid] .. ' premium points to your account.', cid)
else
npcHandler:say('You do not have enough gold.', cid)
end
npcHandler.topic[cid] = 0
end
end
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)