• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC [Module] BuyContainer For Forgotten Server!!

Just to let people stop whining i'll release my advanced one...
 
The best way for buy container(bp with rune or something):
working on TFS.

in file global.lua
change this function

from
PHP:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
	if(doPlayerRemoveMoney(cid, cost) == TRUE) then
		return doPlayerGiveItem(cid, itemid, count, charges)
	end
	return LUA_ERROR
end

to
PHP:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
    if(type(itemid) == "table") then
	cost = cost*count
	end
    if(doPlayerRemoveMoney(cid, cost) == TRUE) then
		if(type(itemid) == "table") then
		y = 0
		while y < count do
		bp = doPlayerAddItem(cid, itemid[1], 1)
		x = 0
		
		while x < itemid[4] do
			doAddContainerItem(bp, itemid[2], itemid[3])
			x = x + 1
		end
		y = y + 1
		end
		return LUA_NO_ERROR
else
    	return doPlayerGiveItem(cid, itemid, count, charges)
	end
    else
        return LUA_ERROR
    end
end

sample rune shop:

shopModule:addBuyableItem({'bp uh'}, {1988, 2273, 1, 20}, 20*150, 'bp of ultimate healing runes')

where:
1988 - is bp
2273 - uh rune
1 - charges in uh rune
20 - amount runes in bp
20*150 (20 runes * price 150gp each)

supported buy more than one bp.. buy 3 bp uh...
 
The best way for buy container(bp with rune or something):
working on TFS.

in file global.lua
change this function

from
PHP:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
	if(doPlayerRemoveMoney(cid, cost) == TRUE) then
		return doPlayerGiveItem(cid, itemid, count, charges)
	end 
	return LUA_ERROR
end

to
PHP:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
    if(type(itemid) == "table") then
	cost = cost*count
	end
    if(doPlayerRemoveMoney(cid, cost) == TRUE) then
		if(type(itemid) == "table") then
		y = 0
		while y < count do
		bp = doPlayerAddItem(cid, itemid[1], 1)
		x = 0
		
		while x < itemid[4] do
			doAddContainerItem(bp, itemid[2], itemid[3])
			x = x + 1
		end
		y = y + 1
		end
		return LUA_NO_ERROR
else
    	return doPlayerGiveItem(cid, itemid, count, charges)
	end
    else
        return LUA_ERROR
    end
end

sample rune shop:

shopModule:addBuyableItem({'bp uh'}, {1988, 2273, 1, 20}, 20*150, 'bp of ultimate healing runes')

where:
1988 - is bp
2273 - uh rune
1 - charges in uh rune
20 - amount runes in bp
20*150 (20 runes * price 150gp each)

supported buy more than one bp.. buy 3 bp uh...

That's nice but i prefer to make an neew function because i dont want to make unessesery bugs,mine is bigger but's its easyer yo overlook
 
Code:
function StdModule.buyContainer(cid, message, keywords, parameters, node)
	if(cid ~= npcHandler.focus) then
		return false
	end
	local bpID, runeID, cost, charges = parameters[1], parameters[2], parameters[3], parameters[4]
	if(doPlayerRemoveMoney(cid, cost) ~= TRUE) then
		selfSay('You do not have enough money!')
	else		
		if(isContainer(bpID) == TRUE) then
			local containerID = doPlayerAddItem(cid, bpID, 1)
			while getContainerSize(bpID) ~= 20 do
				doAddContainerItem(containerId, runeID, charges)
			end
		end
	end
	return true
end

Example:
SDNode:addChildKeyword({'yes'}, StdModule.buyContainer, {BpID, runeId, Cost, Charges, 'Back Pack of sudden death'})

Please don't ask for rep in exchange for your scripts, It's lame, annoying and useless.

Note: I haven't tested this script, but if it does not work, please PM me and I'll try and figure out what's wrong.

Sorry about not adding capacity check, decided that'll just be more work for the scripter that's making the NPC. I might make an edit with a capacity check with a default rune cap as 1.2 oz and editable using parameters... Anyways, I think this is good for now, just to burst Mokerhammer's bubble.
 
Last edited:
Viorka said:
PHP:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
    ........
end

sample rune shop:

shopModule:addBuyableItem({'bp uh'}, {1988, 2273, 1, 20}, 20*150, 'bp of ultimate healing runes')

where:
1988 - is bp
2273 - uh rune
1 - charges in uh rune
20 - amount runes in bp
20*150 (20 runes * price 150gp each)

supported buy more than one bp.. buy 3 bp uh...<<FIX IT!

THANK YOU! It really help me. Rep+ ;)
EDIT--------------------EDIT-----------EDIT----------
@I FOUND BUG IN YOUR CODE "Viorka":
when i buy 1 BP with 20 runes for 800gp/each npc take 16k from my bp, when i buy 2 bp npc take 64 k (cash for 4 bp), when i buy 16 bp npc take 4kk+, but always first he say "18:07 Runeiro: Czy chcesz kupic 16 bp of multi sd za 256000 GP?" (16000gp - bp, 32000-2bp - always good price) and when i say "yes" he take his "price*numer of bp" (256000*16= 4kk+)
How to fix it:
change:
Code:
cost = cost*count
to:
Code:
cost = cost
Fixed code of "Viorka":
Code:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
    if(type(itemid) == "table") then
    cost = cost
    end
    if(doPlayerRemoveMoney(cid, cost) == TRUE) then
        if(type(itemid) == "table") then
        y = 0
        while y < count do
        bp = doPlayerAddItem(cid, itemid[1], 1)
        x = 0
        
        while x < itemid[4] do
            doAddContainerItem(bp, itemid[2], itemid[3])
            x = x + 1
        end
        y = y + 1
        end
        return LUA_NO_ERROR
else
        return doPlayerGiveItem(cid, itemid, count, charges)
    end
    else
        return LUA_ERROR
    end
end
/\ Tested by me. Work fine with 1 and more BPs/runes.
 
Last edited:
THANK YOU! It really help me. Rep+ ;)
EDIT--------------------EDIT-----------EDIT----------
@I FOUND BUG IN YOUR CODE "Viorka":

How to fix it:
change:
Code:
cost = cost*count
to:
Code:
cost = cost
Fixed code of "Viorka":
Code:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
    if(type(itemid) == "table") then
    cost = cost
    end
    if(doPlayerRemoveMoney(cid, cost) == TRUE) then
        if(type(itemid) == "table") then
        y = 0
        while y < count do
        bp = doPlayerAddItem(cid, itemid[1], 1)
        x = 0
        
        while x < itemid[4] do
            doAddContainerItem(bp, itemid[2], itemid[3])
            x = x + 1
        end
        y = y + 1
        end
        return LUA_NO_ERROR
else
        return doPlayerGiveItem(cid, itemid, count, charges)
    end
    else
        return LUA_ERROR
    end
end
/\ Tested by me. Work fine with 1 and more BPs/runes.

actually i'v already released an advanced butcontainer thatw orks way bether then this one
 
I tried to add your advanced containter, but server show errors :>
This code is easier.
 
you shall not just ask for rep like that, rep points is not for "give rep and i release" it's for a good release...
 
I will not give you rep just because you asked for it.
I think people sould want to give reputation and not give because people beg for it.
I doubt you will get 15 rep in one WEEK.
 
Back
Top