This won't work at all because you're not following the logic of the script. As I have said many times, scripting or coding in general is not about copy & paste or changing values...
I am not really interested in writing the code for you because you are not going to learn anything that way, so lets break down the logic of the script line by line so that you can see why you need to learn the language.
This particular function
scanContainer is only accessible within the curent script because it has been defined as a
local function.
It has 2 parameters
cid &
position, cid should be a number value & position should be a table of x,y,z coordinates
Lua:
local function scanContainer(cid, position)
Once the function is called and a value is passed to the cid parameter it is now known as an
argument. This argument is then passed to
Player which based on the information provided by cid may or maynot produce a player userdata
Lua:
local player = Player(cid)
The
if is asking whether
player (the condition) has a value if it does then the condition will return true or false however because there
is a
not in front of the condition (player) the not takes the return value of true or false returns the opposite.
So if the condition (in this case player) originally return true now it returns false and vice versa.
Essentially if it (the condition) is not a player then execute the next line and
return control back to whatever called this function
Lua:
if not player then
return
end
If player is a player continue on and pass the
position to
Tile and get the top most item (the corpse) at that position
and store that value in corpse (we are expecting userdata)
Lua:
local corpse = Tile(position):getTopDownItem()
So now this
if statement is checking to make sure that
corpse contains a value of some sorts, the
or logical operator will also check the 2nd condition
which is whether or not corpse is a container
Since both conditions have
not in front of them if either of them return a false value the not operator will make that condition true and execute the next
line which will return control back to whatever called it ending the execution of this portion of the script
Lua:
if not corpse or not corpse:isContainer() then
return
end
If all went well this if condition will check if the corpse (userdata) is indeed a valid corpse and if the corpse has a getAttribute flag ITEM_ATTRIBUTE_CORPSEOWNER (ownership) associated
with it that can be compared to the current player (the one who killed it) if both conditions return true then it will proceed forward to the next line of the script
if either return false then the function will end right here and return back to whatever called it. (yes I know there is no return statement)
Return is only used if there is an intended value return or you want to break execution of any following procedure
Lua:
if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then
Now we create a for loop using corpse container size since we validated that this userdata is indeed a container.
The iteration won't be starting at 1 instead it will be starting at the max amount of slots this container has - 1
An example is 20 slots, 20 - 1 = 19, so a will hold the initial value of 19 and it will count down to 0 at a step value of -1.. e.g. 19, 18, 17 etc
Lua:
for a = corpse:getSize() - 1, 0, -1 do
This next line uses the current number stored in a and passes it to corpse:getItem at the corpse's slot index of a and returns the item (userdata)
containerItem
Lua:
local containerItem = corpse:getItem(a)
This code here checks to see if containerItem holds a value
This code here takes AUTOLOOT_STORAGE_START as its starting point while storing each iteration original value AUTOLOOT_STORAGE_START
plus 1 into to b until it reaches the value of AUTOLOOT_STORAGE_END
Lua:
for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
Next this if statement will determine whether the condition its comparison of b being passed to player:getStorageValue if it equals containerItem:getId is true
if its false this part of the script will end right here and control will return back to whatever called this function
Lua:
if player:getStorageValue(b) == containerItem:getId() then
If everything went well up to this point then the containerItem (userdata) will execute the method moveTo and give the item to the player
Lua:
containerItem:moveTo(player)
Lua:
end -- closes the if statement
end -- closes the for loop
end -- closes the if statement
end -- closes the for loop
end -- closes the if loop
end -- closes the function
Now that you know how this part of the script executes, now you can use logic and determine where to execute code that will allow you to search for additional containers.