• 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 Minor Crystalline Tokens instead of Gold coins

Peacy

Member
Joined
Mar 20, 2008
Messages
488
Reaction score
10
Location
The Netherlands
Hi,

I need to change an NPC script so that you'll pay with Minor Crystalline Tokens instead of Gold Coins

is that possible?
 
You can try this, just edit values.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local config = {
	count = count_here, item1 = ID_HERE
	}

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

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if msgcontains(msg, "buy item") then
		selfSay("Do you want to buy this rare item.."?", cid)
		talkState[talkUser] = 1
	end
	if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
		if doPlayerRemoveItem(cid, ITEM_ID_HERE, config.count) == TRUE then
			selfSay(Thanks for buying.", cid)
			doPlayerAddItem(cid, config.item1)
		else
			selfSay("You do not have enough tokens..".", cid)
		end
		talkState[talkUser] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local config = {
	token = {2345, 5},
	reward = {2345, 1}
}
 
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
	elseif msgcontains(msg, "buy item") then
		selfSay("Do you want to buy this rare item..?", cid)
		talkState[cid] = 1
	elseif talkState[cid] == 1 and msgcontains(msg, "yes") then
		if doPlayerRemoveItem(cid, unpack(config.token)) then
			selfSay("Thanks for buying.", cid)
			doPlayerAddItem(cid, unpack(config.reward))
		else
			selfSay("You do not have enough tokens...", cid)
		end
		talkState[cid] = nil
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
quotes etc
 
Sweet thanks guys :) and what if I would like to sell multiple items ?

Update:
Never mind, got it fixed.
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 creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
    return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}

local t = {
    [18393] = {price = 15, currency = 18422},   
}
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
        if t[item] and not doPlayerRemoveItem(cid, t[item].currency, t[item].price) then
            selfSay("You dont have "..t[item].price.." "..getItemNameById(t[item].currency), cid)
        else
            doPlayerAddItem(cid, item)
            selfSay("Here you go!", cid)
        end
    return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
    for var, ret in pairs(t) do
        table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top