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

Solved Problem with a Custom NPC Need Help ASAP

Tyson12302

New Member
Joined
Aug 6, 2014
Messages
264
Reaction score
4
I've made a donator NPC that lets you buy from the shop ingame rather than on the website. Heres the code
[12/06/2015 21:54:35] [Error - LuaScriptInterface::loadFile] data/npc/scripts/donations.lua:24: '}' expected (to close '{' at line 21) near '['
[12/06/2015 21:54:35] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/donations.lua
[12/06/2015 21:54:35] data/npc/scripts/donations.lua:24: '}' expected (to close '{' at line 21) near '['

Heres the code
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, xmsg = {}, {}

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 `points` from znote_accounts where name = \''..getPlayerAccount(cid)..'\'')
    if(res:getID() == -1) then
       return 0
    end
    local ret = res:getDataInt("points")
    res:free()
    return tonumber(ret)
end

local items = {
    ["Crystal Coin"] = {points = 10, itemid = 2160},  
    ["Soft Boots"] = {points = 20, itemid = 2640}
    ["Firewalker Boots"] = {points = 100, itemid = 9932}
    ["Demon Legs"] = {points = 15, itemid = 2495}
    ["Koshei's Ancient Amulet"] = {points = 30, itemid = 8266}
    ["Addon Doll"] = {points = 50, itemid = 8982}
    ["Power Sword"] = {points = 80, itemid = 2390}
    ["Stamina Doll"] = {points = 20, itemid = 9693}
}

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 x = items[msg:lower()]

    if msgcontains(msg, 'buy') then
        selfSay('Which donate item would you like to buy?', cid)
        talkState[talkUser] = 2
    elseif x and talkState[talkUser] >= 1 then
        selfSay('Do you want to buy 1 '..msg..' for '..x.points..' shop points?', cid)
        xmsg[cid] = msg
        talkState[talkUser] = 3
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
        x = items[xmsg[cid]:lower()]
        if getPremiumPoints(cid) >= x.points then
            selfSay('Here you are, have fun with it.', cid)
             doPlayerAddItem(cid, x.itemid, 1)
             db.executeQuery("UPDATE `znote_accounts` SET `points` = `points` + " .. points .. " where id = " .. getPlayerAccountId(cid) .. ";")
            talkState[talkUser] = 1
        else
            selfSay('You don\'t have enough points.', cid)
            talkState[talkUser] = 1
        end
    elseif msgcontains(msg, '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
    elseif talkState[talkUser] == 2 then
        selfSay('You can\'t buy this item from me, look in the {list} which items you can buy.', cid)
    else
        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())
 
Use the first version you posted and change
Code:
getPremiumPoints(cid)
To
Code:
getAccountPremiumPoints(cid)

And this
Code:
db.executeQuery("UPDATE `znote_accounts` SET `points` = `points` + " .. points .. " where id = " .. getPlayerAccountId(cid) .. ";")
To this.
Code:
doAccountAddPremiumPoints(cid, x.points)


You can remove the whole function getPremiumPoints(cid) from the script since you already have the right functions so you won't need it.
 
Last edited:
Back
Top