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

TFS 0.X Use with on action

sabodden

Member
Joined
Sep 27, 2019
Messages
138
Reaction score
18
I wanna make UH as action, not spell, but i got a problem:

How get useWith, target
I mean, it u use this UH in other player, not yourself

Code:
    local target = cid
    -- 1 how to check if rune was used in a real player? i mean, not only cid, others players/monsters
    if target == 0 then
        doPlayerSendCancel(cid, "You need to have a target to use this rune.")
        return true
    end


actions/scripts/uh.lua
Code:
local maglv = 3

function onGetFormulaValues(cid)
    local min = ( (((getPlayerMagLevel(cid)) * 100) * 0.5 ) + (40) )
    local max = ( (((getPlayerMagLevel(cid)) * 100) * 1.0 ) + (40) )
    local value = math.random(min, max)
    return value
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local target = cid
    -- 1 how to check if rune was used in a real player? i mean, not only cid, others players/monsters
    if target == 0 then
        doPlayerSendCancel(cid, "You need to have a target to use this rune.")
        return true
    end

    if(os.time() - getPlayerStorageValue(cid, spellcfg_actions_exausted_storage)) < spellcfg_actions_exausted_secs then
       doPlayerSendCancel(cid, "You are exausted.")
       doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
       return true
    end

    if getPlayerMagLevel(cid) < maglv then
        doPlayerSendCancel(cid, "You do not have enought magic level.")
        return true
    end

    doSendMagicEffect(getThingPos(target), CONST_ME_MAGIC_BLUE)

    local dmg = onGetFormulaValues(cid)
    doCreatureAddHealth(cid, dmg)

    setPlayerStorageValue(cid, spellcfg_actions_exausted_storage, os.time())
    doRemoveItem(item.uid, 1)
    return TRUE
end
 
Solution
local target = itemEx.uid
if (not isCreature(target)) then
doPlayerSendCancel(cid, "You need to have a target to use this rune.")
return true
end

And
doCreatureAddHealth(cid, dmg)
To
doCreatureAddHealth(target, dmg)
local target = itemEx.uid
if (not isCreature(target)) then
doPlayerSendCancel(cid, "You need to have a target to use this rune.")
return true
end

And
doCreatureAddHealth(cid, dmg)
To
doCreatureAddHealth(target, dmg)
 
Solution
local target = itemEx.uid
if (not isCreature(target)) then
doPlayerSendCancel(cid, "You need to have a target to use this rune.")
return true
end

And
doCreatureAddHealth(cid, dmg)
To
doCreatureAddHealth(target, dmg)

The problem to use this is:
I have to be close to the target
If for example i'm 2 sqms far for the target, it shows:
"Too far away."
 
Back
Top