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

"function can only be used while being loaded"

AnarchGov

Member
Joined
Oct 3, 2011
Messages
263
Reaction score
6
function onUseWeapon(cid, var)
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)
local level = getPlayerLevel(cid)
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -50-level, 0, -100-(level*2), 0)
return doCombat(cid, combat, var)
end
So yeah basically thats what it says when i try to use this script. Anyone know whats wrong with it? Rep++
 
Here's the exact error it shows:


[14/02/2012 14:48:28] [Error - Weapon Interface]
[14/02/2012 14:48:28] data/weapons/scripts/attackformula.lua:onUseWeapon
[14/02/2012 14:48:28] Description:
[14/02/2012 14:48:28] (luaSetCombatFormula) This function can only be used while loading the script.

[14/02/2012 14:48:28] [Error - Weapon Interface]
[14/02/2012 14:48:28] data/weapons/scripts/attackformula.lua:onUseWeapon
[14/02/2012 14:48:28] Description:
[14/02/2012 14:48:28] (luaDoCombat) Combat not found
 
PHP:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)

function onUseWeapon(cid, var)
local level = getPlayerLevel(cid)
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -50-level, 0, -100-(level*2), 0)
return doCombat(cid, combat, var)
end

try this
 
CombatObjects are loaded as soon as the server is starting up, you cannot define those objects in functions, instead you have to do it beforehand and THEN execute them via doCombat()
Should look like this:
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)
local level = getPlayerLevel(cid)
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -50-level, 0, -100-(level*2), 0)

function onUseWeapon(cid, var)
	return doCombat(cid, combat, var)
end
But there's still something missing, it won't work either.
 
PHP:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)

function onUseWeapon(cid, var)
local level = getPlayerLevel(cid)
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -50-level, 0, -100-(level*2), 0)
return doCombat(cid, combat, var)
end

try this

same error:

[14/02/2012 15:29:20] [Error - Weapon Interface]
[14/02/2012 15:29:20] data/weapons/scripts/attackformula.lua:onUseWeapon
[14/02/2012 15:29:20] Description:
[14/02/2012 15:29:20] (luaSetCombatFormula) This function can only be used while loading the script.

[14/02/2012 15:29:20] [Error - Weapon Interface]
[14/02/2012 15:29:20] data/weapons/scripts/attackformula.lua:onUseWeapon
[14/02/2012 15:29:20] Description:
[14/02/2012 15:29:20] (luaSetCombatFormula) This function can only be used while loading the script.
 
Try my script above and tell me the errors please.

[14/02/2012 15:40:29] [Error - Weapon Interface]
[14/02/2012 15:40:29] data/weapons/scripts/attackformula.lua
[14/02/2012 15:40:29] Description:
[14/02/2012 15:40:29] data/weapons/scripts/attackformula.lua:5: attempt to perform arithmetic on local 'level' (a boolean value)
[14/02/2012 15:40:29] [Warning - Event::loadScript] Cannot load script (data/weapons/scripts/attackformula.lua)

thats the error for yours :O
 
and this one?
LUA:
local level = getPlayerLevel(cid)
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -(level+50), 0, -((level*2)+100), 0)
 
function onUseWeapon(cid, var)
	return doCombat(cid, combat, var)
end
 
and this one?
LUA:
local level = getPlayerLevel(cid)
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -(level+50), 0, -((level*2)+100), 0)
 
function onUseWeapon(cid, var)
	return doCombat(cid, combat, var)
end


[14/02/2012 15:53:02] [Error - Weapon Interface]
[14/02/2012 15:53:02] data/weapons/scripts/attackformula.lua
[14/02/2012 15:53:02] Description:
[14/02/2012 15:53:02] (internalGetPlayerInfo) Player not found when requesting player info #3

[14/02/2012 15:53:02] [Error - Weapon Interface]
[14/02/2012 15:53:02] data/weapons/scripts/attackformula.lua
[14/02/2012 15:53:02] Description:
[14/02/2012 15:53:02] data/weapons/scripts/attackformula.lua:5: attempt to perform arithmetic on local 'level' (a boolean value)
[14/02/2012 15:53:02] [Warning - Event::loadScript] Cannot load script (data/weapons/scripts/attackformula.lua
 
Aight,
you'd have to use fixed values for
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -500, 0, -1000, 0)
then it'll work, like
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -500, 0, -1000, 0)
 
function onUseWeapon(cid, var)
	return doCombat(cid, combat, var)
end
That'll work, but with fixed values though...
No clue how to involve the playerLevel ...
 
Aight,
you'd have to use fixed values for
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -500, 0, -1000, 0)
then it'll work, like
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)
setCombatFormula(combat, COMBAT_FORMULA_DAMAGE, -500, 0, -1000, 0)
 
function onUseWeapon(cid, var)
	return doCombat(cid, combat, var)
end
That'll work, but with fixed values though...
No clue how to involve the playerLevel ...

Damn. That's the part i needed help with :P.
 
Try that:
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)

function getCombatFormulas(cid, lv, maglv)
    local formula_min = (lv+50)
    local formula_max = ((lv*2)+100)

    if(formula_max < formula_min) then
        local tmp = formula_max
        formula_max = formula_min
        formula_min = tmp
    end
    return formula_min, formula_max
end 
setCombatCallback(combat, CALLBACK_FORMULA_DAMAGE, "getCombatFormulas")
function onUseWeapon(cid, var)
	return doCombat(cid, combat, var)
end
I'm laughing my ass off if that works xD
I suck at spells and such...
 
Try that:
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_BURSTARROW)

function getCombatFormulas(cid, lv, maglv)
    local formula_min = (lv+50)
    local formula_max = ((lv*2)+100)

    if(formula_max < formula_min) then
        local tmp = formula_max
        formula_max = formula_min
        formula_min = tmp
    end
    return formula_min, formula_max
end 
setCombatCallback(combat, CALLBACK_FORMULA_DAMAGE, "getCombatFormulas")
function onUseWeapon(cid, var)
	return doCombat(cid, combat, var)
end
I'm laughing my ass off if that works xD
I suck at spells and such...

14/02/2012 16:23:19] [Error - Weapon Interface]
[14/02/2012 16:23:19] data/weapons/scripts/attackformula.lua
[14/02/2012 16:23:19] Description:
[14/02/2012 16:23:19] (luaSetCombatCallBack) 0 is not a valid callback key.
[14/02/2012 16:23:19] [Warning - Weapons::registerEvent] Duplicate registered item with id: 7437
[14/02/2012 16:23:19] Combat::setCallback - Unknown callback type: 0

[14/02/2012 16:23:19] [Error - Weapon Interface]
[14/02/2012 16:23:19] data/weapons/scripts/attackformula.lua
[14/02/2012 16:23:19] Description:
[14/02/2012 16:23:19] (luaSetCombatCallBack) 0 is not a valid callback key.
 
Back
Top