• 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!

Lua Why this weapon no remove any damage?

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
Whats worng with this script?
Code:
w = {
   [12031] = {ef = 36, sh = 3, dmg = COMBAT_FIREDAMAGE},
   [12032] = {ef = 42, sh = 28, dmg = COMBAT_ICEDAMAGE},
   [12033] = {ef = 45, sh = 38, dmg = COMBAT_POISONDAMAGE},
   [12034] = {ef = 17, sh = 31, dmg = COMBAT_DEATHDAMAGE},
   [12035] = {ef = 11, sh = 35, dmg = COMBAT_ENERGYDAMAGE},
   [12036] = {ef = 49, sh = 37, dmg = COMBAT_HOLYDAMAGE}
}

local minimo
local maximo

function onGetFormulaValues(cid, level, skill, attack, factor)
   minimo = (attack * spellconfig_wandnrods_min) * -1
   maximo = (attack * spellconfig_wandnrods_max) * -1
end
function onUseWeapon(cid, var)
   target = getCreatureTarget(cid)
   for stor, info in pairs(w) do
     if getPlayerStorageValue(cid, stor) == 1 then
       if target ~= 0 then
         doSendDistanceShoot(getThingPos(cid), getThingPos(target), info.sh)
         addEvent(doAreaCombatHealth, 100, cid, info.dmg, getThingPos(target), 0, minimo, maximo, info.ef)
       end
     end
   end
   return true
end
 
1. post full script, what is storaged in spellconfig_wandnrods_min?
2. you don't set the callback to onGetFormulaValues.

1- Its the full attack script, the others is just to change storage to element
1- spellconfig_wandnrods_min is in /lib/spellformulas.lua

And its:
Code:
spellconfig_wandnrods_min = 4.0
spellconfig_wandnrods_max = 6.0

2- I dont understand this part
 
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

Code:
local combat = createCombatObject()

w = {
   [12031] = {ef = 36, sh = 3, dmg = COMBAT_FIREDAMAGE},
   [12032] = {ef = 42, sh = 28, dmg = COMBAT_ICEDAMAGE},
   [12033] = {ef = 45, sh = 38, dmg = COMBAT_POISONDAMAGE},
   [12034] = {ef = 17, sh = 31, dmg = COMBAT_DEATHDAMAGE},
   [12035] = {ef = 11, sh = 35, dmg = COMBAT_ENERGYDAMAGE},
   [12036] = {ef = 49, sh = 37, dmg = COMBAT_HOLYDAMAGE}
}

local minimo
local maximo

function onGetFormulaValues(cid, level, skill, attack, factor)
   minimo = (attack * spellconfig_wandnrods_min) * -1
   maximo = (attack * spellconfig_wandnrods_max) * -1
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
   target = getCreatureTarget(cid)
   for stor, info in pairs(w) do
     if getPlayerStorageValue(cid, stor) == 1 then
       if target ~= 0 then
         doSendDistanceShoot(getThingPos(cid), getThingPos(target), info.sh)
         addEvent(doAreaCombatHealth, 100, cid, info.dmg, getThingPos(target), 0, minimo, maximo, info.ef)
       end
     end
   end
   return true
end

No damage, no error ;\
 
I assumed you are using "attack attribute (items.xml)" on wands.
Code:
local wands = {
   [12031] = {ef = 36, sh = 3, dmg = COMBAT_FIREDAMAGE},
   [12032] = {ef = 42, sh = 28, dmg = COMBAT_ICEDAMAGE},
   [12033] = {ef = 45, sh = 38, dmg = COMBAT_POISONDAMAGE},
   [12034] = {ef = 17, sh = 31, dmg = COMBAT_DEATHDAMAGE},
   [12035] = {ef = 11, sh = 35, dmg = COMBAT_ENERGYDAMAGE},
   [12036] = {ef = 49, sh = 37, dmg = COMBAT_HOLYDAMAGE}
}

function onUseWeapon(cid, var)

  for slots = 5, 6 do
    local item = getPlayerSlotItem(cid, slots).itemid
    if item > 0 and getItemInfo(item).weaponType == WEAPON_WAND then
      attackValue = getItemInfo(item).attack
    end
  end

  if (attackValue > 0) then
    local target = getCreatureTarget(cid)
    for str, info in pairs (wands) do
      if getPlayerStorageValue(cid, str) > 0 then
        if target ~= nil then
          doSendDistanceShoot(getThingPos(cid), getThingPos(target), info.sh)
          addEvent(doCombatAreaHealth, 100, cid, info.dmg, getThingPos(target), 0, -((attackValue * spellconfig_wandnrods_min) * 1), -((attackValue * spellconfig_wandnrods_max) * 1), info.ef)
        end
      end
    end
  else
    doPlayerSendTextMessage(cid, 21, "You need to set an attack value on items.xml")
  end
  return true
end
 
I assumed you are using "attack attribute (items.xml)" on wands.
Code:
local wands = {
   [12031] = {ef = 36, sh = 3, dmg = COMBAT_FIREDAMAGE},
   [12032] = {ef = 42, sh = 28, dmg = COMBAT_ICEDAMAGE},
   [12033] = {ef = 45, sh = 38, dmg = COMBAT_POISONDAMAGE},
   [12034] = {ef = 17, sh = 31, dmg = COMBAT_DEATHDAMAGE},
   [12035] = {ef = 11, sh = 35, dmg = COMBAT_ENERGYDAMAGE},
   [12036] = {ef = 49, sh = 37, dmg = COMBAT_HOLYDAMAGE}
}

function onUseWeapon(cid, var)

  for slots = 5, 6 do
    local item = getPlayerSlotItem(cid, slots).itemid
    if item > 0 and getItemInfo(item).weaponType == WEAPON_WAND then
      attackValue = getItemInfo(item).attack
    end
  end

  if (attackValue > 0) then
    local target = getCreatureTarget(cid)
    for str, info in pairs (wands) do
      if getPlayerStorageValue(cid, str) > 0 then
        if target ~= nil then
          doSendDistanceShoot(getThingPos(cid), getThingPos(target), info.sh)
          addEvent(doCombatAreaHealth, 100, cid, info.dmg, getThingPos(target), 0, -((attackValue * spellconfig_wandnrods_min) * 1), -((attackValue * spellconfig_wandnrods_max) * 1), info.ef)
        end
      end
    end
  else
    doPlayerSendTextMessage(cid, 21, "You need to set an attack value on items.xml")
  end
  return true
end


Code:
[5:1:48.063] [Error - Weapon Interface]
[5:1:48.063] data/weapons/scripts/wands_n_rods/elemental_staff.lua:onUseWeapon
[5:1:48.063] Description:
[5:1:48.063] data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: attempt to compare number with nil
[5:1:48.063] stack traceback:
[5:1:48.063]    data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: in function <data/weapons/scripts/wands_n_rods/elemental_staff.lua:10>

[5:1:50.074] [Error - Weapon Interface]
[5:1:50.074] data/weapons/scripts/wands_n_rods/elemental_staff.lua:onUseWeapon
[5:1:50.074] Description:
[5:1:50.074] data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: attempt to compare number with nil
[5:1:50.074] stack traceback:
[5:1:50.075]    data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: in function <data/weapons/scripts/wands_n_rods/elemental_staff.lua:10>

[5:1:52.088] [Error - Weapon Interface]
[5:1:52.089] data/weapons/scripts/wands_n_rods/elemental_staff.lua:onUseWeapon
[5:1:52.089] Description:
[5:1:52.089] data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: attempt to compare number with nil
[5:1:52.090] stack traceback:
[5:1:52.090]    data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: in function <data/weapons/scripts/wands_n_rods/elemental_staff.lua:10>

Yes, i'm using attack in wands
 
Code:
if target ~= nil then
to
Code:
if target > 0 then

Not work bro

Code:
[16:50:27.351] [Error - Weapon Interface]
[16:50:27.351] data/weapons/scripts/wands_n_rods/elemental_staff.lua:onUseWeapon
[16:50:27.351] Description:
[16:50:27.351] data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: attempt to compare number with nil
[16:50:27.351] stack traceback:
[16:50:27.351]    data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: in function <data/weapons/scripts/wands_n_rods/elemental_staff.lua:10>

[16:50:29.359] [Error - Weapon Interface]
[16:50:29.359] data/weapons/scripts/wands_n_rods/elemental_staff.lua:onUseWeapon
[16:50:29.359] Description:
[16:50:29.359] data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: attempt to compare number with nil
[16:50:29.359] stack traceback:
[16:50:29.360]    data/weapons/scripts/wands_n_rods/elemental_staff.lua:19: in function <data/weapons/scripts/wands_n_rods/elemental_staff.lua:10

what tfs you using?

0.4
 
Code:
local wands = {
  [12031] = {ef = 36, sh = 3, dmg = COMBAT_FIREDAMAGE},
  [12032] = {ef = 42, sh = 28, dmg = COMBAT_ICEDAMAGE},
  [12033] = {ef = 45, sh = 38, dmg = COMBAT_POISONDAMAGE},
  [12034] = {ef = 17, sh = 31, dmg = COMBAT_DEATHDAMAGE},
  [12035] = {ef = 11, sh = 35, dmg = COMBAT_ENERGYDAMAGE},
  [12036] = {ef = 49, sh = 37, dmg = COMBAT_HOLYDAMAGE}
}

function onUseWeapon(cid, var)
   local attackValue = 0
  for slots = 5, 6 do
  local item = getPlayerSlotItem(cid, slots).itemid
  if item > 0 and getItemInfo(item).weaponType == WEAPON_WAND then
  attackValue = getItemInfo(item).attack
  end
  end

  if (attackValue > 0) then
  local target = getCreatureTarget(cid)
  for str, info in pairs (wands) do
  if getPlayerStorageValue(cid, str) > 0 then
  if target ~= nil then
  doSendDistanceShoot(getThingPos(cid), getThingPos(target), info.sh)
  addEvent(doCombatAreaHealth, 100, cid, info.dmg, getThingPos(target), 0, -((attackValue * spellconfig_wandnrods_min) * 1), -((attackValue * spellconfig_wandnrods_max) * 1), info.ef)
  end
  end
  end
  else
  doPlayerSendTextMessage(cid, 21, "You need to set an attack value on items.xml")
  end
  return true
end
 
Like @tetra20 did, add local attackValue = 0 under onUseWeapon function (Weird tho, it worked fine to me without any change maybe cuz i tested it on 0.3.7).
 
Code:
local wands = {
  [12031] = {ef = 36, sh = 3, dmg = COMBAT_FIREDAMAGE},
  [12032] = {ef = 42, sh = 28, dmg = COMBAT_ICEDAMAGE},
  [12033] = {ef = 45, sh = 38, dmg = COMBAT_POISONDAMAGE},
  [12034] = {ef = 17, sh = 31, dmg = COMBAT_DEATHDAMAGE},
  [12035] = {ef = 11, sh = 35, dmg = COMBAT_ENERGYDAMAGE},
  [12036] = {ef = 49, sh = 37, dmg = COMBAT_HOLYDAMAGE}
}

function onUseWeapon(cid, var)
   local attackValue = 0
  for slots = 5, 6 do
  local item = getPlayerSlotItem(cid, slots).itemid
  if item > 0 and getItemInfo(item).weaponType == WEAPON_WAND then
  attackValue = getItemInfo(item).attack
  end
  end

  if (attackValue > 0) then
  local target = getCreatureTarget(cid)
  for str, info in pairs (wands) do
  if getPlayerStorageValue(cid, str) > 0 then
  if target ~= nil then
  doSendDistanceShoot(getThingPos(cid), getThingPos(target), info.sh)
  addEvent(doCombatAreaHealth, 100, cid, info.dmg, getThingPos(target), 0, -((attackValue * spellconfig_wandnrods_min) * 1), -((attackValue * spellconfig_wandnrods_max) * 1), info.ef)
  end
  end
  end
  else
  doPlayerSendTextMessage(cid, 21, "You need to set an attack value on items.xml")
  end
  return true
end

It's show me:
Code:
You need to set an attack value on items.xml

But my elemental wand in items.xml is
Code:
  <item id="12327" article="a" name="elemental staff">
     <attribute key="weight" value="2800" />
     <attribute key="weaponType" value="wand" />
     <attribute key="shootType" value="holy" />
     <attribute key="range" value="8" />
     <attribute key="attack" value="20"/>
     <attribute key="description" value="Change element using: !staffelement type." />
   </item>
 
It's show me:
Code:
You need to set an attack value on items.xml

But my elemental wand in items.xml is
Code:
  <item id="12327" article="a" name="elemental staff">
     <attribute key="weight" value="2800" />
     <attribute key="weaponType" value="wand" />
     <attribute key="shootType" value="holy" />
     <attribute key="range" value="8" />
     <attribute key="attack" value="20"/>
     <attribute key="description" value="Change element using: !staffelement type." />
   </item>

Code:
<attribute key="attack" value="20"/>

it is in source.. you need to edit items.cpp
 
Code:
<attribute key="attack" value="20"/>

it is in source.. you need to edit items.cpp

not really, thats how to fix (tested)
Code:
local wands = {
  [12031] = {ef = 36, sh = 3, dmg = COMBAT_FIREDAMAGE},
  [12032] = {ef = 42, sh = 28, dmg = COMBAT_ICEDAMAGE},
  [12033] = {ef = 45, sh = 38, dmg = COMBAT_POISONDAMAGE},
  [12034] = {ef = 17, sh = 31, dmg = COMBAT_DEATHDAMAGE},
  [12035] = {ef = 11, sh = 35, dmg = COMBAT_ENERGYDAMAGE},
  [12036] = {ef = 49, sh = 37, dmg = COMBAT_HOLYDAMAGE}
}

function onUseWeapon(cid, var)
  local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
  local staffatk, hand1, hand2 = 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
  staffatk = hand1
  else
  staffatk = hand2
  end
  local attackValue = staffatk


  if (attackValue > 0) then
  local target = getCreatureTarget(cid)
  for str, info in pairs (wands) do
  if getPlayerStorageValue(cid, str) > 0 then
  if target ~= nil then
  doSendDistanceShoot(getThingPos(cid), getThingPos(target), info.sh)
  addEvent(doCombatAreaHealth, 100, cid, info.dmg, getThingPos(target), 0, -((attackValue * spellconfig_wandnrods_min) * 1), -((attackValue * spellconfig_wandnrods_max) * 1), info.ef)
  end
  end
  end
  else
  doPlayerSendTextMessage(cid, 21, "You need to set an attack value on items.xml")
  end
  return true
end
 
Back
Top