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

[REQUEST] NPC Premium

f@bio

Fudera Otserver
Joined
Jul 10, 2007
Messages
213
Reaction score
0
Location
Brasil
Hello friends, I would like someone postasse an NPC that sells PA, as the command! Buypremium, is not accepted by the players, and the NPC would be a great option to sell days of PA, please help me ...

F @ bio
 
Not tested, if you found any bugs, post here:
Code:
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

local function getCount(msg)
    local ret = -1
    local b, e = string.find(msg, "%d+")
    if b ~= nil and e ~= nil then
        ret = tonumber(string.sub(msg, b, e))
    end
    return ret
end

function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end

    local count = (getCount(msg))
    local premium_day_price = 1000 -- price of each day of premium account (in gold coins)

    if msgcontains(msg, 'premium') or msgcontains(msg, 'premmy') then
        talk_state = 1
        selfSay("How much premium days you want to buy?")
    
    elseif isNumber(getCount(msg)) == TRUE and talk_state == 1 then
        talk_state = 2
        premium_days = count
        cost = math.floor(premium_days * premium_day_price)
        selfSay("Do you want to buy "..premium_days.." premium account days for "..cost.." gold coins?")
        
    elseif msgcontains(msg, 'yes') and talk_state == 2 then
        talk_state = 0
        if doPlayerRemoveMoney(cid, cost) == TRUE then
            doPlayerAddPremiumDays(cid, premium_days)
            selfSay("You have successfully bought "..premium_days.." premium account days for "..cost.." gold coins.")
        else
                selfSay("Sorry, you do not have enough money.")
        end

    elseif msgcontains(msg, 'no') and talk_state == 2 then
        selfSay('Then not.')
        talk_state = 0
    end
    return true
end

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