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

getItemAttack

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
Error:
Code:
[26/2/2014 14:38:0] [Error - CreatureScript Interface]
[26/2/2014 14:38:0] data/creaturescripts/scripts/critical.lua:onAttack
[26/2/2014 14:38:0] Description:
[26/2/2014 14:38:0] data/creaturescripts/scripts/critical.lua:33: attempt to call global 'getItemAttack' (a nil value)
[26/2/2014 14:38:0] stack traceback:
[26/2/2014 14:38:0]    data/creaturescripts/scripts/critical.lua:33: in function <data/creaturescripts/scripts/critical.lua:8>

Script:
Code:
local tabelachance=
{
[11]=20,
[12]=5
}


function onAttack(cid,target)
    local weapon = getPlayerWeapon(cid)
    if weapon.uid == 0 then
        return true
    end
    local atk = getItemInfo(weapon.itemid).attack + getItemInfo(weapon.itemid).extraAttack
    if atk < 0 then
        return true
    end
    if getDistanceBetween(getCreaturePos(cid), getCreaturePos(target)) > 1 then
        return TRUE
    end
   
local healing =
{
[1] = 0.01,
[2] = 0.02,
[3] = 0.03,
[4] = 0.04,
[5] = 0.05
}

    local skill = getPlayerSkillLevel(cid, getPlayerWeaponSkill(cid))
    local level = getPlayerLevel(cid)
   
    local formula = math.floor((getItemAttack(weapon)/100*60)+(skill/100*60)+(level/100*60))
    local text = "Critical!"
    local effect = 31
    local rand1 = math.random(1,100)
    local vid = getPlayerVocation(cid)
   
    if tabelachance[vid] and rand1 <= tabelachance[vid] then
    doCreatureSay(cid, text, TALKTYPE_MONSTER)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid)*healing[math.random(1,#healing)])
        doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, (-formula), (-formula), effect)
    end
    return true
end

Functions:
Code:
function getWeaponSkill(itemid)
    if itemid == 0 then
        return 0
    end
    local skill = {[0]=0, [2]=1, [1]=2, [3]=3, [7]=4, [6]=7}
    return skill[getItemInfo(itemid).weaponType]
end

function getPlayerWeaponSkill(cid)
    return getWeaponSkill(getPlayerWeapon(cid).itemid)
end
 
Use this instead of getItemAttack(getPlayerWeapon(cid).uid):
Code:
local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
local atk, atk1, atk2 = 0, 0, 0
if item1.uid ~= 0 then
atk1 = getItemAttack(item1.uid)
end
if item2.uid ~= 0 then
atk2 = getItemAttack(item2.uid)
end
if atk1 > atk2 then
atk = atk1
else
atk = atk2
end

It returns atk = getItemAttack(getPlayerWeapon(cid).uid)
Prefer to add it into libs.
 
Back
Top