• 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 [Module] BuyContainer For Forgotten Server!!

Mokerhamer

Retired Global Mod
Senator
Joined
Aug 6, 2007
Messages
1,767
Reaction score
35
Hi,


I'v made this function because the old buycontainer was way to big and you couldent make it compare with the new buy RUne npcs.

Some points about my buycontainer:
-You can use it with the newest Jiddo Npc system (V3.0)
-You can only buy 1 backpack at the time
-Yes it's weard

And no!, I wont release my advanced buyContainer function only this buycontainer.. since no one is giving me rep -.-"

Lets begin!!

Add this ABOVE "function StdModule.say(cid, message, keywords, parameters, node) in modules.lua"

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) then
			return false
		end	
		   if(doPlayerRemoveMoney(cid, parameters.cost) ~= TRUE) then
			selfSay('You do not have enough money!')
			else		
			local containerId = doPlayerAddItem(cid, parameters.containerId, 1)
			if isContainer(containerId) == TRUE then
				while getContainerSize(containerId) ~= 20 do
					doAddContainerItem(containerId, parameters.runeId, parameters.runeCharges)
			 end
			 end
		return true
    end
	end

Npc Code (it's an working example):
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())

Credits:
-Pedro B (Helped with some bugs)
-Mokerhamer (Scripted)
-Jiddo? (I forgot if he helped with this function or the other one:eek:)


Not Released buyContainer function unless i got 15+ rep in 1 weak
as i said i wont release my advanced buyContainer version unless i get atleast 15 COUNTING rep in 1 weak.

How does my advanced buyContainer work?
-You can buy Multi backpacks at 1 time
-Checks cap, and if you have enoughe place in your backpack
-And you can use my advanced buyContainer with 1 line likt this.
shopModule:buyContainer({'crap', 'bp sd'},
Code:
BpID, runeId, Cost, Charges,  	'Back Pack of sudden death')

Yours,
Mokerhamer
 
Hey my friend! :)

Very nice work there! Thanks for release :)


Your LajNuZ ;)
 
yeah thanks for the script but u shouldnt ask for rep. :X
 
Asking for 15 rep is Lame...
If everybody is going to ask for it it will annoy people and then they will give - REP because you beg for it..

Edit: that advanced code looks very good and i bet if you released it you get many rep and thnx for it. But if you release something like this you can't expect that everybody will rep you for it.
 
Last edited:
Done ;)
Good job mate.

Thank you :p glad to see more and more people using it


anywais who gave me a rep and said stop leaking scripts to the public.. i cant see the names of the people who give me rep..
 
Last edited:
Yes now you can buy backpack of runes =)

How Do I add more different kinds of backpacks to be sold?

Like this?
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() 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 = 1988, runeId = 2268, runeCharges = 10})
SDNode:addChildKeyword({'no'}, StdModuel.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok, can I help you in anything else?'})

local SDNode = keywordHandler:addKeyword({'bp uh', 'backpack of uh', 'backpack of ultimate healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy a backpack of ultimate healing runes for 3000 gold?'})
SDNode:addChildKeyword({'yes'}, StdModule.buyContainer, {npcHandler = npcHandler, onlyFocus = true, cost = 3000, containerId = 1988, runeId = 2273, runeCharges = 10})
SDNode:addChildKeyword({'no'}, StdModuel.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok, can I help you in anything else?'})

npcHandler:addModule(FocusModule:new())



OR CAN YOU GIVE A SAMPLE NPC!?
 
Last edited:
How Do I add more different kinds of backpacks to be sold?

Like this?

I'm not sure try it i use an diferent Buycontainer functions that i made.. mine works like this


Code:
shopModule:[COLOR="Red"]buyContainer[/COLOR]({'bp sd'}, 	             2003, 2268, 3000, 1,  	'Backpack of sudden death')
shopModule:[COLOR="Red"]buyContainer[/COLOR]({'bp uh'}, 	             2003, 2273, 1000, 1,  	'Backpack of ultimate healing')
shopModule:[COLOR="Red"]buyContainer[/COLOR]({'bp ih'}, 	             2003, 2265, 300, 1,  	'Backpack of intense healing')
 
I'm not sure try it i use an diferent Buycontainer functions that i made.. mine works like this


Code:
shopModule:[COLOR="Red"]buyContainer[/COLOR]({'bp sd'}, 	             2003, 2268, 3000, 1,  	'Backpack of sudden death')
shopModule:[COLOR="Red"]buyContainer[/COLOR]({'bp uh'}, 	             2003, 2273, 1000, 1,  	'Backpack of ultimate healing')
shopModule:[COLOR="Red"]buyContainer[/COLOR]({'bp ih'}, 	             2003, 2265, 300, 1,  	'Backpack of intense healing')

You put this in the NPC File?
Not the script right?


I have this so far:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end
-- OTServ event handling functions end

shopModule:buyContainer({'bp sd'}, 2003, 2268, 3000, 1, 'Backpack of sudden death')
shopModule:buyContainer({'bp uh'}, 2003, 2273, 1000, 1, 'Backpack of ultimate healing')
shopModule:buyContainer({'bp ih'}, 2003, 2265, 300, 1, 'Backpack of intense healing')

npcHandler:addModule(FocusModule:new())

Still not working, can you just post your whole script please :(
 
You put this in the NPC File?
Not the script right?


I have this so far:


Still not working, can you just post your whole script please :(

U dident get it i'm using an advanced BuyCOntainer i never released my advanced only my crappy one :p You should us ethe way how i posted it here..


maby like thid?
Code:
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 = 1988, runeId = 2268, runeCharges = 10})
SDNode:addChildKeyword({'no'}, StdModuel.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok, can I help you in anything else?'})

local SDNode[COLOR="Red"]1[/COLOR] = keywordHandler:addKeyword({'bp uh', 'backpack of uh', 'backpack of ultimate healing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy a backpack of ultimate healing runes for 3000 gold?'})
SDNode[COLOR="Red"]1[/COLOR]:addChildKeyword({'yes'}, StdModule.buyContainer, {npcHandler = npcHandler, onlyFocus = true, cost = 3000, containerId = 1988, runeId = 2273, runeCharges = 10})
SDNode[COLOR="Red"]1[/COLOR]:addChildKeyword({'no'}, StdModuel.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok, can I help you in anything else?'})

npcHandler:addModule(FocusModule:new())
I'v heart somting about u can add "1/2/3/4etc" after it.. but let em think in witch npc it was
 
Last edited:
Spelling error. script doesnt work. when i put the text in modules.lua my whole serv goes crazy and just crashes b4 it finishes loading the map.

can u just either put out the advanced one. or edit the crappy one so it works. and sells more then just sd runes. Cause a script as flawed as this really doesnt deserve rep. AT ALL

SDNode:addChildKeyword({'no'}, >>>>>>>>StdModuel<<<<<<<.say
 
Guys... Hes demanding rep. What If. We black mail him, GIVE US ADVANCED BUYCONTAINER OR - REP!

~takes down mokers rep by 1~ Ahuhauhauhua
 
Moker's dont work use this one

Add this to data/npc/lib/npc.lua

PHP:
function buyContainer(cid, container, itemid, count, money)
	if doPlayerRemoveMoney(cid, money) == 1 then
		bp = doPlayerAddItem(cid, container, 1)
		x = 0
		
		while x < 20 do
			doAddContainerItem(bp, itemid, count)
			x = x + 1
		end
		
		selfSay('Here you are.')
	else
		selfSay('Sorry, you don\'t have enough money.')
	end
end

And use this script:

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

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if(npcHandler.focus ~= cid) then
        return false
    end

        if msgcontains(msg, 'bp of sd') or msgcontains(msg, 'backpack sd') or msgcontains(msg, 'backpack of sudden death runes') then
            selfSay('Do you want buy bacpack of sudden death runes for 9000gp?')
            talk_state = 1
        elseif msgcontains(msg, 'bp of uh') or msgcontains(msg, 'backpack uh') then
            selfSay('Do you want buy backpack of ultimate healing runes for 6500gp?')
            talk_state = 2
        elseif msgcontains(msg, 'bp of explo') or msgcontains(msg, 'backpack explo') or msgcontains(msg, 'bp explosion') or msgcontains(msg, 'bacpack explosion') then
            selfSay('Do you want buy bacpack of explosion runes for 8000gp?')
            talk_state = 3
        elseif msgcontains(msg, 'bp of hmm') or msgcontains(msg, 'backpack hmm') then
            selfSay('Do you want buy backpack of heavy magic missile runes for 5000gp?')
            talk_state = 4
        elseif msgcontains(msg, 'bp of gfb') or msgcontains(msg, 'backpack gfb') then
            selfSay('Do you want buy backpack of great fireball runes for 7000gp?')
            talk_state = 5
        elseif msgcontains(msg, 'bp of manafluid') then
            selfSay('Do you want buy backpack of manafluids for 2000gp?')
            talk_state = 6
------------------------------------------------ confirm yes ------------------------------------------------
			elseif msgcontains(msg, 'yes') and talk_state == 1 then
                    buyContainer(cid,5926,2268,5,9000)
                talk_state = 0
            
			elseif msgcontains(msg, 'yes') and talk_state == 2 then
                    buyContainer(cid,5949,2273,5,6500)
            talk_state = 0
            
			elseif msgcontains(msg, 'yes') and talk_state == 3 then
                    buyContainer(cid,2000,2313,15,8000)
            talk_state = 0
            
			elseif msgcontains(msg, 'yes') and talk_state == 4 then
                    buyContainer(cid,2001,2311,5,5000)
            talk_state = 0
            
			elseif msgcontains(msg, 'yes') and talk_state == 5 then
                    buyContainer(cid,2000,2304,2,7000)
            talk_state = 0
            
            elseif msgcontains(msg, 'yes') and talk_state == 6 then
                    buyContainer(cid,2001,2006,7,2000)
            talk_state = 0
------------------------------------------------ confirm no ------------------------------------------------
        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 6) then
            selfSay('Ok than.')
            talk_state = 0
        end

    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

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

@ Mokerhamer

Unlike your dodgy script. mine works. and unlike you, I might get rep for it :)

Ahahahaha 4 posts and i probably have more rep than you :)
 
Back
Top