Hello Guys.
•¤•Description:•¤•
With this function you can give backpacks to players, but not normal backpacks.
Example: You can give the player a backpack with a carrot, another backpack and inside this backpack 5 gold coins and 3 ham and outside again in the first backpack 2 health potions. (Just example)
•¤•The Code:•¤•
Put the code in data/lib/function.lua (at the end)
•¤•How to use:•¤•
Example:
This is an example from my war server. The player get a backpack and inside are a backpack with 2 potions,a backpack with some runes(which have 5 charges all), some rings and a rope.
list is the list of items which should be added.
Just put like {item,item,container,{array with items to put in the container},item again,container,{again items inside container}}
startbp is the backpack all things should be added to. You need to use the unique id of an item. (You can use "doPlayerAddItem(cid,containerID,1)" or "getPlayerSlotItem(cid,3)" and such too)
count is the amount of every item. This is an array one by one. Just go through the list array you made and put the count you want in count array.
--> Look at the example how its made.
You can leave the count array out and every item will be added once.
•¤•Bugs:•¤•
Rep+ if anyone can fix it!
-If you want to add a container and only put 1 thing in it the script bugs.
-Maybe some endless loops if it is set up wrong. (but while testing I found nothing)
•¤•Credits:•¤•
~Me
~My brain for helping me
~The one whole will fix the bugs..
•¤•Notes:•¤•
-if you have question post them here
-the script is very complicated and if you don't understand a part ask (I didn't know how it should work after I did it xD)
-it is hard to explain how it must be set up, so if you want me to make some examples tell me and I will try
Yours,
•¤•Rhux/Summ
Btw. do you like my tabbing?
•¤•Description:•¤•
With this function you can give backpacks to players, but not normal backpacks.
Example: You can give the player a backpack with a carrot, another backpack and inside this backpack 5 gold coins and 3 ham and outside again in the first backpack 2 health potions. (Just example)
•¤•The Code:•¤•
Put the code in data/lib/function.lua (at the end)
Code:
function setLevel(var,count,lvl) -- don't mind this function or its name
local var = var
for i = 1,(lvl-1) do
if i ~= lvl then
var = var[count[(i)]]
else
var = var[count[(i+1)]]
end
end
return var
end
function addAdvancedBackpack(cid,startbp,list,count)
local s,lvl = 1,1
local count = type(count) == "table" and count or {}
local save = list
local lastcreated,localbp = startbp,startbp
local run = 1
local counter,bpuid = {},{}
counter[1] = 1
bpuid[1] = startbp
while 1 do
if type(list[s]) == "number" then
if list[(s+1)] then
lastcreated = doAddContainerItem(localbp, list[s],(isNumber(count[run]) == true and count[run] or 1))
s = s+1
else
lastcreated = doAddContainerItem(localbp, list[s],(isNumber(count[run]) == true and count[run] or 1))
while 1 do
if check == 1 then
check = 0
break
else
lvl = lvl > 1 and lvl-1 or "end"
if lvl == "end" then
return true
end
list = setLevel(save,counter,(lvl))
s = counter[(lvl)]+1
localbp = bpuid[(lvl)]
if list[s] ~= nil then
check = 1
end
end
end
end
elseif type(list[s]) == "table" then
list = list[s]
counter[lvl] = (s)
lvl = lvl + 1
bpuid[lvl] = lastcreated
s = 1
doAddContainerItem(lastcreated, list[s],(isNumber(count[run]) == true and count[run] or 1))
s = s+1
localbp = lastcreated
else
return true
end
run = (run+1)
end
return true
end
•¤•How to use:•¤•
Example:
Code:
function onLogin(cid)
local startback = doPlayerAddItem(cid,9774,1)
local list = {2000,{7590,7589},2003,{2261,2305,2313,2293,2274,2273,2268}}
local count = {1,1,1,1,5,5,5,5,5,5,5}
addAdvancedBackpack(cid,startbp,list,count)
return true
end
This is an example from my war server. The player get a backpack and inside are a backpack with 2 potions,a backpack with some runes(which have 5 charges all), some rings and a rope.
list is the list of items which should be added.
Just put like {item,item,container,{array with items to put in the container},item again,container,{again items inside container}}
startbp is the backpack all things should be added to. You need to use the unique id of an item. (You can use "doPlayerAddItem(cid,containerID,1)" or "getPlayerSlotItem(cid,3)" and such too)
count is the amount of every item. This is an array one by one. Just go through the list array you made and put the count you want in count array.
--> Look at the example how its made.
You can leave the count array out and every item will be added once.
•¤•Bugs:•¤•
Rep+ if anyone can fix it!
-If you want to add a container and only put 1 thing in it the script bugs.
-Maybe some endless loops if it is set up wrong. (but while testing I found nothing)
•¤•Credits:•¤•
~Me
~My brain for helping me
~The one whole will fix the bugs..
•¤•Notes:•¤•
-if you have question post them here
-the script is very complicated and if you don't understand a part ask (I didn't know how it should work after I did it xD)
-it is hard to explain how it must be set up, so if you want me to make some examples tell me and I will try
Yours,
•¤•Rhux/Summ
Btw. do you like my tabbing?
Last edited: