NPC [OTX 2.9] NPC that buys loot - please help!

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
Hello!

I'm working on a 7.6 server using OTX 2.9, I've been trying to add loot NPC, but none have worked. I have an NPC that sells amulet of loss and some rings, I'll post the script below. Could someone please help me modify it so instead of selling stuff, it buys them? I just need the function with one item, I'll add the rest of them. I try to edit it but it didn't work, I would really appreciate it!

Lua:
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
 

    
    --------- AMULETS and RINGS ---------
     if msgcontains(msg, 'rings') then
        npcHandler:say('I sell Energy Ring, Life Ring, and Ring of Healing.')
         talk_start = 1
     end

     if msgcontains(msg, 'aol') then
    item = 2173
    price = 10000
    npcHandler:say('Do you want to buy an Amulet of Loss for 1 crystal coin?')
     talk_start = 1
     end
    
    if msgcontains(msg, 'energy ring') then
    item = 2167
    price = 2000
    npcHandler:say('Do you want to buy a Energy Ring for 20 platinum coins?')
     talk_start = 1
     end

     if msgcontains(msg, 'life ring') then
    item = 2205
    price = 2500
    npcHandler:say('Do you want to buy a Life Ring for 25 platinum coins?')
     talk_start = 1
     end

    if msgcontains(msg, 'ring of healing') then
    item = 2214
    price = 5000
    npcHandler:say('Do you want to buy a Ring of Healing for 50 platinum coins?')
     talk_start = 1
     end


    if msgcontains(msg, 'yes') and getPlayerMoney(cid) >= price then
    npcHandler:say('Here you go!')
    doPlayerAddItem(cid, item, 1)
    doPlayerRemoveMoney(cid, price)
    talk_start = 0
    
    elseif msgcontains(msg, 'yes') and getPlayerMoney(cid) < price then
    npcHandler:say('You don\'t have enough money.')
    talk_start = 0
    end
    
    if msgcontains(msg, 'no') and talk_start == 1 then
    npcHandler:say('Okay, let me know if you would like to buy something else.')
    talk_start = 0
    end
    
 return TRUE
end

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

ralke

Felipe
Joined
Dec 17, 2011
Messages
270
Reaction score
32
Location
Chile
Try changing line 54
Lua:
doPlayerAddItem(cid, item, 1)
doPlayerRemoveMoney(cid, price)
for
Lua:
doPlayerRemoveItem(cid,item,1)
doPlayerAddMoney(cid, money)
hope it works!!
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
Try changing line 54
Lua:
doPlayerAddItem(cid, item, 1)
doPlayerRemoveMoney(cid, price)
for
Lua:
doPlayerRemoveItem(cid,item,1)
doPlayerAddMoney(cid, money)
hope it works!!
Hello ralke!

Unfortunately, it did not work. However, there's a bit of progress now I think. I added "brass armor" as an option to sell and this is what happens...
  1. If I say "brass armor" and I do not have at least 1 cyrstal coin, it says "You don't have enough money.".
  2. If I say "brass armor" and I have 1 or more crystal coins, it takes the armor but I do not get any money.
  3. If I say "brass armor" and I have 1 or more crystal coins, but I do not have a brass armor, it says "Here you go!" as if I actually had one.
Any idea?
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
Update: I've made some research on my own and started to play a little with the script. Using a brass armor as a test, I managed to make the NPC take the armor from me, and add the money (1 crystal coin). The problem now is that even if I don't have the armor, it still gives me 1cc. Here's the code:

Lua:
if msgcontains(msg, 'brass armor') and getPlayerItemCount(cid, 2465) then
    npcHandler:say('Here you go!')
    doPlayerRemoveItem(cid, 2465, 1)
    doPlayerAddItem(cid, 2160, 1)
    talk_start = 0
   
    elseif msgcontains(msg, 'brass armor') and not getPlayerItemCount(cid, 2465) then
    npcHandler:say('Sorry, you do not have that item.')
    talk_start = 0
    end
Can someone help me fix the "elseif" function, please?
 

ralke

Felipe
Joined
Dec 17, 2011
Messages
270
Reaction score
32
Location
Chile
Try changing elseif for else

Example:
Lua:
if msgcontains(msg, 'brass armor') then
            if getPlayerItemCount(cid,2465) >= 1 then
                selfSay('Did you bring me a brass armor?', cid)
                talk_state = 1
            else
                selfSay('I need a brass armor to give you a crystal coin. Come back when you have them.', cid)
                talk_state = 0
            end

            elseif msgcontains(msg, 'yes') and talk_state == 1 then
            talk_state = 0
            if getPlayerItemCount(cid,2465) >= 1 then
            if doPlayerRemoveItem(cid,2465, 10) == TRUE then
                            selfSay(done, cid)
            doPlayerAddItem(cid, 2160, 1)
            end
            else
                selfSay(item, cid)
            end
Check this maybe will be helpfull


Hope this helps!
Regards
 

mdwilliams

(Michael)
Premium User
Joined
Nov 15, 2007
Messages
623
Reaction score
125
Location
Western Australia
Isn't OTX just like TFS 1.x?
Can't you just use the standard shop modules?
In npc/lib/npcsystem/modules.lua you might need to force SHOPMODULE_MODE = SHOPMODULE_MODE_TALK

I snagged this NPC from here: mattyx14/otxserver (https://github.com/mattyx14/otxserver/tree/otxv2_12/path_7_x/data/npc)

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Britany" nameDescription="Britany, the arms buyer" script="lot.lua" walkinterval="2000" skull="green" floorchange="0">
    <health now="150" max="150"/>
    <look type="139" head="114" body="94" legs="19" feet="0" corpse="2212"/>
    <parameters>
        <parameter key="module_shop" value="1"/>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. I buy swords, clubs, axes, helmets, boots, legs, shields and armors."/>
    </parameters>
    <voices>
        <voice text="Come and sell your items very expensive price..." interval2="60" margin="1" type="16" yell="no"/>
        <voice text="There are some geniuses who valued your items to a much higher price..." interval2="120" margin="1" type="16" yell="no"/>
    </voices>
</npc>
Lua:
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
function onPlayerEndTrade(cid)                npcHandler:onPlayerEndTrade(cid)            end
function onPlayerCloseChannel(cid)            npcHandler:onPlayerCloseChannel(cid)        end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

-- Seller Objets
-- Helmets
shopModule:addSellableItem({'steel helmet'}, 2457, 200, 'steel helmet')
shopModule:addSellableItem({'devil helmet'}, 2462, 5000, 'devil helmet')
shopModule:addSellableItem({'warrior helmet'}, 2475, 7000, 'warrior helmet')
shopModule:addSellableItem({'dark helmet'}, 2490, 250, 'dark helmet')
shopModule:addSellableItem({'crown helmet'}, 2491, 7500, 'crown helmet')
shopModule:addSellableItem({'crusader helmet'}, 2497, 7600, 'crusader helmet')
shopModule:addSellableItem({'beholder helmet'}, 3972, 7500, 'beholder helmet')
shopModule:addSellableItem({'helmet of the ancients'}, 2342, 12700, 'helmet of the ancients')
shopModule:addSellableItem({'royal helmet'}, 2498, 34500, 'royal helmet')
shopModule:addSellableItem({'amazon helmet'}, 2499, 112500, 'amazon helmet')
shopModule:addSellableItem({'dragon scale helmet'}, 2506, 115000, 'dragon scale helmet')
shopModule:addSellableItem({'golden helmet'}, 2471, 188000, 'golden helmet')
shopModule:addSellableItem({'winged helmet'}, 2474, 185000, 'winged helmet')
shopModule:addSellableItem({'demon helmet'}, 2493, 184000, 'demon helmet')
shopModule:addSellableItem({'horned helmet'}, 2496, 195000, 'horned helmet')

-- Armors
shopModule:addSellableItem({'plate armor'}, 2463, 600, 'plate armor')
shopModule:addSellableItem({'knight armor'}, 2476, 5500, 'knight armor')
shopModule:addSellableItem({'scale armor'}, 2483, 100, 'scale armor')
shopModule:addSellableItem({'noble armor'}, 2486, 1000, 'noble armor')
shopModule:addSellableItem({'leopard armor'}, 3968, 500, 'leopard armor')
shopModule:addSellableItem({'rangers cloak'}, 2660, 200, 'rangers cloak')
shopModule:addSellableItem({'dark armor'}, 2489, 500, 'dark armor')
shopModule:addSellableItem({'golden armor'}, 2466, 33500, 'golden armor')
shopModule:addSellableItem({'crown armor'}, 2487, 22500, 'crown armor')
shopModule:addSellableItem({'amazon armor'}, 2500, 122500, 'amazon armor')
shopModule:addSellableItem({'elven armor'}, 2505, 22500, 'elven armor')
shopModule:addSellableItem({'magic plate armor'}, 2472, 160000, 'magic plate armor')
shopModule:addSellableItem({'demon armor'}, 2494, 245000, 'demon armor')
shopModule:addSellableItem({'dragon scale mail'}, 2492, 46000, 'dragon scale mail')

-- Legs
shopModule:addSellableItem({'knight legs'}, 2477, 8000, 'knight legs')
shopModule:addSellableItem({'elven legs'}, 2507, 400, 'elven legs')
shopModule:addSellableItem({'plate legs'}, 2647, 700, 'plate legs')
shopModule:addSellableItem({'crown legs'}, 2488, 18000, 'crown legs')
shopModule:addSellableItem({'golden legs'}, 2470, 67000, 'golden legs')
shopModule:addSellableItem({'demon legs'}, 2495, 175000, 'demon legs')

-- Boots
shopModule:addSellableItem({'steel boots'}, 2645, 42000, 'steel boots')
shopModule:addSellableItem({'golden boots'}, 2646, 45000, 'golden boots')

shopModule:addSellableItem({'sword'}, 2376, 70, 'sword')
shopModule:addSellableItem({'mace'}, 2398, 70, 'mace')
shopModule:addSellableItem({'axe'}, 2386, 70, 'axe')
shopModule:addSellableItem({'giant smithhammer'}, 2321, 2400, 'giant smithhammer')
shopModule:addSellableItem({'two handed sword'}, 2377, 950, 'two handed sword')
shopModule:addSellableItem({'battle axe'}, 2378, 900, 'battle axe')
shopModule:addSellableItem({'halberd'}, 2381, 950, 'halberd')
shopModule:addSellableItem({'spike sword'}, 2383, 1100, 'spike sword')
shopModule:addSellableItem({'double axe'}, 2387, 920, 'double axe')
shopModule:addSellableItem({'fire sword'}, 2392, 6000, 'fire sword')
shopModule:addSellableItem({'morning star'}, 2394, 400, 'morning star')
shopModule:addSellableItem({'bright sword'}, 2407, 9000, 'bright sword')
shopModule:addSellableItem({'serpent sword'}, 2409, 1000, 'serpent sword')
shopModule:addSellableItem({'broad sword'}, 2413, 300, 'broad sword')
shopModule:addSellableItem({'battle hammer'}, 2417, 250, 'battle hammer')
shopModule:addSellableItem({'clerical mace'}, 2423, 300, 'clerical mace')
shopModule:addSellableItem({'obsidian lance'}, 2425, 2500, 'obsidian lance')
shopModule:addSellableItem({'naginata'}, 2426, 4500, 'naginata')
shopModule:addSellableItem({'barbarian axe'}, 2429, 3000, 'barbarian axe')
shopModule:addSellableItem({'knight axe'}, 2430, 5000, 'knight axe')
shopModule:addSellableItem({'fire axe'}, 2432, 7000, 'fire axe')
shopModule:addSellableItem({'dragon hammer'}, 2434, 2500, 'dragon hammer')
shopModule:addSellableItem({'dwarven axe'}, 2435, 2800, 'dwarven axe')
shopModule:addSellableItem({'skull staff'}, 2436, 6000, 'skull staff')
shopModule:addSellableItem({'epee'}, 2438, 7000, 'epee')
shopModule:addSellableItem({'daramanian waraxe'}, 2440, 1500, 'daramanian waraxe')
shopModule:addSellableItem({'crystal mace'}, 2445, 6000, 'crystal mace')
shopModule:addSellableItem({'pharaoh sword'}, 2446, 19000, 'pharaoh sword')
shopModule:addSellableItem({'djinn blade'}, 2451, 18000, 'djinn blade')
shopModule:addSellableItem({'lich staff'}, 3961, 18000, 'lich staff')
shopModule:addSellableItem({'beastslayer axe'}, 3962, 5000, 'beastslayer axe')
shopModule:addSellableItem({'platinum amulet'}, 2171, 2000, 'platinum amulet')

shopModule:addSellableItem({'war hammer'}, 2391, 21200, 'war hammer')
shopModule:addSellableItem({'giant sword'}, 2393, 22000, 'giant sword')
shopModule:addSellableItem({'dragon lance'}, 2414, 22200, 'dragon lance')
shopModule:addSellableItem({'silver mace'}, 2424, 21200, 'silver mace')
shopModule:addSellableItem({'guardian halberd'}, 2427, 3200, 'guardian halberd')
shopModule:addSellableItem({'light mace'}, 2437, 5500, 'light mace')
shopModule:addSellableItem({'ravagers axe'}, 2443, 5200, 'ravagers axe')
shopModule:addSellableItem({'hammer of wrath'}, 2444, 5400, 'hammer of wrath')
shopModule:addSellableItem({'tytan axe'}, 2447, 2800, 'tytan axe')
shopModule:addSellableItem({'heavy mace'}, 2452, 2200, 'heavy mace')
shopModule:addSellableItem({'war axe'}, 2454, 2900, 'war axe')
shopModule:addSellableItem({'hat of the mad'}, 2323, 23500, 'hat of the mad')
shopModule:addSellableItem({'ceremonial mask'}, 2501, 12500, 'ceremonial mask')
shopModule:addSellableItem({'blue robe'}, 2656, 33500, 'blue robe')
shopModule:addSellableItem({'magician hat'}, 2662, 7555, 'magician hat')

shopModule:addSellableItem({'magic longsword'}, 2390, 440000, 'magic longsword')
shopModule:addSellableItem({'ice rapier'}, 2396, 1000, 'ice rapier')
shopModule:addSellableItem({'magic sword'}, 2400, 119000, 'magic sword')
shopModule:addSellableItem({'warlord sword'}, 2408, 135000, 'warlord sword')
shopModule:addSellableItem({'great axe'}, 2415, 140000, 'great axe')
shopModule:addSellableItem({'thunder hammer'}, 2421, 119000, 'thunder hammer')
shopModule:addSellableItem({'stonecutter axe'}, 2431, 119000, 'stonecutter axe')
shopModule:addSellableItem({'arcane staff'}, 2453, 140000, 'arcane staff')

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
Try changing elseif for else

Example:
Lua:
if msgcontains(msg, 'brass armor') then
            if getPlayerItemCount(cid,2465) >= 1 then
                selfSay('Did you bring me a brass armor?', cid)
                talk_state = 1
            else
                selfSay('I need a brass armor to give you a crystal coin. Come back when you have them.', cid)
                talk_state = 0
            end

            elseif msgcontains(msg, 'yes') and talk_state == 1 then
            talk_state = 0
            if getPlayerItemCount(cid,2465) >= 1 then
            if doPlayerRemoveItem(cid,2465, 10) == TRUE then
                            selfSay(done, cid)
            doPlayerAddItem(cid, 2160, 1)
            end
            else
                selfSay(item, cid)
            end
Check this maybe will be helpfull


Hope this helps!
Regards
I’ll give it a try later today and I’ll let you know how it goes, thanks!
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
Isn't OTX just like TFS 1.x?
Can't you just use the standard shop modules?
In npc/lib/npcsystem/modules.lua you might need to force SHOPMODULE_MODE = SHOPMODULE_MODE_TALK

I snagged this NPC from here: mattyx14/otxserver (https://github.com/mattyx14/otxserver/tree/otxv2_12/path_7_x/data/npc)

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Britany" nameDescription="Britany, the arms buyer" script="lot.lua" walkinterval="2000" skull="green" floorchange="0">
    <health now="150" max="150"/>
    <look type="139" head="114" body="94" legs="19" feet="0" corpse="2212"/>
    <parameters>
        <parameter key="module_shop" value="1"/>
        <parameter key="message_greet" value="Hello |PLAYERNAME|. I buy swords, clubs, axes, helmets, boots, legs, shields and armors."/>
    </parameters>
    <voices>
        <voice text="Come and sell your items very expensive price..." interval2="60" margin="1" type="16" yell="no"/>
        <voice text="There are some geniuses who valued your items to a much higher price..." interval2="120" margin="1" type="16" yell="no"/>
    </voices>
</npc>
Lua:
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
function onPlayerEndTrade(cid)                npcHandler:onPlayerEndTrade(cid)            end
function onPlayerCloseChannel(cid)            npcHandler:onPlayerCloseChannel(cid)        end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

-- Seller Objets
-- Helmets
shopModule:addSellableItem({'steel helmet'}, 2457, 200, 'steel helmet')
shopModule:addSellableItem({'devil helmet'}, 2462, 5000, 'devil helmet')
shopModule:addSellableItem({'warrior helmet'}, 2475, 7000, 'warrior helmet')
shopModule:addSellableItem({'dark helmet'}, 2490, 250, 'dark helmet')
shopModule:addSellableItem({'crown helmet'}, 2491, 7500, 'crown helmet')
shopModule:addSellableItem({'crusader helmet'}, 2497, 7600, 'crusader helmet')
shopModule:addSellableItem({'beholder helmet'}, 3972, 7500, 'beholder helmet')
shopModule:addSellableItem({'helmet of the ancients'}, 2342, 12700, 'helmet of the ancients')
shopModule:addSellableItem({'royal helmet'}, 2498, 34500, 'royal helmet')
shopModule:addSellableItem({'amazon helmet'}, 2499, 112500, 'amazon helmet')
shopModule:addSellableItem({'dragon scale helmet'}, 2506, 115000, 'dragon scale helmet')
shopModule:addSellableItem({'golden helmet'}, 2471, 188000, 'golden helmet')
shopModule:addSellableItem({'winged helmet'}, 2474, 185000, 'winged helmet')
shopModule:addSellableItem({'demon helmet'}, 2493, 184000, 'demon helmet')
shopModule:addSellableItem({'horned helmet'}, 2496, 195000, 'horned helmet')

-- Armors
shopModule:addSellableItem({'plate armor'}, 2463, 600, 'plate armor')
shopModule:addSellableItem({'knight armor'}, 2476, 5500, 'knight armor')
shopModule:addSellableItem({'scale armor'}, 2483, 100, 'scale armor')
shopModule:addSellableItem({'noble armor'}, 2486, 1000, 'noble armor')
shopModule:addSellableItem({'leopard armor'}, 3968, 500, 'leopard armor')
shopModule:addSellableItem({'rangers cloak'}, 2660, 200, 'rangers cloak')
shopModule:addSellableItem({'dark armor'}, 2489, 500, 'dark armor')
shopModule:addSellableItem({'golden armor'}, 2466, 33500, 'golden armor')
shopModule:addSellableItem({'crown armor'}, 2487, 22500, 'crown armor')
shopModule:addSellableItem({'amazon armor'}, 2500, 122500, 'amazon armor')
shopModule:addSellableItem({'elven armor'}, 2505, 22500, 'elven armor')
shopModule:addSellableItem({'magic plate armor'}, 2472, 160000, 'magic plate armor')
shopModule:addSellableItem({'demon armor'}, 2494, 245000, 'demon armor')
shopModule:addSellableItem({'dragon scale mail'}, 2492, 46000, 'dragon scale mail')

-- Legs
shopModule:addSellableItem({'knight legs'}, 2477, 8000, 'knight legs')
shopModule:addSellableItem({'elven legs'}, 2507, 400, 'elven legs')
shopModule:addSellableItem({'plate legs'}, 2647, 700, 'plate legs')
shopModule:addSellableItem({'crown legs'}, 2488, 18000, 'crown legs')
shopModule:addSellableItem({'golden legs'}, 2470, 67000, 'golden legs')
shopModule:addSellableItem({'demon legs'}, 2495, 175000, 'demon legs')

-- Boots
shopModule:addSellableItem({'steel boots'}, 2645, 42000, 'steel boots')
shopModule:addSellableItem({'golden boots'}, 2646, 45000, 'golden boots')

shopModule:addSellableItem({'sword'}, 2376, 70, 'sword')
shopModule:addSellableItem({'mace'}, 2398, 70, 'mace')
shopModule:addSellableItem({'axe'}, 2386, 70, 'axe')
shopModule:addSellableItem({'giant smithhammer'}, 2321, 2400, 'giant smithhammer')
shopModule:addSellableItem({'two handed sword'}, 2377, 950, 'two handed sword')
shopModule:addSellableItem({'battle axe'}, 2378, 900, 'battle axe')
shopModule:addSellableItem({'halberd'}, 2381, 950, 'halberd')
shopModule:addSellableItem({'spike sword'}, 2383, 1100, 'spike sword')
shopModule:addSellableItem({'double axe'}, 2387, 920, 'double axe')
shopModule:addSellableItem({'fire sword'}, 2392, 6000, 'fire sword')
shopModule:addSellableItem({'morning star'}, 2394, 400, 'morning star')
shopModule:addSellableItem({'bright sword'}, 2407, 9000, 'bright sword')
shopModule:addSellableItem({'serpent sword'}, 2409, 1000, 'serpent sword')
shopModule:addSellableItem({'broad sword'}, 2413, 300, 'broad sword')
shopModule:addSellableItem({'battle hammer'}, 2417, 250, 'battle hammer')
shopModule:addSellableItem({'clerical mace'}, 2423, 300, 'clerical mace')
shopModule:addSellableItem({'obsidian lance'}, 2425, 2500, 'obsidian lance')
shopModule:addSellableItem({'naginata'}, 2426, 4500, 'naginata')
shopModule:addSellableItem({'barbarian axe'}, 2429, 3000, 'barbarian axe')
shopModule:addSellableItem({'knight axe'}, 2430, 5000, 'knight axe')
shopModule:addSellableItem({'fire axe'}, 2432, 7000, 'fire axe')
shopModule:addSellableItem({'dragon hammer'}, 2434, 2500, 'dragon hammer')
shopModule:addSellableItem({'dwarven axe'}, 2435, 2800, 'dwarven axe')
shopModule:addSellableItem({'skull staff'}, 2436, 6000, 'skull staff')
shopModule:addSellableItem({'epee'}, 2438, 7000, 'epee')
shopModule:addSellableItem({'daramanian waraxe'}, 2440, 1500, 'daramanian waraxe')
shopModule:addSellableItem({'crystal mace'}, 2445, 6000, 'crystal mace')
shopModule:addSellableItem({'pharaoh sword'}, 2446, 19000, 'pharaoh sword')
shopModule:addSellableItem({'djinn blade'}, 2451, 18000, 'djinn blade')
shopModule:addSellableItem({'lich staff'}, 3961, 18000, 'lich staff')
shopModule:addSellableItem({'beastslayer axe'}, 3962, 5000, 'beastslayer axe')
shopModule:addSellableItem({'platinum amulet'}, 2171, 2000, 'platinum amulet')

shopModule:addSellableItem({'war hammer'}, 2391, 21200, 'war hammer')
shopModule:addSellableItem({'giant sword'}, 2393, 22000, 'giant sword')
shopModule:addSellableItem({'dragon lance'}, 2414, 22200, 'dragon lance')
shopModule:addSellableItem({'silver mace'}, 2424, 21200, 'silver mace')
shopModule:addSellableItem({'guardian halberd'}, 2427, 3200, 'guardian halberd')
shopModule:addSellableItem({'light mace'}, 2437, 5500, 'light mace')
shopModule:addSellableItem({'ravagers axe'}, 2443, 5200, 'ravagers axe')
shopModule:addSellableItem({'hammer of wrath'}, 2444, 5400, 'hammer of wrath')
shopModule:addSellableItem({'tytan axe'}, 2447, 2800, 'tytan axe')
shopModule:addSellableItem({'heavy mace'}, 2452, 2200, 'heavy mace')
shopModule:addSellableItem({'war axe'}, 2454, 2900, 'war axe')
shopModule:addSellableItem({'hat of the mad'}, 2323, 23500, 'hat of the mad')
shopModule:addSellableItem({'ceremonial mask'}, 2501, 12500, 'ceremonial mask')
shopModule:addSellableItem({'blue robe'}, 2656, 33500, 'blue robe')
shopModule:addSellableItem({'magician hat'}, 2662, 7555, 'magician hat')

shopModule:addSellableItem({'magic longsword'}, 2390, 440000, 'magic longsword')
shopModule:addSellableItem({'ice rapier'}, 2396, 1000, 'ice rapier')
shopModule:addSellableItem({'magic sword'}, 2400, 119000, 'magic sword')
shopModule:addSellableItem({'warlord sword'}, 2408, 135000, 'warlord sword')
shopModule:addSellableItem({'great axe'}, 2415, 140000, 'great axe')
shopModule:addSellableItem({'thunder hammer'}, 2421, 119000, 'thunder hammer')
shopModule:addSellableItem({'stonecutter axe'}, 2431, 119000, 'stonecutter axe')
shopModule:addSellableItem({'arcane staff'}, 2453, 140000, 'arcane staff')

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Hi mdwilliams. It is, but I’ve tried many NPCs like that and they weren’t working. I didn’t know about the modules.lua thing you said, so I’ll check it out, maybe that was the problem. I’ll update the post with the results later today - thanks!
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
Try changing elseif for else

Example:
Lua:
if msgcontains(msg, 'brass armor') then
            if getPlayerItemCount(cid,2465) >= 1 then
                selfSay('Did you bring me a brass armor?', cid)
                talk_state = 1
            else
                selfSay('I need a brass armor to give you a crystal coin. Come back when you have them.', cid)
                talk_state = 0
            end

            elseif msgcontains(msg, 'yes') and talk_state == 1 then
            talk_state = 0
            if getPlayerItemCount(cid,2465) >= 1 then
            if doPlayerRemoveItem(cid,2465, 10) == TRUE then
                            selfSay(done, cid)
            doPlayerAddItem(cid, 2160, 1)
            end
            else
                selfSay(item, cid)
            end
Check this maybe will be helpfull


Hope this helps!
Regards
Hey Ralke, thanks for your help, it works! Just a question, is there any way you can help me modify it so that I don't have to confirm with a "yes" every time I want to sell one? I would have to say "brass armor" - "yes" over and over again. If it's possible, can it be changed to just say "brass armor" and make the sell? And of course, if there are no armors left, have a "sorry you dont have that armor" kind of message.
 

ralke

Felipe
Joined
Dec 17, 2011
Messages
270
Reaction score
32
Location
Chile
ok, I'll try, this is the first script I've ever made from scratch, I used bank.lua change gold function as reference (this line specifically
https://pastebin.com/yVqexb4J)
Lua:
 -- i started with talkstate = 1 to start the selling, then NPC will ask how many items you have (talkstate = 2) --
            if msgcontains(msg, 'brass armor') then
            selfSay('How many brass armors you bring me?', cid)
            talkstate[cid] = 1
            elseif talkState[cid] == 1 then
            if getCount(msg) == -1 or getCount(msg) == 0 then
            selfSay('Can I help with something else?', cid)
            talk_state = 0
            else
            count[cid] = getCount(msg)
            selfSay("You want to sell ".. count[cid] .. " of your brass armor for " .. count[cid] .. " crystal?", cid)
            talkstate[cid] = 2
            end

-- starting with talkstate 2 the message "yes" will action doPlayerRemove and AddItem with a count set by count[cid] = getCount (msg) --
            elseif talkstate[cid] == 2 then
            if msgcontains (msg, 'yes') then
            if doPlayerRemoveItem(cid, 2465, count[cid]) then
            doPlayerAddItem(cid, 2160, count[cid] * 100)
            selfSay('Here you are.', cid)
            else
            selfSay('Sorry you dont have the requiered items.', cid)
            end
            else
            selfSay('Can I help with something else?', cid)
            end
            talkstate[cid] = 0
            end
            return true
            end
I fixed the amount of given gold. At count[cid] * 100, set "100" as the price of brass armor, that will multiply the price according to count[cid] or getcount(msg) that is the same. Also change 2160 to the gold coin ID. Please report my any error I really want this to work

Hope it helps!
Regards
 
Last edited:

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Joined
Mar 16, 2017
Messages
412
Reaction score
237
Location
London
Tested on TFS 0.4
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 sellSelect = {}
local countState = {}
local sellShop = {
    { name = "plate armor", itemid = 2463, cost = 100 },
    { name = "wand of vortex", itemid = 2190, cost = 100 }
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if not sellSelect[cid] then
        for index, info in pairs(sellShop) do
            if msgcontains(msg, info.name) then
                sellSelect[cid] = info
                npcHandler:say(string.format("How many {%s} do you want to sell?", info.name), cid)
                break
            elseif not next(sellShop, index) then
                npcHandler:say("There is no item in the list with that name.", cid)
                return true
            end
        end
    elseif not countState[cid] then
        countState[cid] = tonumber(msg)
        if countState[cid] and countState[cid] > 0 then
            if getPlayerItemCount(cid, sellSelect[cid].itemid) >= countState[cid] then
                npcHandler:say(string.format("Do you want to sell {%u %s}?", countState[cid], sellSelect[cid].name), cid)
            else
                npcHandler:say(string.format("You do not have enough %s, choose another amount.", sellSelect[cid].name), cid)
                countState[cid] = nil
            end
        else
            npcHandler:say("You must tell me the amount you want to sell.", cid)
        end
    else
        if msgcontains(msg, "yes") then
            local totalCost = sellSelect[cid].cost * countState[cid]
            if doPlayerRemoveItem(cid, sellSelect[cid].itemid, countState[cid]) then
                doPlayerAddMoney(cid, totalCost)
                npcHandler:say(string.format("you have sold {%u %s} x {%u} golds.", countState[cid], sellSelect[cid].name, totalCost), cid)
            else
                npcHandler:say(string.format("You do not have enough %s.", sellSelect[cid].name), cid)
            end
            countState[cid] = nil
            sellSelect[cid] = nil
        elseif msgcontains(msg, "no") then
            npcHandler:say("Come back when you want to sell friend.", cid)
            countState[cid] = nil
            sellSelect[cid] = nil
        end
    end

    return true
end

function creatureDisappear(cid)
    countState[cid] = nil
    sellSelect[cid] = nil
    npcHandler:releaseFocus(cid)
    npcHandler:say(npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_WALKAWAY), { [TAG_PLAYERNAME] = getPlayerName(cid) }))
    return true
end

npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureDisappear)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
1) Example: hi - plate armor - 1 - yes
2) Example: hi - wand of vortex - 2 - yes


The list of items you can sell:
Code:
local sellShop = {
    { name = "plate armor", itemid = 2463, cost = 100 },
    { name = "wand of vortex", itemid = 2190, cost = 100 }
}
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
ok, I'll try, this is the first script I've ever made from scratch, I used bank.lua change gold function as reference (this line specifically
https://pastebin.com/yVqexb4J)
Lua:
 -- i started with talkstate = 1 to start the selling, then NPC will ask how many items you have (talkstate = 2) --
            if msgcontains(msg, 'brass armor') then
            selfSay('How many brass armors you bring me?', cid)
            talkstate[cid] = 1
            elseif talkState[cid] == 1 then
            if getCount(msg) == -1 or getCount(msg) == 0 then
            selfSay('Can I help with something else?', cid)
            talk_state = 0
            else
            count[cid] = getCount(msg)
            selfSay("You want to sell ".. count[cid] .. " of your brass armor for " .. count[cid] .. " crystal?", cid)
            talkstate[cid] = 2
            end

-- starting with talkstate 2 the message "yes" will action doPlayerRemove and AddItem with a count set by count[cid] = getCount (msg) --
            elseif talkstate[cid] == 2 then
            if msgcontains (msg, 'yes') then
            if doPlayerRemoveItem(cid, 2465, count[cid]) then
            doPlayerAddItem(cid, 2160, count[cid] * 100)
            selfSay('Here you are.', cid)
            else
            selfSay('Sorry you dont have the requiered items.', cid)
            end
            else
            selfSay('Can I help with something else?', cid)
            end
            talkstate[cid] = 0
            end
            return true
            end
I fixed the amount of given gold. At count[cid] * 100, set "100" as the price of brass armor, that will multiply the price according to count[cid] or getcount(msg) that is the same. Also change 2160 to the gold coin ID. Please report my any error I really want this to work

Hope it helps!
Regards
Absolutely, as soon as I test it, I’ll let you know how it goes. I really appreciate your help!
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
Tested on TFS 0.4
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 sellSelect = {}
local countState = {}
local sellShop = {
    { name = "plate armor", itemid = 2463, cost = 100 },
    { name = "wand of vortex", itemid = 2190, cost = 100 }
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if not sellSelect[cid] then
        for index, info in pairs(sellShop) do
            if msgcontains(msg, info.name) then
                sellSelect[cid] = info
                npcHandler:say(string.format("How many {%s} do you want to sell?", info.name), cid)
                break
            elseif not next(sellShop, index) then
                npcHandler:say("There is no item in the list with that name.", cid)
                return true
            end
        end
    elseif not countState[cid] then
        countState[cid] = tonumber(msg)
        if countState[cid] and countState[cid] > 0 then
            if getPlayerItemCount(cid, sellSelect[cid].itemid) >= countState[cid] then
                npcHandler:say(string.format("Do you want to sell {%u %s}?", countState[cid], sellSelect[cid].name), cid)
            else
                npcHandler:say(string.format("You do not have enough %s, choose another amount.", sellSelect[cid].name), cid)
                countState[cid] = nil
            end
        else
            npcHandler:say("You must tell me the amount you want to sell.", cid)
        end
    else
        if msgcontains(msg, "yes") then
            local totalCost = sellSelect[cid].cost * countState[cid]
            if doPlayerRemoveItem(cid, sellSelect[cid].itemid, countState[cid]) then
                doPlayerAddMoney(cid, totalCost)
                npcHandler:say(string.format("you have sold {%u %s} x {%u} golds.", countState[cid], sellSelect[cid].name, totalCost), cid)
            else
                npcHandler:say(string.format("You do not have enough %s.", sellSelect[cid].name), cid)
            end
            countState[cid] = nil
            sellSelect[cid] = nil
        elseif msgcontains(msg, "no") then
            npcHandler:say("Come back when you want to sell friend.", cid)
            countState[cid] = nil
            sellSelect[cid] = nil
        end
    end

    return true
end

function creatureDisappear(cid)
    countState[cid] = nil
    sellSelect[cid] = nil
    npcHandler:releaseFocus(cid)
    npcHandler:say(npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_WALKAWAY), { [TAG_PLAYERNAME] = getPlayerName(cid) }))
    return true
end

npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureDisappear)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
1) Example: hi - plate armor - 1 - yes
2) Example: hi - wand of vortex - 2 - yes


The list of items you can sell:
Code:
local sellShop = {
    { name = "plate armor", itemid = 2463, cost = 100 },
    { name = "wand of vortex", itemid = 2190, cost = 100 }
}
Hey Sarah, thank you very much! I’ll try it out in a few hours and I’ll let you know if it works on my server. I appreciate it!
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
ok, I'll try, this is the first script I've ever made from scratch, I used bank.lua change gold function as reference (this line specifically
https://pastebin.com/yVqexb4J)
Lua:
 -- i started with talkstate = 1 to start the selling, then NPC will ask how many items you have (talkstate = 2) --
            if msgcontains(msg, 'brass armor') then
            selfSay('How many brass armors you bring me?', cid)
            talkstate[cid] = 1
            elseif talkState[cid] == 1 then
            if getCount(msg) == -1 or getCount(msg) == 0 then
            selfSay('Can I help with something else?', cid)
            talk_state = 0
            else
            count[cid] = getCount(msg)
            selfSay("You want to sell ".. count[cid] .. " of your brass armor for " .. count[cid] .. " crystal?", cid)
            talkstate[cid] = 2
            end

-- starting with talkstate 2 the message "yes" will action doPlayerRemove and AddItem with a count set by count[cid] = getCount (msg) --
            elseif talkstate[cid] == 2 then
            if msgcontains (msg, 'yes') then
            if doPlayerRemoveItem(cid, 2465, count[cid]) then
            doPlayerAddItem(cid, 2160, count[cid] * 100)
            selfSay('Here you are.', cid)
            else
            selfSay('Sorry you dont have the requiered items.', cid)
            end
            else
            selfSay('Can I help with something else?', cid)
            end
            talkstate[cid] = 0
            end
            return true
            end
I fixed the amount of given gold. At count[cid] * 100, set "100" as the price of brass armor, that will multiply the price according to count[cid] or getcount(msg) that is the same. Also change 2160 to the gold coin ID. Please report my any error I really want this to work

Hope it helps!
Regards
Hey Ralke, I just tried your script but unfortunately it didn't work. When the NPC asks me how many -item- do I want to sell, I tell him the amount (1,2,3,4, whatever...) and nothing happens. And this error appears in the .exe: 20: attempt to index global 'talkState' (a nil value).

It must be a minor error, I'll try to figure it out as well.
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
Hi
Tested on TFS 0.4
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 sellSelect = {}
local countState = {}
local sellShop = {
    { name = "plate armor", itemid = 2463, cost = 100 },
    { name = "wand of vortex", itemid = 2190, cost = 100 }
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if not sellSelect[cid] then
        for index, info in pairs(sellShop) do
            if msgcontains(msg, info.name) then
                sellSelect[cid] = info
                npcHandler:say(string.format("How many {%s} do you want to sell?", info.name), cid)
                break
            elseif not next(sellShop, index) then
                npcHandler:say("There is no item in the list with that name.", cid)
                return true
            end
        end
    elseif not countState[cid] then
        countState[cid] = tonumber(msg)
        if countState[cid] and countState[cid] > 0 then
            if getPlayerItemCount(cid, sellSelect[cid].itemid) >= countState[cid] then
                npcHandler:say(string.format("Do you want to sell {%u %s}?", countState[cid], sellSelect[cid].name), cid)
            else
                npcHandler:say(string.format("You do not have enough %s, choose another amount.", sellSelect[cid].name), cid)
                countState[cid] = nil
            end
        else
            npcHandler:say("You must tell me the amount you want to sell.", cid)
        end
    else
        if msgcontains(msg, "yes") then
            local totalCost = sellSelect[cid].cost * countState[cid]
            if doPlayerRemoveItem(cid, sellSelect[cid].itemid, countState[cid]) then
                doPlayerAddMoney(cid, totalCost)
                npcHandler:say(string.format("you have sold {%u %s} x {%u} golds.", countState[cid], sellSelect[cid].name, totalCost), cid)
            else
                npcHandler:say(string.format("You do not have enough %s.", sellSelect[cid].name), cid)
            end
            countState[cid] = nil
            sellSelect[cid] = nil
        elseif msgcontains(msg, "no") then
            npcHandler:say("Come back when you want to sell friend.", cid)
            countState[cid] = nil
            sellSelect[cid] = nil
        end
    end

    return true
end

function creatureDisappear(cid)
    countState[cid] = nil
    sellSelect[cid] = nil
    npcHandler:releaseFocus(cid)
    npcHandler:say(npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_WALKAWAY), { [TAG_PLAYERNAME] = getPlayerName(cid) }))
    return true
end

npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureDisappear)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
1) Example: hi - plate armor - 1 - yes
2) Example: hi - wand of vortex - 2 - yes


The list of items you can sell:
Code:
local sellShop = {
    { name = "plate armor", itemid = 2463, cost = 100 },
    { name = "wand of vortex", itemid = 2190, cost = 100 }
}
Hi Sarah, I just tested your script and it works perfectly, thank you very much!

Just one question, is there any way to change the price to crystal coins? I changed the plate armor price to 10,000, to make it 1 cc, however, once the sell is done, the NPC will say "you have sold {%u %s} x {%u} golds.", and if I change "golds" to "crystal coins", it will say "x 10,000 crystal coins" when it is in fact 1 cc, you know what I mean?
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Joined
Mar 16, 2017
Messages
412
Reaction score
237
Location
London
Hi

Hi Sarah, I just tested your script and it works perfectly, thank you very much!

Just one question, is there any way to change the price to crystal coins? I changed the plate armor price to 10,000, to make it 1 cc, however, once the sell is done, the NPC will say "you have sold {%u %s} x {%u} golds.", and if I change "golds" to "crystal coins", it will say "x 10,000 crystal coins" when it is in fact 1 cc, you know what I mean?
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 sellSelect = {}
local countState = {}
local sellShop = {
    { name = "plate armor", itemid = 2463, cost = 155000 },
    { name = "wand of vortex", itemid = 2190, cost = 100000 }
}

local function getMoneyMessage(golds)
    if golds >= 10000 then
        return string.format("%.1f crystal coins", golds/10000)
    end
    return string.format("%u golds", golds)
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if not sellSelect[cid] then
        for index, info in pairs(sellShop) do
            if msgcontains(msg, info.name) then
                sellSelect[cid] = info
                npcHandler:say(string.format("How many {%s} do you want to sell?", info.name), cid)
                break
            elseif not next(sellShop, index) then
                npcHandler:say("There is no item in the list with that name.", cid)
                return true
            end
        end
    elseif not countState[cid] then
        countState[cid] = tonumber(msg)
        if countState[cid] and countState[cid] > 0 then
            if getPlayerItemCount(cid, sellSelect[cid].itemid) >= countState[cid] then
                npcHandler:say(string.format("Do you want to sell {%u %s}?", countState[cid], sellSelect[cid].name), cid)
            else
                npcHandler:say(string.format("You do not have enough %s, choose another amount.", sellSelect[cid].name), cid)
                countState[cid] = nil
            end
        else
            npcHandler:say("You must tell me the amount you want to sell.", cid)
        end
    else
        if msgcontains(msg, "yes") then
            local totalCost = sellSelect[cid].cost * countState[cid]
            if doPlayerRemoveItem(cid, sellSelect[cid].itemid, countState[cid]) then
                doPlayerAddMoney(cid, totalCost)
                npcHandler:say(string.format("you have sold {%u %s} x {%s}.", countState[cid], sellSelect[cid].name, getMoneyMessage(totalCost)), cid)
            else
                npcHandler:say(string.format("You do not have enough %s.", sellSelect[cid].name), cid)
            end
            countState[cid] = nil
            sellSelect[cid] = nil
        elseif msgcontains(msg, "no") then
            npcHandler:say("Come back when you want to sell friend.", cid)
            countState[cid] = nil
            sellSelect[cid] = nil
        end
    end

    return true
end

function creatureDisappear(cid)
    countState[cid] = nil
    sellSelect[cid] = nil
    npcHandler:releaseFocus(cid)
    npcHandler:say(npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_WALKAWAY), { [TAG_PLAYERNAME] = getPlayerName(cid) }))
    return true
end
 
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureDisappear)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
With this you can see the amount of money you get but in crystals.
 
OP
X

XST53

Member
Joined
May 14, 2019
Messages
34
Reaction score
4
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 sellSelect = {}
local countState = {}
local sellShop = {
    { name = "plate armor", itemid = 2463, cost = 155000 },
    { name = "wand of vortex", itemid = 2190, cost = 100000 }
}

local function getMoneyMessage(golds)
    if golds >= 10000 then
        return string.format("%.1f crystal coins", golds/10000)
    end
    return string.format("%u golds", golds)
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if not sellSelect[cid] then
        for index, info in pairs(sellShop) do
            if msgcontains(msg, info.name) then
                sellSelect[cid] = info
                npcHandler:say(string.format("How many {%s} do you want to sell?", info.name), cid)
                break
            elseif not next(sellShop, index) then
                npcHandler:say("There is no item in the list with that name.", cid)
                return true
            end
        end
    elseif not countState[cid] then
        countState[cid] = tonumber(msg)
        if countState[cid] and countState[cid] > 0 then
            if getPlayerItemCount(cid, sellSelect[cid].itemid) >= countState[cid] then
                npcHandler:say(string.format("Do you want to sell {%u %s}?", countState[cid], sellSelect[cid].name), cid)
            else
                npcHandler:say(string.format("You do not have enough %s, choose another amount.", sellSelect[cid].name), cid)
                countState[cid] = nil
            end
        else
            npcHandler:say("You must tell me the amount you want to sell.", cid)
        end
    else
        if msgcontains(msg, "yes") then
            local totalCost = sellSelect[cid].cost * countState[cid]
            if doPlayerRemoveItem(cid, sellSelect[cid].itemid, countState[cid]) then
                doPlayerAddMoney(cid, totalCost)
                npcHandler:say(string.format("you have sold {%u %s} x {%s}.", countState[cid], sellSelect[cid].name, getMoneyMessage(totalCost)), cid)
            else
                npcHandler:say(string.format("You do not have enough %s.", sellSelect[cid].name), cid)
            end
            countState[cid] = nil
            sellSelect[cid] = nil
        elseif msgcontains(msg, "no") then
            npcHandler:say("Come back when you want to sell friend.", cid)
            countState[cid] = nil
            sellSelect[cid] = nil
        end
    end

    return true
end

function creatureDisappear(cid)
    countState[cid] = nil
    sellSelect[cid] = nil
    npcHandler:releaseFocus(cid)
    npcHandler:say(npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_WALKAWAY), { [TAG_PLAYERNAME] = getPlayerName(cid) }))
    return true
end

npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureDisappear)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
With this you can see the amount of money you get but in crystals.
Amazing, thank you very much, it's exactly what I needed!

Thanks Sarah & Ralke, I appreciate you guys taking your time to help me out, plus I learned a little of lua scripting from both of you, thanks again!
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Joined
Mar 16, 2017
Messages
412
Reaction score
237
Location
London
If your problem is already solved, then mark the best answer, so this topic can help other people who need the similar.
 
Top