Tjockis
New Member
- Joined
- Jun 5, 2013
- Messages
- 44
- Reaction score
- 2
So my donation NPC that will sel Don items for premium points will not wok.
I can talk to him and se the list of items he sells and so, but when I try to buy a item he tells me that i dont have premium points to buy it but I have premium points at the website .
No erros or somthing like that
Script
Rep++
Tnx Tjockis.
I can talk to him and se the list of items he sells and so, but when I try to buy a item he tells me that i dont have premium points to buy it but I have premium points at the website .
No erros or somthing like that
Script
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Donation Shop" script="donations.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="130" head="114" body="113" legs="114" feet="114" addons="3"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|, You can {buy} items from me for premium points. You can see in the {list} which items you can buy."/>
</parameters>
</npc>
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 getPremiumPoints(cid)
local res = db.getResult('select `premium_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
if(res:getID() == -1) then
return 0
end
local ret = res:getDataInt("premium_points")
res:free()
return tonumber(ret)
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 items = {
["Thaian Sword"] = {points = 100, itemid = 7391},
["Golden Helmet"] = {points = 100, itemid = 2471}
}
local function addCptl(first, rest)
return first:upper()..rest:lower()
end
local x = items[msg:gsub("(%a)([%w_']*)", addCptl)]
local buy = (msgcontains(msg, 'buy'))
if buy then
selfSay('Which donate item would you like to buy?', cid)
talkState[talkUser] = 2
end
if x and talkState[talkUser] >= 1 then
selfSay('Do you want to buy 1 '..msg..' for '..x.points..' premium points?', cid)
xmsg = msg
talkState[talkUser] = 3
end
local agree = (msgcontains(msg, 'yes'))
if agree and talkState[talkUser] == 3 then
x = items[xmsg:gsub("(%a)([%w_']*)", addCptl)]
if getPremiumPoints(cid) >= x.points then
selfSay('Here you are, have fun with it.', cid)
doPlayerAddItem(cid, x.itemid, 1)
db.executeQuery('UPDATE accounts SET premium_points=premium_points-'..x.points..' WHERE id=' .. getPlayerAccountId(cid))
talkState[talkUser] = 1
else
selfSay('You don\'t have enough points.', cid)
talkState[talkUser] = 1
end
end
local list = (msgcontains(msg, 'list'))
if list then
text = 'Donation Items\n'
for i, x in pairs(items) do
text = text .. "\n" .. i .. " - "..x.points.." points"
end
doShowTextDialog(cid, 7391, "" .. text)
talkState[talkUser] = 1
end
if not x and not list and not buy and not agree and talkState[talkUser] == 2 then
selfSay('You can\'t buy this item from me, look in the {list} which items you can buy.', cid)
elseif not x and not list and not buy and not agree and talkState[talkUser] ~= 2 then
selfSay('What? I don\'t understand what you mean with '..msg..'.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Rep++
Tnx Tjockis.