• 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 Problem new damage system (distance - bows/crossbows)

dudie

Member
Joined
May 23, 2016
Messages
128
Reaction score
12
I made this script with help to you from forum to new damage system
weapons/scripts/distance_damage.lua
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
   --min = ((0.08) * (attack) * (skill)) * -1
   --max = ((0.08) * (attack) * (skill)) * -1
   --print(skill)
   print(attack)
   min = ((attack) * (100)) * -1
   max = ((attack) * (100)) * -1
   return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
   return doCombat(cid, combat, var)
end

It's work fine to royal spears for exemple... print fine (35)
Assassin star print 65, fine work too


But bows and arrows i have a problem...
I want attack be arrow attack + bow attack

Using bow
Code:
16:44 You see a bow (Range:6, Atk +1).
It weighs 31.00 oz.
ItemID: [2456].

Code:
<item id="2544" article="an" name="arrow" plural="arrows">
   <attribute key="weight" value="10" />
   <attribute key="slotType" value="ammo" />
   <attribute key="attack" value="30" />
   <attribute key="maxHitChance" value="90" />
   <attribute key="weaponType" value="ammunition" />
   <attribute key="ammoType" value="arrow" />
   <attribute key="shootType" value="arrow" />
   <attribute key="ammoAction" value="removecount" />
</item>

print only 30 and not 31

I want print bow atk + arrow atk

For exemple if bow is attack 20 and arrow is attack 30...
Total attack on script is 50


weapons.xml
Code:
   <!-- mage & paladin -->
   <distance id="2456" unproperly="1" swing="true" event="script" value="distance_damage.lua" /> <!-- bow -->
   <!-- paladin -->
   <distance id="2455" unproperly="1" swing="true" event="script" value="distance_damage.lua"> <!-- crossbow -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="7438" unproperly="1" swing="true" event="script" value="distance_damage.lua"> <!-- elvish bow -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="5803" unproperly="1" swing="true" event="script" value="distance_damage.lua" /> <!-- arbalest -->
   <distance id="5907" unproperly="1" swing="true" event="script" value="distance_damage.lua" /> <!-- slingshot -->
   <distance id="1294" unproperly="1" swing="true" event="script" value="distance_damage.lua" /> <!-- small stone -->
   
   <distance id="8849" unproperly="1" swing="true" event="function" value="default"> <!-- Modified Crossbow -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="8850" unproperly="1" swing="true" event="function" value="default"> <!-- Chain Bolter -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="8853" unproperly="1" swing="true" event="function" value="default"> <!-- Ironworker -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="8852" unproperly="1" swing="true" event="function" value="default"> <!-- Devileye -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="8851" unproperly="1" swing="true" event="function" value="default"> <!-- Royal Crossbow -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="8857" unproperly="1" swing="true" event="function" value="default"> <!-- Silkweaver Bow -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="8855" unproperly="1" swing="true" event="function" value="default"> <!-- Composite Hornbow -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="8858" unproperly="1" swing="true" event="function" value="default"> <!-- Elethriel's Elemental Bow -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>
   <distance id="8854" unproperly="1" swing="true" event="function" value="default"> <!-- Warsinger Bow -->
     <vocation id="3"/>
     <vocation id="7" showInDescription="0"/>
     <vocation id="11" showInDescription="0"/>
   </distance>

   <!-- Ammunition -->
   <distance id="2545" swing="true" event="script" value="poison_arrow.lua"/>
   <distance id="2546" swing="true" event="script" value="burst_arrow.lua"/>
   <distance id="7366" swing="true" event="script" value="viper_star.lua"/>
   <distance id="7838" swing="true" type="energy" event="script" value="distance_damage.lua"/>
   <distance id="7839" swing="true" type="ice" event="script" value="distance_damage.lua"/>
   <distance id="7840" swing="true" type="fire" event="script" value="distance_damage.lua"/>
   <distance id="7850" swing="true" type="earth" event="script" value="distance_damage.lua"/>
   <distance id="3965" swing="true" event="script" value="distance_damage.lua"/> <!-- Hunting Spear -->
   <distance id="7378" swing="true" event="script" value="distance_damage.lua"/> <!-- Royal Spear -->
   <distance id="7367" swing="true" event="script" value="distance_damage.lua"/> <!-- Enchanted Spear -->
   <distance id="7368" swing="true" event="script" value="distance_damage.lua"/> <!-- Assassin Star -->
   <distance id="7364" swing="true" event="script" value="distance_damage.lua"/> <!-- Sniper Arrow -->
   <distance id="7365" swing="true" event="script" value="distance_damage.lua"/> <!-- Onyx Arrow -->
   <distance id="7363" swing="true" event="script" value="distance_damage.lua"/> <!-- Piercing Bolt -->
   <distance id="2547" swing="true" event="script" value="distance_damage.lua"/> <!-- Power Bolt -->
   <distance id="6529" swing="false" event="script" value="distance_damage.lua"/> <!-- Infernal Bolt -->
   <distance id="2544" swing="true" event="script" value="distance_damage.lua"/> <!-- Arrow -->
   <distance id="2543" swing="true" event="script" value="distance_damage.lua"/> <!-- Bolt -->
 
i believe you have to get bow attack from fetching player slot from cid

I tried... But so much errors
I tried:
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
   --min = ((0.08) * (attack) * (skill)) * -1
   --max = ((0.08) * (attack) * (skill)) * -1
   --print(skill)
   print(attack)
   -- get weapon attack (bow/crossbow)
   local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
   local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
   local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
   if item1.uid ~= 0 then
     hand1 = getItemInfo(item1.uid).attack
   end
   if item2.uid ~= 0 then
     hand2 = getItemInfo(item2.uid).attack
   end
   if hand1 > hand2 then
     bowattack = hand1
   else
     bowattack = hand2
   end
   print(bowattack)
   atktotal = bowattack + attack
   print(atktotal)
   min = ((atktotal) * (100)) * -1
   max = ((atktotal) * (100)) * -1
   return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
   return doCombat(cid, combat, var)
end

Errors:
Code:
[18:53:38.077] [Error - Weapon Interface]
[18:53:38.077] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:53:38.077] (Unknown script file)
[18:53:38.077] Description:
[18:53:38.077] data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
30

[18:53:54.250] [Error - Weapon Interface]
[18:53:54.250] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:53:54.250] (Unknown script file)
[18:53:54.250] Description:
[18:53:54.250] data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
30

[18:53:58.362] [Error - Weapon Interface]
[18:53:58.362] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:53:58.362] (Unknown script file)
[18:53:58.362] Description:
[18:53:58.362] data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
30

[18:54:00.369] [Error - Weapon Interface]
[18:54:00.369] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:54:00.369] (Unknown script file)
[18:54:00.369] Description:
[18:54:00.369] data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
 
data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
A boolean value is a value which contains true or false or considers 1 or 0 as boolean.

"attempt to index" means, you can not access a property of something which is not a table.
Example
Code:
true.uid -- returns "attempt to index a boolean value"
false.uid -- returns "attempt to index a boolean value"

Your error is on line 15
data/weapons/scripts/distance_damage.lua:15
 
The way to trouble shoot issues like this is to use type in conjunction with print.
Example
Code:
print(type(getPlayerSlotItem(cid, CONST_SLOT_LEFT)), getPlayerSlotItem(cid, CONST_SLOT_LEFT), getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid, getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid)
Do the same for CONST_SLOT_RIGHT.

 
The way to trouble shoot issues like this is to use type in conjunction with print.
Example
Code:
print(type(getPlayerSlotItem(cid, CONST_SLOT_LEFT)), getPlayerSlotItem(cid, CONST_SLOT_LEFT), getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid, getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid)
Do the same for CONST_SLOT_RIGHT.
people need to utilize troubleshooting with massive amounts of printing much more..
 
data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
A boolean value is a value which contains true or false or considers 1 or 0 as boolean.

"attempt to index" means, you can not access a property of something which is not a table.
Example
Code:
true.uid -- returns "attempt to index a boolean value"
false.uid -- returns "attempt to index a boolean value"

Your error is on line 15
data/weapons/scripts/distance_damage.lua:15

The way to trouble shoot issues like this is to use type in conjunction with print.
Example
Code:
print(type(getPlayerSlotItem(cid, CONST_SLOT_LEFT)), getPlayerSlotItem(cid, CONST_SLOT_LEFT), getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid, getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid)
Do the same for CONST_SLOT_RIGHT.

I'm sorry, I don't understand
 
I tried... But so much errors
I tried:
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
   --min = ((0.08) * (attack) * (skill)) * -1
   --max = ((0.08) * (attack) * (skill)) * -1
   --print(skill)
   print(attack)
   -- get weapon attack (bow/crossbow)
   local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
   local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
   local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
   if item1.uid ~= 0 then
     hand1 = getItemInfo(item1.uid).attack
   end
   if item2.uid ~= 0 then
     hand2 = getItemInfo(item2.uid).attack
   end
   if hand1 > hand2 then
     bowattack = hand1
   else
     bowattack = hand2
   end
   print(bowattack)
   atktotal = bowattack + attack
   print(atktotal)
   min = ((atktotal) * (100)) * -1
   max = ((atktotal) * (100)) * -1
   return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
   return doCombat(cid, combat, var)
end

Errors:
Code:
[18:53:38.077] [Error - Weapon Interface]
[18:53:38.077] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:53:38.077] (Unknown script file)
[18:53:38.077] Description:
[18:53:38.077] data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
30

[18:53:54.250] [Error - Weapon Interface]
[18:53:54.250] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:53:54.250] (Unknown script file)
[18:53:54.250] Description:
[18:53:54.250] data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
30

[18:53:58.362] [Error - Weapon Interface]
[18:53:58.362] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:53:58.362] (Unknown script file)
[18:53:58.362] Description:
[18:53:58.362] data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
30

[18:54:00.369] [Error - Weapon Interface]
[18:54:00.369] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:54:00.369] (Unknown script file)
[18:54:00.369] Description:
[18:54:00.369] data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
Line 15:getItemInfo(item1.uid)

actually
Code:
getItemInfo(itemid)
it is itemid not .uid

so it should be

Code:
getItemInfo(item.itemid)

Or just use

Code:
getItemAttack(item1.uid)

Whatever solves it
 
data/weapons/scripts/distance_damage.lua:15: attempt to index a boolean value
A boolean value is a value which contains true or false or considers 1 or 0 as boolean.

"attempt to index" means, you can not access a property of something which is not a table.
Example
Code:
true.uid -- returns "attempt to index a boolean value"
false.uid -- returns "attempt to index a boolean value"

Your error is on line 15
data/weapons/scripts/distance_damage.lua:15

The reason it prints a boolean value is because of the source

Code:
if(!(item = Item::items.getElement(popNumber(L))))
   {
     lua_pushboolean(L, false);
     return 1;
   }

Since you are using item.uid then the source cant find the specific item so it just pushs false..it would push a number if you are using it correctly.
 
EDIT: New script actually checks if the player has an arrow in ammo slot, if they don't, the weaapon will not work.
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 0)
setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 0)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)

function onGetFormulaValues(cid, level, skill, attack, factor)
    local ML = getPlayerMagLevel(cid)
    local Arrow = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
    if Arrow.itemid ~= 0 then
    min = attack + ML + getItemInfo(Arrow.itemid).attack
    max = attack + ML + getItemInfo(Arrow.itemid).attack
    return -min, -max
end
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local area = createCombatArea({
   {1, 1, 1},
   {1, 3, 1},
   {1, 1, 1}
})

setCombatArea(combat, area)

function onUseWeapon(cid, var)
    local Arrow = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
    if Arrow.itemid == 0 then
        return false
    end
    if Arrow.itemid ~= 0 then
    if getItemInfo(Arrow.itemid).weaponType ~= 8 then
    return false
end
end
   return doCombat(cid, combat, var)
end
 
Last edited:
Line 15:getItemInfo(item1.uid)

actually
Code:
getItemInfo(itemid)
it is itemid not .uid

so it should be

Code:
getItemInfo(item.itemid)

Or just use

Code:
getItemAttack(item1.uid)

Whatever solves it

I've tried

getItemAttack

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
   --min = ((0.08) * (attack) * (skill)) * -1
   --max = ((0.08) * (attack) * (skill)) * -1
   --print(skill)
   print(attack)
   -- get weapon attack (bow/crossbow)
   local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
   local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
   local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
   if item1.uid ~= 0 then
     hand1 = getItemAttack(item1.uid)
   end
   if item2.uid ~= 0 then
     hand2 = getItemAttack(hand2.uid)
   end
   if hand1 > hand2 then
     bowattack = hand1
   else
     bowattack = hand2
   end
   print(bowattack)
   atktotal = bowattack + attack
   print(atktotal)
   min = ((atktotal) * (100)) * -1
   max = ((atktotal) * (100)) * -1
   return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
   return doCombat(cid, combat, var)
end


Code:
[16:7:28.170] [Error - Weapon Interface]
[16:7:28.170] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[16:7:28.170] (Unknown script file)
[16:7:28.170] Description:
[16:7:28.171] data/weapons/scripts/distance_damage.lua:15: attempt to call global 'getItemAttack' (a nil value)
 
I've tried

getItemAttack

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
   --min = ((0.08) * (attack) * (skill)) * -1
   --max = ((0.08) * (attack) * (skill)) * -1
   --print(skill)
   print(attack)
   -- get weapon attack (bow/crossbow)
   local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
   local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
   local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
   if item1.uid ~= 0 then
     hand1 = getItemAttack(item1.uid)
   end
   if item2.uid ~= 0 then
     hand2 = getItemAttack(hand2.uid)
   end
   if hand1 > hand2 then
     bowattack = hand1
   else
     bowattack = hand2
   end
   print(bowattack)
   atktotal = bowattack + attack
   print(atktotal)
   min = ((atktotal) * (100)) * -1
   max = ((atktotal) * (100)) * -1
   return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
   return doCombat(cid, combat, var)
end


Code:
[16:7:28.170] [Error - Weapon Interface]
[16:7:28.170] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[16:7:28.170] (Unknown script file)
[16:7:28.170] Description:
[16:7:28.171] data/weapons/scripts/distance_damage.lua:15: attempt to call global 'getItemAttack' (a nil value)
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
  --min = ((0.08) * (attack) * (skill)) * -1
  --max = ((0.08) * (attack) * (skill)) * -1
  --print(skill)
  print(attack)
  -- get weapon attack (bow/crossbow)
  local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
  local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
  if item1.uid ~= 0 then
  hand1 = getItemInfo(item1.itemid)
  end
  if item2.uid ~= 0 then
  hand2 = getItemInfo(item2.itemid)
  end
  if hand1 > hand2 then
  bowattack = hand1
  else
  bowattack = hand2
  end
  print(bowattack)
  atktotal = bowattack + attack
  print(atktotal)
  min = ((atktotal) * (100)) * -1
  max = ((atktotal) * (100)) * -1
  return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
  return doCombat(cid, combat, var)
end
 
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
  --min = ((0.08) * (attack) * (skill)) * -1
  --max = ((0.08) * (attack) * (skill)) * -1
  --print(skill)
  print(attack)
  -- get weapon attack (bow/crossbow)
  local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
  local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
  if item1.uid ~= 0 then
  hand1 = getItemInfo(item1.itemid)
  end
  if item2.uid ~= 0 then
  hand2 = getItemInfo(item2.itemid)
  end
  if hand1 > hand2 then
  bowattack = hand1
  else
  bowattack = hand2
  end
  print(bowattack)
  atktotal = bowattack + attack
  print(atktotal)
  min = ((atktotal) * (100)) * -1
  max = ((atktotal) * (100)) * -1
  return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
  return doCombat(cid, combat, var)
end


I tried... Error:
Code:
[18:51:47.835] Test Bow has logged in.
30

[18:52:17.236] [Error - Weapon Interface]
[18:52:17.236] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:52:17.236] (Unknown script file)
[18:52:17.236] Description:
[18:52:17.236] data/weapons/scripts/distance_damage.lua:20: attempt to compare number with table
30

How could i check arrow slot, to make ifs like: poison arrow (add conditions and effects)
for exemple:
Code:
if(slotarrow_itemid == 2545)
   local combat = createCombatObject()
   setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
   setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
   setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)
   setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

   local condition = createConditionObject(CONDITION_POISON)
   setConditionParam(condition, CONDITION_PARAM_DELAYED, 15)
   addDamageCondition(condition, 10, 2000, -30)
   setCombatCondition(combat, condition)
elseif
   ...
end
 
I tried... Error:
Code:
[18:51:47.835] Test Bow has logged in.
30

[18:52:17.236] [Error - Weapon Interface]
[18:52:17.236] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[18:52:17.236] (Unknown script file)
[18:52:17.236] Description:
[18:52:17.236] data/weapons/scripts/distance_damage.lua:20: attempt to compare number with table
30

How could i check arrow slot, to make ifs like: poison arrow (add conditions and effects)
for exemple:
Code:
if(slotarrow_itemid == 2545)
   local combat = createCombatObject()
   setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
   setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
   setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)
   setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

   local condition = createConditionObject(CONDITION_POISON)
   setConditionParam(condition, CONDITION_PARAM_DELAYED, 15)
   addDamageCondition(condition, 10, 2000, -30)
   setCombatCondition(combat, condition)
elseif
   ...
end
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
  --min = ((0.08) * (attack) * (skill)) * -1
  --max = ((0.08) * (attack) * (skill)) * -1
  --print(skill)
  print(attack)
  -- get weapon attack (bow/crossbow)
  local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
  local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
  if item1.uid ~= 0 then
  hand1 = getItemInfo(item1.itemid).attack
  end
  if item2.uid ~= 0 then
  hand2 = getItemInfo(item2.itemid).attack
  end
  if hand1 > hand2 then
  bowattack = hand1
  else
  bowattack = hand2
  end
  print(bowattack)
  atktotal = bowattack + attack
  print(atktotal)
  min = ((atktotal) * (100)) * -1
  max = ((atktotal) * (100)) * -1
  return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
  return doCombat(cid, combat, var)
end
 
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
  --min = ((0.08) * (attack) * (skill)) * -1
  --max = ((0.08) * (attack) * (skill)) * -1
  --print(skill)
  print(attack)
  -- get weapon attack (bow/crossbow)
  local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
  local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
  if item1.uid ~= 0 then
  hand1 = getItemInfo(item1.itemid).attack
  end
  if item2.uid ~= 0 then
  hand2 = getItemInfo(item2.itemid).attack
  end
  if hand1 > hand2 then
  bowattack = hand1
  else
  bowattack = hand2
  end
  print(bowattack)
  atktotal = bowattack + attack
  print(atktotal)
  min = ((atktotal) * (100)) * -1
  max = ((atktotal) * (100)) * -1
  return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
  return doCombat(cid, combat, var)
end


Ty you so much...
Do u know how to finish?
Code:
  -- effects and atributes AMMO (SLOT ARROW)
  if(slotarrow_itemid == 2545)
  local combat = createCombatObject()
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)
  setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

  local condition = createConditionObject(CONDITION_POISON)
  setConditionParam(condition, CONDITION_PARAM_DELAYED, 15)
  addDamageCondition(condition, 10, 2000, -30)
  setCombatCondition(combat, condition)
  elseif
  -- ...
  end

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
  -- get atk bow
  local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
  local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
  if item1.uid ~= 0 then
  hand1 = getItemInfo(item1.itemid).attack
  end
  if item2.uid ~= 0 then
  hand2 = getItemInfo(item2.itemid).attack
  end
  if hand1 > hand2 then
  bowattack = hand1
  else
  bowattack = hand2
  end
  -- effects and atributes AMMO (SLOT ARROW)
  if(slotarrow_itemid == 2545)
  local combat = createCombatObject()
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)
  setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

  local condition = createConditionObject(CONDITION_POISON)
  setConditionParam(condition, CONDITION_PARAM_DELAYED, 15)
  addDamageCondition(condition, 10, 2000, -30)
  setCombatCondition(combat, condition)
  elseif
  -- ...
  end
  -- bowattack + attack [arrow]
  atktotal = bowattack + attack
  min = ((0.05) * (atktotal) * (skill)) * -1
  max = ((0.05) * (atktotal) * (skill)) * -1
  return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
  return doCombat(cid, combat, var)
end
 
Ty you so much...
Do u know how to finish?
Code:
  -- effects and atributes AMMO (SLOT ARROW)
  if(slotarrow_itemid == 2545)
  local combat = createCombatObject()
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)
  setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

  local condition = createConditionObject(CONDITION_POISON)
  setConditionParam(condition, CONDITION_PARAM_DELAYED, 15)
  addDamageCondition(condition, 10, 2000, -30)
  setCombatCondition(combat, condition)
  elseif
  -- ...
  end

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
  -- get atk bow
  local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
  local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
  if item1.uid ~= 0 then
  hand1 = getItemInfo(item1.itemid).attack
  end
  if item2.uid ~= 0 then
  hand2 = getItemInfo(item2.itemid).attack
  end
  if hand1 > hand2 then
  bowattack = hand1
  else
  bowattack = hand2
  end
  -- effects and atributes AMMO (SLOT ARROW)
  if(slotarrow_itemid == 2545)
  local combat = createCombatObject()
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)
  setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 0, 1, 0)

  local condition = createConditionObject(CONDITION_POISON)
  setConditionParam(condition, CONDITION_PARAM_DELAYED, 15)
  addDamageCondition(condition, 10, 2000, -30)
  setCombatCondition(combat, condition)
  elseif
  -- ...
  end
  -- bowattack + attack [arrow]
  atktotal = bowattack + attack
  min = ((0.05) * (atktotal) * (skill)) * -1
  max = ((0.05) * (atktotal) * (skill)) * -1
  return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
  return doCombat(cid, combat, var)
end
eh, thats what i got for today, you can thank Xeraphus first, then we can continue
 
I like how you completely ignored my script
Thanks :)

I'm so sorry, i didnt saw your coment!

Your script was to use in bow item or arrow?

I tried use your base to create a arrow script like this

But show this error on console:
Code:
[3:47:19.258] [Error - Weapon Interface]
[3:47:19.258] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[3:47:19.259] (Unknown script file)
[3:47:19.259] Description:
[3:47:19.259] (luaSetCombatParam) This function can only be used while loading the script.

[3:47:19.259] [Error - Weapon Interface]
[3:47:19.259] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[3:47:19.259] (Unknown script file)
[3:47:19.259] Description:
[3:47:19.259] (luaSetCombatParam) This function can only be used while loading the script.

[3:47:19.259] [Error - Weapon Interface]
[3:47:19.259] In a callback: data/weapons/scripts/distance_damage.lua:onGetFormulaValues
[3:47:19.259] (Unknown script file)
[3:47:19.260] Description:
[3:47:19.260] (luaSetCombatParam) This function can only be used while loading the script.

Script:
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
  local arrowid = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
  print(arrowid)
  if(arrowid == 2545) then -- poison arrow
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISONARROW)

  local condition = createConditionObject(CONDITION_POISON)
  setConditionParam(condition, CONDITION_PARAM_DELAYED, 15)
  addDamageCondition(condition, 10, 2000, -30)
  setCombatCondition(combat, condition)
  elseif(arrowid == 2544) then -- arrow
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 2)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 7364) then -- sniper arrow
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 21)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 7365) then -- onyx arrow
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 22)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 7839) then -- shiver arrow (ice)
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 28)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
  elseif(arrowid == 7850) then -- earth arrow
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 29)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_EARTHDAMAGE)
  elseif(arrowid == 7838) then -- flash arrow (energy)
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 32)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
  elseif(arrowid == 7840) then -- flaming arrow
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 33)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
  elseif(arrowid == 2543) then -- bolt
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 1)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 7363) then -- piercing bolt
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 23)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 2547) then -- power bolt
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 13)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 6529) then -- infernal bolt
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 15)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 2389) then -- spear
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 0)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 3965) then -- hunting spear
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 16)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 7367) then -- enchanted spear
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 17)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 7378) then -- royal spear
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 20)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 7368) then -- assassin star
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 7366) then -- viper star
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 19)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 2399) then -- throwing stars
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 7)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 2410) then -- throwing knife
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 8)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  elseif(arrowid == 1294) then -- small stone
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 9)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  else -- bug
   
  setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
  setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 41)
  setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
  end
 
  -- get weapon attack (bow/crossbow)
  local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
  local bowattack, hand1, hand2, atktotal = 0, 0, 0, 0
  if item1.uid ~= 0 then
  hand1 = getItemInfo(item1.itemid).attack
  end
  if item2.uid ~= 0 then
  hand2 = getItemInfo(item2.itemid).attack
  end
  if hand1 > hand2 then
  bowattack = hand1
  else
  bowattack = hand2
  end
  atktotal = bowattack + attack
  min = ((0.05) * (attack) * (skill)) * -1
  max = ((0.05) * (attack) * (skill)) * -1
  return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
  return doCombat(cid, combat, var)
end
 
Back
Top