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

NPC That Selling Things To You Using an ID instead of Money

ELEM3NT

LUA Status: Beginner
Joined
Mar 12, 2009
Messages
191
Reaction score
0
Location
In your room without you knowing.
Alright, so I have events on my server, in the events you gain these things called "Event Tokens." The itemid for it is: 9020. And I'm trying to make an NPC that sells different things but you can only buy them with event tokens...

Heres what it should be like:
Code:
Player: hello
NPC: Hello there, Player! I will buy your event tokens in return of great items, type {stockings} to see what I have.
Player: stockings
NPC: Great! So you're interested, I currently have {potions}, {exp scroll}, and {items}.
Player: potions
NPC: I have {berserk potions}, {bullseye potions}, and {mastermind potions}, each cost 10 event tokens.
Player: buy berserk potion
NPC: Would you like to buy a berserk potion?
Player: yes
NPC: Thank you for your tokens!

Then the NPC removes 10 Event Tokens from that player and adds 1 berserk potion...

Here's what my scripter scripted for me but has not completed it, he says he can't get the rest done. This is how far we got, at the moment, the NPC is only selling one item and it only has one reply talk thingy, (the hi, berserk potion, yes). If it makes it easier you guys can edit it from the script:

Event Tokens.xml
LUA:
<?xml version="1.0" encoding="utf-8"?>
<npc name="Event Token" nameDescription="Event Token, the one that takes event tokens" script="tokens.lua" walkinterval="2000" floorchange="0" skull="green" > 
	<health now="150" max="150"/>
	<look type="128" head="114" body="94" legs="114" feet="114" addons="3" corpse="2212"/>
</npc>

tokens.lua
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

npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. I buy event tokens for many great things. Type {stock} to see what I have.") 

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

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(msgcontains(msg, 'potion') or msgcontains(msg, 'berserker potion')) then
		selfSay('Do you want to buy a berserker potion for 5 event tokens? ID IS 2090 for token', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 9020) >= 5) then
			if(doPlayerRemoveMoney(cid, 0) == TRUE) then
				local item = getPlayerItemById(cid, TRUE, 9020)
				doTransformItem(item.uid, 7439)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end

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

Also, if this helps you with the script heres some info:

For the exp scroll, just put it "Unnamed scroll" then the itemID xxxx on the script.

For the items, just make it sell 3 items for now, make the itemID xxxx on the script and just name it unnamed item 1, unnamed item 2, unnamed item 3. I'm just not sure what items its gonna sell yet. Just make 3 for now then I can just try to work with the script and figure out how to add more.:thumbup:

This seems like alot so if you can make like a system or somethin, of this for me, I'd appreciate it.

Thank you,
ELEM3NT ^_^

PCE:peace:
 
Last edited:
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

npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. I buy event tokens for many great things. Type {stock} to see what I have.") 

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

        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

        if(msgcontains(msg, 'potion') or msgcontains(msg, 'berserker potion')) then
                selfSay('Do you want to buy a berserker potion for 5 event tokens?', cid)
                talkState[talkUser] = 1
        elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
                if(getPlayerItemCount(cid, 9020) >= 5) then
                        if doPlayerRemoveItem(cid,9020,5) then
                               doPlayerAddItem(cid,7439,1)
                                selfSay('Here you are.', cid)
                        else
                                selfSay('Sorry, you don\'t have enough tokens.', cid)
                        end
                else
                        selfSay('Sorry, you don\'t have the item.', cid)
                end
                talkState[talkUser] = 0
        elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
                talkState[talkUser] = 0
                selfSay('Ok then.', cid)
        end

        return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
@Ped0bear, thanks for taking your time to make that, but that's just not what I'm looking for.
The Story line of the NPC should be like this:

Code:
Player: hello
NPC: Hello there, Player! I will buy your event tokens in return of great items, type {stockings} to see what I have.
Player: stockings
NPC: Great! So you're interested, I currently have {potions}, {exp scroll}, and {items}.
Player: potions
NPC: I have {berserk potions}, {bullseye potions}, and {mastermind potions}, each cost 10 event tokens.
Player: buy berserk potion
NPC: Would you like to buy a berserk potion?
Player: yes
NPC: Thank you for your tokens!
 
About as easily-configurable as it can get.
Code:
local t = {
[B][COLOR="Red"]	['stockings'] = "Great! So you're interested, I currently have {potions}, {exp scroll}, and {items}.",
	['potions'] = "I have {berserk potions}, {bullseye potions}, and {mastermind potions}, each cost 10 event tokens.",
	['berserk potion'] = {9020, 10, 7439},
	['bullseye potion'] = {9020, 10, 7443},
	['mastermind potion'] = {9020, 10, 7440},[/COLOR][/B]
}

local function get(id, count)
	return (count > 1 and count or getItemInfo(id).article) .. ' ' .. (count > 1 and getItemInfo(id).plural or getItemInfo(id).name)
end

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

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 greetCallback(cid)
	Topic[cid] = ''
	return true
end

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

	if msgcontains(msg, 'yes') and Topic[cid] ~= '' then
		local k = t[Topic[cid]]
		if doPlayerRemoveItem(cid, k[1], k[2]) then
			npcHandler:say('Thank you for your tokens!', cid)
			doPlayerAddItem(cid, k[3], k[4] or 1)
		else
			npcHandler:say('You don\'t have enough tokens.', cid)
		end
		Topic[cid] = ''
		return
	end

	for k, v in pairs(t) do
		if msgcontains(msg, k) then
			if type(v) == 'string' then
				npcHandler:say(v, cid)
				Topic[cid] = ''
			else
				npcHandler:say('Would you like to buy ' .. get(v[3], v[4] or 1) .. ' for ' .. get(v[1], v[2]) .. '?', cid)
				Topic[cid] = k
			end
			break
		end
	end

end

npcHandler:setMessage(MESSAGE_GREET, 'Hello there, |PLAYERNAME|! I will buy your event tokens in return of great items, type {stockings} to see what I have.')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top