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

C++ [Request] Elemental bow

Landera

Veteran OT User
Joined
Nov 24, 2011
Messages
905
Solutions
1
Reaction score
318
Hello I'd like too make a elemental bow similiar too the flaming bow from medivia.
Medivia - Flaming Bow


EDIT: TFS 0.3.6


I've found a script that is what im searching for however is has some flaws when I want too make a poison bow that makes the target poisoned but after ive edited weapons.xml I'm getting an error because its duplicated.

Lua:
    <distance id="2544" action="removecount" script="ice_bow.lua"/>
    <distance id="2544" action="removecount" script="poison_bow.lua"/>

is it possible too merge these 2 script or even more in the future

Lua:
local bowid = 8855
local condition = createConditionObject(CONDITION_FREEZING)
setConditionParam(condition, CONDITION_PARAM_DELAYED, 1)
        addDamageCondition(condition, 15, 2000, -8)
local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1, 0)
function onUseWeapon(cid, var)
    local slotleft = getPlayerSlotItem(cid,CONST_SLOT_LEFT)
    local slotright = getPlayerSlotItem(cid,CONST_SLOT_RIGHT)
    if slotleft.itemid == bowid or slotright.itemid == bowid and getCreatureTarget(cid) then
        doTargetCombatCondition(cid, getCreatureTarget(cid), condition, CONST_ME_FIRE)
    end
   return doCombat(cid, combat, var)
end

Lua:
local bowid = 8856
local condition = createConditionObject(CONDITION_POISON)
setConditionParam(condition, CONDITION_PARAM_DELAYED, 1)
        addDamageCondition(condition, 15, 2000, -6)
local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1, 0)
function onUseWeapon(cid, var)
    local slotleft = getPlayerSlotItem(cid,CONST_SLOT_LEFT)
    local slotright = getPlayerSlotItem(cid,CONST_SLOT_RIGHT)
    if slotleft.itemid == bowid or slotright.itemid == bowid and getCreatureTarget(cid) then
        doTargetCombatCondition(cid, getCreatureTarget(cid), condition, CONST_ME_FIRE)
    end
   return doCombat(cid, combat, var)
end

Bump
 
Last edited by a moderator:
Solution
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1, 0)

local bow_c = {
     [8855] = createConditionObject(CONDITION_FREEZING),
     [8856] = createConditionObject(CONDITION_POISON)
}
setConditionParam(bow_c[8855], CONDITION_PARAM_DELAYED, 1)
addDamageCondition(bow_c[8855], 15, 2000, -8)

setConditionParam(bow_c[8856], CONDITION_PARAM_DELAYED, 1)
addDamageCondition(bow_c[8856], 15, 2000, -6)
        
function onUseWeapon(cid, var)
    local wid = getPlayerWeapon(cid, true).itemid -- If getPlayerWeapon doesn't work on your server, locate ID of the weapon via another means, e.g...
I'd help you out but I don't understand what you want to do exactly.
You want to have different elements on the same weapon ID? Cuz that's what you're trying to do here and obviously you can't have multiple scripts attached to same weapon.

On what factor does it depend whether the attack will leave the victim burning or poisoned (etc.)?
 
@Shadowsong

Well the id in the scripts 8855 and 8856 are the bows. The id in de weapons.xml is the id of the arrow. The idea is that the elemental damage will only work when using normal arrows and since I want too have more bows with elemental damage. So my idea is too merge the scripts I have. However if there is another way arround im open for it.
 
Greetings.

Why don't you use:
Code:
getPlayerWeapon(cid[, ignoreAmmo = false]) //TODO

And:
Code:
getPlayerSlotItem(cid, slot)
Info
This function checks what item player have actually in slot.
Slot can be:
CONST_SLOT_HEAD (1) = helmet
CONST_SLOT_NECKLACE (2) = necklace slot (amulet of loss etc.)
CONST_SLOT_BACKPACK (3) = backpack, bag
CONST_SLOT_ARMOR (4) = armor
CONST_SLOT_LEFT (5) = left hand (its really hand placed >> (right page on screen))
CONST_SLOT_RIGHT (6) = right hand (its really hand placed << (left page on screen))
CONST_SLOT_LEGS (7) = legs
CONST_SLOT_FEET (8) = boots
CONST_SLOT_RING (9) = ring slot
CONST_SLOT_AMMO (10) = ammo slot (arrows etc.)

And register the bows ids instead?

Otherwise, to fill in your request:

Lua:
local bowid = {8855, 8856}
local bow_c = {
     [8855] = createConditionObject(CONDITION_FREEZING),
     [8856] = createConditionObject(CONDITION_POISON)
}

setConditionParam(bow_c[8855], CONDITION_PARAM_DELAYED, 1)
addDamageCondition(bow_c[8855], 15, 2000, -8)


setConditionParam(bow_c[8856], CONDITION_PARAM_DELAYED, 1)
addDamageCondition(bow_c[8856], 15, 2000, -6)

local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1, 0)

function onUseWeapon(cid, var)
    local wid = getPlayerWeapon(cid, true) -- GET WEAPON ID, NOT AMMO
    if isInArray(bowid, wid)  and getCreatureTarget(cid) then
        doTargetCombatCondition(cid, getCreatureTarget(cid), bow_c[wid], CONST_ME_FIRE)
    end
   return doCombat(cid, combat, var)
end

Not tested.
 
Last edited:
@Shadowsong

Well the id in the scripts 8855 and 8856 are the bows. The id in de weapons.xml is the id of the arrow. The idea is that the elemental damage will only work when using normal arrows and since I want too have more bows with elemental damage. So my idea is too merge the scripts I have. However if there is another way arround im open for it.

Understood, you could try something like this, but whether it will work depends on your TFS:

Lua:
local ctbl = {
  [8855] = {ctype = CONDITION_FREEZING, cticks = 15, ctickduration = 2000, ctickdmg = -8},
  [8856] = {ctype = CONDITION_FREEZING, cticks = 15, ctickduration = 2000, ctickdmg = -6}
}

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1, 0)
   
function onUseWeapon(cid, var)
    local wid = getPlayerWeapon(cid, true).itemid
    if getCreatureTarget(cid) ~= 0 then
        if ctbl[wid] then           
            local condition = createConditionObject(ctbl[wid].ctype)
            setConditionParam(condition, CONDITION_PARAM_DELAYED, 1)
            addDamageCondition(condition, ctbl[wid].cticks, ctbl[wid].ctickduration, ctbl[wid].ctickdmg)           
            doTargetCombatCondition(cid, getCreatureTarget(cid), condition, CONST_ME_FIRE)
        end
    end

   return doCombat(cid, combat, var)
end
 
hmm thank you for the help guys but non of these scripts are working somehow.

@ScorpionOT you script doesnt give me any errors but isnt working

@Shadowsong you script is giving me this error

Lua:
[14/11/2017 16:41:59] [Error - Weapon Interface]
[14/11/2017 16:41:59] data/weapons/scripts/elemental_bow.lua:onUseWeapon
[14/11/2017 16:41:59] Description:
[14/11/2017 16:41:59] (luaSetConditionParam) This function can only be used while loading the script.
 
hmm thank you for the help guys but non of these scripts are working somehow.

@ScorpionOT you script doesnt give me any errors but isnt working

@Shadowsong you script is giving me this error

Lua:
[14/11/2017 16:41:59] [Error - Weapon Interface]
[14/11/2017 16:41:59] data/weapons/scripts/elemental_bow.lua:onUseWeapon
[14/11/2017 16:41:59] Description:
[14/11/2017 16:41:59] (luaSetConditionParam) This function can only be used while loading the script.

I see... That's unfortunate.

Well, I mean, you can always do it like this, it will most likely work but it's a shitty way of doing it because there's so much stuff that could be optimized here if condition altering worked inside the onUseWeapon function. :\
It does on my server, but now I realize it might have to do with a bunch of changes that were done to the combat system, and it doesn't allow this in the default TFS 0.3.6 code.

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1, 0)

-- Conditions --
local condition_8855 = createConditionObject(CONDITION_FREEZING)
setConditionParam(condition_8855, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(condition_8855, 15, 2000, -8)

local condition_8856 = createConditionObject(CONDITION_POISON)
setConditionParam(condition_8855, CONDITION_PARAM_DELAYED, 1)
addDamageCondition(condition_8855, 15, 2000, -6)
----------------
          
function onUseWeapon(cid, var)
    local wid = getPlayerWeapon(cid, true).itemid -- If getPlayerWeapon doesn't work on your server, locate ID of the weapon via another means, e.g. getPlayerSlotItem and store it in this var
    if getCreatureTarget(cid) ~= 0 then
        if wid == 8855 then        
            doTargetCombatCondition(cid, getCreatureTarget(cid), condition_8855, CONST_ME_FIRE)
        elseif wid == 8856 then
            doTargetCombatCondition(cid, getCreatureTarget(cid), condition_8856, CONST_ME_FIRE)
        end
    end
   return doCombat(cid, combat, var)
end
 
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1, 0)

local bow_c = {
     [8855] = createConditionObject(CONDITION_FREEZING),
     [8856] = createConditionObject(CONDITION_POISON)
}
setConditionParam(bow_c[8855], CONDITION_PARAM_DELAYED, 1)
addDamageCondition(bow_c[8855], 15, 2000, -8)

setConditionParam(bow_c[8856], CONDITION_PARAM_DELAYED, 1)
addDamageCondition(bow_c[8856], 15, 2000, -6)
        
function onUseWeapon(cid, var)
    local wid = getPlayerWeapon(cid, true).itemid -- If getPlayerWeapon doesn't work on your server, locate ID of the weapon via another means, e.g. getPlayerSlotItem and store it in this var
    if getCreatureTarget(cid) ~= 0 then
        if bow_c[wid] then
            doTargetCombatCondition(cid, getCreatureTarget(cid), bow_c[wid], CONST_ME_FIRE)
        end
    end
   return doCombat(cid, combat, var)
end

Optimized a bit.

Edit:
When your problems is resolved, please mark it as "Best Answer". This allows everyone to keep track of unsolved threads and rewards the person who helps you.
 
Last edited:
Solution
Back
Top