- Joined
- Nov 17, 2010
- Messages
- 6,796
- Solutions
- 581
- Reaction score
- 5,360
This function allows you to give a player infinite items with one simple function.
Function fully created by Xikini.
Tested and working for TFS 0.3.7.
Will likely work for 0.3.6 and 0.4, with no issues.
If someone wants to convert the scant amount of actual functions for TFS 1.0+, please do so.
13:02 You have found a backpack weighing 134280.00 oz.
Unique items in table: 10371. Function took 1.446 seconds to complete.
13:03 You have found a backpack weighing 69804.00 oz.
Unique items in table: 5391. Function took 0.481 seconds to complete.
13:04 You have found a backpack weighing 14114.00 oz.
Unique items in table: 1090. Function took 0.078 seconds to complete.
13:04 You have found a backpack weighing 630.00 oz.
Unique items in table: 48. Function took 0.026 seconds to complete.
13:05 You have found a bag weighing 20.00 oz.
Unique items in table: 1. Function took 0.001 seconds to complete.
Install location for TFS 0.3.7
data/lib/050_function.lua [anywhere that is not inside another function]
This script is a direct result of this this script that I gave to the community awhile ago.
I didn't know how to script infinite items back then, and it's forever bugged me.
This will probably be my last large contribution to the community.
I have to actually focus on my friends server, or we will never finish it.
Cheers,
Xikini
Function fully created by Xikini.
Tested and working for TFS 0.3.7.
Will likely work for 0.3.6 and 0.4, with no issues.
If someone wants to convert the scant amount of actual functions for TFS 1.0+, please do so.
Function will check if player has capacity to receive item(s).
Function will check if player has room in inventory to receive item(s).
The items will automatically be placed into a bag or backpack, based on how many items are given to the player.
When items exceed capacity of container the script will place excess items into a new appropriate container. (bag/backpack)
If items exceed capacity of the new container the script will place excess items into another new appropriate container. (loops infinitely, until all items are given to player.)
Function will check if player has room in inventory to receive item(s).
The items will automatically be placed into a bag or backpack, based on how many items are given to the player.
When items exceed capacity of container the script will place excess items into a new appropriate container. (bag/backpack)
If items exceed capacity of the new container the script will place excess items into another new appropriate container. (loops infinitely, until all items are given to player.)
Lua:
local function giveReward(cid, table_location)
local milliseconds = os.mtime()
local item_count_in_table = #table_location
.
.
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a " .. getItemNameById(c_[1]) .. " weighing ".. string.format("%.2f", weight) .." oz.\nUnique items in table: " .. item_count_in_table .. ". Function took " .. (os.mtime() - milliseconds)/1000 .. " seconds to complete.")
13:02 You have found a backpack weighing 134280.00 oz.
Unique items in table: 10371. Function took 1.446 seconds to complete.
13:03 You have found a backpack weighing 69804.00 oz.
Unique items in table: 5391. Function took 0.481 seconds to complete.
13:04 You have found a backpack weighing 14114.00 oz.
Unique items in table: 1090. Function took 0.078 seconds to complete.
13:04 You have found a backpack weighing 630.00 oz.
Unique items in table: 48. Function took 0.026 seconds to complete.
13:05 You have found a bag weighing 20.00 oz.
Unique items in table: 1. Function took 0.001 seconds to complete.
Lua:
local table_name = {
{1111, 11}, -- item_id, item_count
{2222, 22}, -- item_count rules: stackable max is 100. NON-stackable max is 1.
{3333, 33} -- if you don't adhere to the above cautionary rules, YOU WILL RECEIVE a massive amount of errors.
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if giveReward(cid, table_location) == true then
print("success")
else
print("failed")
end
return true
end
Lua:
local other_table = {
["vocation_1"] = {storage = 1111, reward = {{1111, 11}, {2222, 22}, {3333, 33}} },
["vocation_2"] = {storage = 1111, reward = {{1111, 11}, {2222, 22}, {3333, 33}} }
-- you can setup your table however you want to
-- just provide the correct table location in your script
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local x = other_table["" .. getPlayerVocationName(cid):lower() .. ""]
if x then
if getPlayerStorageValue(cid, x.storage) < 1 then
if giveItemsFromTable(cid, x.reward) == true then
setPlayerStorageValue(cid, x.storage, 1)
print("success")
end
else
print("failed")
end
end
return true
end
Install location for TFS 0.3.7
data/lib/050_function.lua [anywhere that is not inside another function]
Lua:
function giveItemsFromTable(cid, table_location)
local item_count_in_table = #table_location
local reward_count = 0
local tmp = 0
local weight = 8
local c_ = {}
local v = 2
c_[v - 1] = 1987
if item_count_in_table > 8 then
c_[v - 1] = 1988
weight = 18
end
c_[v] = doCreateItemEx(c_[1], 1)
if item_count_in_table > 20 then
repeat
tmp = 1987
v = v + 1
if item_count_in_table > 20 * (v - 2) + 8 - (v - 2) then
tmp = 1988
weight = weight + 10
end
weight = weight + 8
c_[v] = doAddContainerItem(c_[v - 1], tmp, 1)
if tmp == 1988 and item_count_in_table < 20 * (v - 1) - (v - 3) or tmp == 1987 then
v = 0
end
until v == 0
end
v = 2
for n = 1, #c_ do
tmp = 20
if c_[v + 1] then
tmp = 19
end
for m = 1, tmp do
reward_count = reward_count + 1
tmp = table_location[reward_count]
if tmp then
doAddContainerItem(c_[v], tmp[1], tmp[2])
weight = weight + getItemWeightById(tmp[1], tmp[2])
else
break
end
end
v = v + 1
end
if doPlayerAddItemEx(cid, c_[2], false) == RETURNVALUE_NOERROR then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a " .. getItemNameById(c_[1]) .. " weighing ".. string.format("%.2f", weight) .." oz.")
return true
else
local cap = getPlayerFreeCap(cid)
if cap < weight then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Require " .. string.format("%.2f", weight - cap) .. " more capacity to receive this reward weighing ".. string.format("%.2f", weight) .." oz.")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You require more inventory space to receive this reward.")
end
end
return false
end
This script is a direct result of this this script that I gave to the community awhile ago.
I didn't know how to script infinite items back then, and it's forever bugged me.
This will probably be my last large contribution to the community.
I have to actually focus on my friends server, or we will never finish it.
Cheers,
Xikini