• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Largest value within an array.

milbradt

New Member
Joined
Dec 25, 2011
Messages
177
Solutions
1
Reaction score
4
Example +-... =S

Code:
local potion = {
  [1111] = {
  damage = 850,
  def = 450
  },
  [1112] = {
  damage = 600,
  def = 500
  }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if toPosition:getTile() then
     if itemEx.potion[getItemById(potion.damage)] > item.potion[getItemById(potion.damage)] then
       toPosition:sendMagicEffect(11)
     else
       toPosition:sendMagicEffect(32)
     end
   end
  
   return true
end
 
could you explain it better?
thank you
Yea

I want to check the damage value of the two items.
If the damage of the item you'll use is greater than the hit item. My english it's bad =\ Srry

Example..
wk4lb1i.png
 
ah, I see. potion is a table, so it's accessed by using potion[1111].damage as an example. you're trying to call potion as an attribute of item or itemEx which are not available attributes on those objects.
Code:
if itemEx.potion[getItemById(potion.damage)] > item.potion[getItemById(potion.damage)] then
this should be more like
Code:
if potion[getItemById(itemEx)].damage > potion[getItemById(item)].damage then
since you're accessing the table by item id, you'd have to set the table values to the ids of the potions like this (strong health and strong mana potions)
Code:
local potion = {
[7588] = {
damage = 850,
def = 450
},
[7589] = {
damage = 600,
def = 500
}
}
but I'm not sure I understand what you're trying to achieve. Are you using a potion on another potion?
For further assistance please explain better what you're trying to achieve and provide information like what server distro you're using (if TFS, is it 0.2? 0.3? 0.4? 1.x?
 
adding up to RazorBlade question:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
item = its the item you use (right mouse click)
itemEx = its the item you use at (use with crosshair, for example)
 
adding up to RazorBlade question:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
item = its the item you use (right mouse click)
itemEx = its the item you use at (use with crosshair, for example)
I understand what the function is for :P
Just trying to figure out what you're trying to achieve
 
ah, I see. potion is a table, so it's accessed by using potion[1111].damage as an example. you're trying to call potion as an attribute of item or itemEx which are not available attributes on those objects.
Code:
if potion[getItemById(itemEx)].damage > potion[getItemById(item)].damage then
but I'm not sure I understand what you're trying to achieve. Are you using a potion on another potion?
For further assistance please explain better what you're trying to achieve and provide information like what server distro you're using (if TFS, is it 0.2? 0.3? 0.4? 1.x?

Yes, using a potion on another potion.
I tested it, and it looks like it worked. Thanks man!!!!!

Using tfs 1.2
 
Back
Top