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

[Weapons] Throwing Knife

sn3ejk

This account is inactive.
Joined
Nov 16, 2011
Messages
2,121
Solutions
1
Reaction score
145
[Weapons]
Throwing Knife


-agHot.gif

When player hold throwing knife, he throws additional throwing knives at two targets standing next to target after each attack.


  • ~/data/weapons/weapons.xml
    XML:
    <distance id="2410" event="script" value="throwing_knife.lua"/>
  • ~/data/weapons/scripts/throwing_knife.lua
    Lua:
    local combat, sub_combat = createCombatObject(), createCombatObject()
    for param, value in pairs({[COMBAT_PARAM_TYPE] = COMBAT_PHYSICALDAMAGE, 
        [COMBAT_PARAM_BLOCKARMOR] = true, [COMBAT_PARAM_EFFECT] = CONST_ME_HITAREA,
        [COMBAT_PARAM_DISTANCEEFFECT] = CONST_ANI_THROWINGKNIFE}) do
        setCombatParam(combat, param, value)
        setCombatParam(sub_combat, param, value)
    end
    
    function combat_skillvalue(cid, level, skill, attack, element, factor)
        return -math.ceil((2 * (attack * (skill + 5.8) / 25 + (level - 1) / 10)) 
            / factor)
    end
    setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "combat_skillvalue")
    
    function sub_combat_skillvalue(cid, level, skill, attack, element, factor)
        return -math.ceil(((2 * (attack * (skill + 5.8) / 25 + (level - 1) / 10))
            / factor) * 0.14)
    end
    setCombatCallback(sub_combat, CALLBACK_PARAM_SKILLVALUE, "sub_combat_skillvalue")
    
    
    
    function onUseWeapon(cid, var)
        local ret = doCombat(cid, combat, var)
        if not ret then
            return false
        end
    
        local target = variantToNumber(var)
        if target ~= 0 then
            local throws = 0
            for _, position in pairs(getArea(getCreaturePosition(target), 1, 1)) do
                local tmp = getTopCreature(position).uid
    
                if tmp ~= 0 and tmp ~= cid and tmp ~= target then
                    if doCombat(cid, sub_combat, numberToVariant(tmp)) then
                        throws = throws + 1
                        
                        if throws >= 2 then
                            break
                        end
                    end
                end
            end
        end
        return ret
    end


_
Regards,
sn3ejk
 
Last edited:
It's possible to do custom ammunition instead of throwing knife ex. arrows or bolts, with this script ?
 
Everything is possible.


_
Regards,
sn3ejk
 
~/data/weapons/scripts/bonebreaker.lua

I guess you mean throwing_knife.lua :p

- - - Updated - - -

Btw, I tried converting it into a spell (for monsters) and it doesn't quite work... (no damage done, arrows are shot)
Any idea why?

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)

function onCastSpell(cid, var)
    local ret = doCombat(cid, combat, var)
    if not ret then
        return false
    end
 
    local target = variantToNumber(var)
    doTargetCombatHealth(cid,target,COMBAT_PHYSICAL,-20,-80,CONST_ME_NONE,false)
    if target ~= 0 then
        local throws = 0
        for _, position in pairs(getArea(getCreaturePosition(target), 2, 2)) do
            local tmp = getTopCreature(position).uid
            if tmp ~= 0 and tmp ~= cid and tmp ~= target then
                if doCombat(cid, combat, numberToVariant(tmp)) then
		    doTargetCombatHealth(cid,tmp,COMBAT_PHYSICAL, -20, -80, CONST_ME_NONE,false)
                    throws = throws + 1
                    if throws >= 2 then
                        break
                    end
                end
            end
        end
    end
    return ret
end
 
what do i change to make it for viper star
this code?
<distance id="2410" event="script" value="throwing_knife.lua"/>?

- - - Updated - - -

ehmm it is trowing but its not hitting anything why? :/

- - - Updated - - -

getting error
[Error - Weapon Inferface]
in a callback: data/weapons/scripts/viperstar.lua:sub_combat_skillvale
<unknown script file>
Description:
data/wepons/scripts/viperstar.lua17: attempt to perform arithmetic on local 'factor' <a nil value>
 
what do i change to make it for viper star
this code?
<distance id="2410" event="script" value="throwing_knife.lua"/>?

- - - Updated - - -

ehmm it is trowing but its not hitting anything why? :/

- - - Updated - - -

getting error
[Error - Weapon Inferface]
in a callback: data/weapons/scripts/viperstar.lua:sub_combat_skillvale
<unknown script file>
Description:
data/wepons/scripts/viperstar.lua17: attempt to perform arithmetic on local 'factor' <a nil value>

the same error i have it the factor when i removed it i shot 3 knives but only one of the three knives do damage the one which i attacking with

please help fast
 
the same error i have it the factor when i removed it i shot 3 knives but only one of the three knives do damage the one which i attacking with

please help fast

What distro?
 
solved

I Just removed the Factor

PHP:
function sub_combat_skillvalue(cid, level, skill, attack, element, factor)
    return -math.ceil(((2 * (attack * (skill + 5.8) / 25 + (level - 1) / 10))
        / ----->factor<-----) * 0.14)
 
I can't hit anything with this, get this in console
[22/11/2014 17:23:27] [Error - Weapon Interface]
[22/11/2014 17:23:27] In a callback: data/weapons/scripts/throwing_knife.lua:combat_skillvalue
[22/11/2014 17:23:27] (Unknown script file)
[22/11/2014 17:23:27] Description:
[22/11/2014 17:23:27] data/weapons/scripts/throwing_knife.lua:11: attempt to perform arithmetic on local 'factor' (a nil value)
 
Back
Top