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

[idea] New way to buy Bp Of runes!!!

Status
Not open for further replies.
Code:
	function StdModule.buyContainer(cid, message, keywords, parameters, node)
		local npcHandler = parameters.npcHandler
		if(npcHandler == nil) then
			error('StdModule.buyContainer called without any npcHandler instance.')
		end
		if(cid ~= npcHandler.focus and (parameters.onlyFocus == nil or parameters.onlyFocus == true)) then
			return false
		end

		if getPlayerMoney(cid) >= parameters.cost then
			local container = doPlayerAddItem(cid, parameters.containerId, 1)
			if isContainer(container) == TRUE then
				while getContainerCap(container) ~= 0 do
					doAddContainerItem(container, parameters.runeId, parameters.runeCharges)
				end
			elseif container == LUA_ERROR then
				container = doCreateItem(parameters.containerId, 1, getThingPos(cid))
				if isContainer(container) == TRUE then
					while getContainerCap(container) ~= 0 do
						doAddContainerItem(container, parameters.runeId, parameters.runeCharges)
					end
				end
			end
			doPlayerRemoveMoney(cid, parameters.cost)
			npcHandler:say('Here you are.')
		else
			npcHandler:say('You do not have enough money.')
		end
		return true
	end

Example npc:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

local SDNode = keywordHandler:addKeyword({'bp sd', 'backpack of sd', 'backpack of sudden death'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy a backpack of sudden death runes for 6000 gold?'})
	SDNode:addChildKeyword({'yes'}, StdModule.buyContainer, {npcHandler = npcHandler, onlyFocus = true, cost = 6000, containerId = 2000, runeId = 2216, runeCharges = 1})
	SDNode:addChildKeyword({'no'}, StdModuel.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok, can I help you in anything else?'})

npcHandler:addModule(FocusModule:new())

Hope tis helps ;)

Obs: The IDs might be wrong.
 
Dude of this works i'm going to kiss you! (K)!!!! gone test it when i'm home;)



Edit)

dosen't work:
Bug

doAddContainerItem cant add item or somting like that.. my serevr get loads of these message
 
Last edited:
OKe i'v tryt somting new based on pedro B script, I'v fixed around 4 bugs but i'm stuck at this one and dont know hwot to fix :S:
Code:
			function StdModule.buyContainer(cid, message, keywords, parameters, node)
		local npcHandler = parameters.npcHandler
		if(npcHandler == nil) then
			error('StdModule.buyContainer called without any npcHandler instance.')
		end
		if(cid ~= npcHandler.focus and (parameters.onlyFocus == nil or parameters.onlyFocus == true)) then
			return false
		end
           		
		if getCount(cid) >= parameters.cost then
			local containerId = doPlayerAddItem(cid, parameters.containerId, 1)
			if isContainer(containerId) == TRUE then
				while getContainerCap(containerId) ~= 0 do
					doAddContainerItem(containerId, parameters.runeId, parameters.runeCharges)
				end
				end
			
			doPlayerRemoveMoney(cid, parameters.cost)
			npcHandler:say('Here you are.')
		else
			npcHandler:say('You do not have enough money.')
		end
		return true
	end
	
	function StdModule.say(cid, message, keywords, parameters, node)
		local npcHandler = parameters.npcHandler
		if(npcHandler == nil) then
			error('StdModule.say called without any npcHandler instance.')
		end
		if(cid ~= npcHandler.focus and (parameters.onlyFocus == nil or parameters.onlyFocus == true)) then
			return false
		end
		local parseInfo = {       
				[TAG_PLAYERNAME] = getPlayerName(cid),
			}
		msgout = npcHandler:parseMessage(parameters.text or parameters.message, parseInfo)
		selfSay(msgout)
		if(parameters.reset == true) then
			npcHandler:resetNpc()
		elseif(parameters.moveup ~= nil and type(parameters.moveup) == 'number') then
			npcHandler.keywordHandler:moveUp(parameters.moveup)
		end
		return true
	end

Npc:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end
	
local buyContainerNode = keywordHandler:addKeyword({'bp sd'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy a backpack of sudden death runes for 6000 gold?'})
	buyContainerNode:addChildKeyword({'yes'}, StdModule.buyContainer, {npcHandler = npcHandler, premium = true, cost = 6000, containerId = 2000, runeId = 2216, runeCharges = 1})
	buyContainerNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok, can I help you in anything else?'})
npcHandler:addModule(FocusModule:new())

Error:

doAddContainerItem() cant add item or somting like that.. my serevr get loads of these message
 
Last edited:
Heh, nice ;) I will try it on my server ; )

Yours,
polostap


OMFG I'M GETTING SOO ANGRY!!!

START READING IT SAIS IT DOSEN'T WORK, AND I WANT IT GETTING WORKED BUT NO-ONE IS HELPING.
THEN U COME AMD SAI "i'll try on my server" IT'S BUGGED AND IT'S GOING TO CRASH YOUR SERVER!

Stop TRYING TO GET THOSE FREE POSTS IF YOU DONT KNOW HOW TO FIX
 
Please close this thread.. i got this working without anyones help..
 
Status
Not open for further replies.
Back
Top Bottom