• 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 Another way to create FIREFIELD

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
74
I've got the following spell:

LUA:
local areaCombat, combat = createCombatObject(), createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 5)
setCombatParam(combat, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.2, 1, -0.3, 1)

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

And it works fine when it comes to creating fire field just under the creature.

However I need to set a chance for the fire to appear

I tried :

LUA:
local areaCombat, combat = createCombatObject(), createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 5)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.2, 1, -0.3, 1)

function onCastSpell(cid, var)
if math.random(100) < 50 then
setCombatParam(combat, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)
end
    return doCombat(cid, combat, var)
end

but that didn't work as it needs to be specified when the spell is loaded. That's why I am asking if there is any other way of creating fire field.

tfs 1.0

Cheers!
 
Solution
You can try to specify second combat variable and return it dependant on chance, like this:
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
setCombatParam(combat, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)

local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_POFF)
setCombatParam(combat2, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)

function onCastSpell(cid, var, isHotkey)
local chance = math.random(1, 100)
    if chance > 70 then
    return doCombat(cid, combat, var)
    else
    return doCombat(cid, combat2...
You can try to specify second combat variable and return it dependant on chance, like this:
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
setCombatParam(combat, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)

local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_POFF)
setCombatParam(combat2, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)

function onCastSpell(cid, var, isHotkey)
local chance = math.random(1, 100)
    if chance > 70 then
    return doCombat(cid, combat, var)
    else
    return doCombat(cid, combat2, var)
    end
end
 
Solution
You can try to specify second combat variable and return it dependant on chance, like this:
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
setCombatParam(combat, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)

local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_POFF)
setCombatParam(combat2, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)

function onCastSpell(cid, var, isHotkey)
local chance = math.random(1, 100)
    if chance > 70 then
    return doCombat(cid, combat, var)
    else
    return doCombat(cid, combat2, var)
    end
end

doesn't exactly the right answer but a workaround
 
It's an idea, not a ready-to-use script.
You can add any parameter you want.

true :D

I've found another way if someone is interested:

LUA:
local  combat, combatFire = createCombatObject(), createCombatObject()

setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 7)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 5)
setCombatParam(combatFire, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.2, 1, -0.3, 1)

    if math.random(100) < 50 then
       return doCombat(cid, combat, var)
   else
       doCombat(cid, combat, var)
       return doCombat(cid, combatFire, var)
   end
 
true :D

I've found another way if someone is interested:

LUA:
local  combat, combatFire = createCombatObject(), createCombatObject()

setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 7)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 5)
setCombatParam(combatFire, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.2, 1, -0.3, 1)

    if math.random(100) < 50 then
       return doCombat(cid, combat, var)
   else
       doCombat(cid, combat, var)
       return doCombat(cid, combatFire, var)
   end

you don't need else here and you missed some crucial parts in your code, namely onCastSpell:
LUA:
local  combat, combatFire = createCombatObject(), createCombatObject()

setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 7)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 5)
setCombatParam(combatFire, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.2, 1, -0.3, 1)

function onCastSpell(cid, var, isHotkey)
    if math.random(100) < 50 then
        doCombat(cid, combatFire, var)
    end
 
    return doCombat(cid, combat, var);
end

But I still think making multiple doCombat calls is unreliable (e.g. the additional doCombat fails we have no indication of this) and the solution proposed in "best answer" is much better in terms of reliability.
 
you don't need else here and you missed some crucial parts in your code, namely onCastSpell:
LUA:
local  combat, combatFire = createCombatObject(), createCombatObject()

setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 7)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 5)
setCombatParam(combatFire, COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.2, 1, -0.3, 1)

function onCastSpell(cid, var, isHotkey)
    if math.random(100) < 50 then
        doCombat(cid, combatFire, var)
    end
 
    return doCombat(cid, combat, var);
end

But I still think making multiple doCombat calls is unreliable (e.g. the additional doCombat fails we have no indication of this) and the solution proposed in "best answer" is much better in terms of reliability.

but this:

LUA:
    if math.random(100) < 50 then
        doCombat(cid, combatFire, var)
    end

will execute only fire field, without damage

also, not sure why would you add:


function onCastSpell(cid, var, isHotkey)
 
but this:

LUA:
    if math.random(100) < 50 then
        doCombat(cid, combatFire, var)
    end

will execute only fire field, without damage

also, not sure why would you add:


function onCastSpell(cid, var, isHotkey)

I can agree the isHotkey here is not necessary. As for the script, look at it once again and try to follow both execution paths available :) This is equivalent of your script, just shorter. end here will only close if statement, the rest of the code will be executed every time. The optional (based on random number) is creating fire field.
 
I can agree the isHotkey here is not necessary. As for the script, look at it once again and try to follow both execution paths available :) This is equivalent of your script, just shorter. end here will only close if statement, the rest of the code will be executed every time. The optional (based on random number) is creating fire field.

LOOl I can see it now xD

and for the isHotkey I was just asking what is its purpose for

thanks
 
LOOl I can see it now xD

and for the isHotkey I was just asking what is its purpose for

thanks

isHotkey has no purpose here :) I just took it from the "best anwer" post, not being aware there's a onCastSpell signature taking only cid and var arguments - I'm not up-to-date with OTS development :)
 
Back
Top