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

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