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

onuse item regen hp/mp mostly finished script that won't work

tozikrulz

New Member
Joined
Jun 10, 2009
Messages
46
Reaction score
1
Hello, I've made a script which will = remove soul, change outfit for 1 min and add mp/hp regeneration for 1 min, i'm not a good scripter (come back on ots after 6 years of no scripting) but i think the script looks like it should almost work and yet it does not. If you have some spare time could you fix this script for me so i could learn from my mistakes.
tfs 0.3.6 no errors returned
here is the script:
Code:
local duration = 1
local level = getPlayerLevel(cid)
local voc = getPlayerVocation(cid)
    if level > 0 and < 150 then
    if isInArray({1,5,9,2,6,10}, voc) then
        heal = level * 7.5
    elseif level > 0 and < 150 then
    if isInArray({3,7,11}, voc) then
        heal = level * 10
    elseif level > 0 and < 150 then
    if isInArray({4,8,12}, voc) then
        heal = level * 13
    elseif level > 149 then
    if isInArray({1,5,9,2,6,10}, voc) then
        heal = level * 10
    elseif level > 149 then
    if isInArray({3,7,11}, voc) then
        heal = level * 13
    elseif level > 149 then
    if isInArray({4,8,12}, voc) then
        heal = level * 17
local regeneration = createConditionObject(CONDITION_REGENERATION)
    setConditionParam(regeneration, CONDITION_PARAM_TICKS, duration * 60 * 1000)
    setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, heal)
    setConditionParam(regeneration, CONDITION_PARAM_HEALTHTICKS, 1000)
    setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, heal)
    setConditionParam(regeneration, CONDITION_PARAM_MANATICKS, 1000)

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 7443 then
    if getPlayerSoul(cid) >= 100 then
        doSetCreatureOutfit(cid, {lookType= 12}, duration * 60 * 1000)
        doPlayerAddSoul(cid, -100)
        doAddCondition(cid, regeneration)
        doSendMagicEffect(fromPosition, CONST_ME_MORTAREA)
    end
    end
    return TRUE
end

Thank you for taking the time to read my problem
 
Last edited:
@tozikrulz i see, i tested same script but with 1.x interface and works well, when i run through compat.lua getPlayerLevel(cid) and getPlayerVocation(cid) are also returning boolean to me, and it is out my knowledge, i dont touch a script of 0.3~ since back 2009, so i cant remember how player is indexed in this tfs, ask to anyone that still up with this lua api interface, i dont know why it is returning as a boolean.
 
i understand, i have just come back from 6 years of no scripting and i wasn't the best scripter to begin with lol.

the script now returns this error:
Code:
[30/05/2016 13:02:24] [Error - Action Interface]
[30/05/2016 13:02:24] data/actions/scripts/other/soulpotion.lua:onUse
[30/05/2016 13:02:24] Description:
[30/05/2016 13:02:24] (luaSetConditionParam) This function can only be used while loading the script.

[30/05/2016 13:02:24] [Error - Action Interface]
[30/05/2016 13:02:24] data/actions/scripts/other/soulpotion.lua:onUse
[30/05/2016 13:02:24] Description:
[30/05/2016 13:02:24] (luaDoAddCondition) Condition not found

I'm beginning to think this might not be possible
 
you cannot script conditions and combats inside an event, it needs to be pre loaded at the start.
hence what you're trying to accomplish will simply not work
ex:
Code:
local regeneration = createConditionObject(CONDITION_REGENERATION)
setConditionParam(regeneration, CONDITION_PARAM_TICKS, duration * 60 * 1000)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, heal)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHTICKS, 1000)
setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, heal)
setConditionParam(regeneration, CONDITION_PARAM_MANATICKS, 1000)

function onUse(cid, item, fromPosition, itemEx, toPosition)
end
will work
however this will not:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local regeneration = createConditionObject(CONDITION_REGENERATION)
setConditionParam(regeneration, CONDITION_PARAM_TICKS, duration * 60 * 1000)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, heal)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHTICKS, 1000)
setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, heal)
setConditionParam(regeneration, CONDITION_PARAM_MANATICKS, 1000)
end
since you try to load the condition inside the event.
 
well you could create your own condition system and make use of addevent that would be a good way aswell.
ex:
Code:
regeneration = {}

function regen(cid, n, interval, maxticks)
   n = n or 0
   if isPlayer(cid) then
     if n <= maxticks then
       local formula = math.random((player:getMagicLevel()* 4  + player:getMagicLevel() / 4), (player:getMagicLevel() * 6 + player:getMagicLevel() / 3))
       doTargetCombatHealth(cid, cid, COMBAT_HEALING, formula, formula, CONST_ME_MAGIC_BLUE)
       regeneration[cid] = addEvent(regen,interval,cid, n+1, maxticks)
     end
   end
   return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if regeneration[cid] ~= nil then
     stopEvent(regeneration[cid])
   end
   regen(cid, 0, 1000, 10) -- 10 ticks each 1 second
   return true
end
 
@Evil Hero i know that, first time i send the for him was outside of events, but somehow (or idk how 0.3 works) his function just cant index cid and return all cid getvalues as a booleans, take a look http://pastebin.com/eirrSGDb, do you know why? on tfs 1.x i tested (with syntax that i know) and worked fine, i just get interested how 0.3 index cid.
 
@Evil Hero i know that, first time i send the for him was outside of events, but somehow (or idk how 0.3 works) his function just cant index cid and return all cid getvalues as a booleans, take a look http://pastebin.com/eirrSGDb, do you know why? on tfs 1.x i tested (with syntax that i know) and worked fine, i just get interested how 0.3 index cid.
what you pasted on pastebin will not work doesn't matter if it's 1.x or 0.3, you try to get cid outside of the event where it returns nil.
 
@Evil Hero
1: actually i could get whole return with p = Player() p:getLevel() p:getVocation():getId()
returned all correct values i just dont know how to declare cid in tfs 0.3
2: if i cant get cid outside of event how can i make custom libs? i mean i have saved some libs that i made long time ago that still working, one of them that i tested seens like that
function usingVIPSet(cid)
local voc = getPlayerVocation(cid)
if voc == x then
do thing
end
this lib still working even on 1.2 because of compat.lua, but here cid also was declared outside of any event how it get indexed so?
 
Last edited:
when you create a function and register it the variables are just there as an empty shell until you call the function and fill them
ex:
Code:
function test(player) print(player) end
player is an empty variable until you call the function itself
Code:
test(player)
which equals nil atm as player is nowhere declared.
same as in the way you try to do it right now.
 
@Evil Hero
1: actually i could get whole return with p = Player() p:getLevel() p:getVocation():getId()
returned all correct values i just dont know how to declare cid in tfs 0.3
2: if i cant get cid outside of event how can i make custom libs? i mean i have saved some libs that i made long time ago that still working, one of them that i tested seens like that
function usingVIPSet(cid)
local voc = getPlayerVocation(cid)
if voc == x then
do thing
end
this lib still working even on 1.2 because of compat.lua, but here cid also was declared outside of any event how it get indexed so?
usingVIPSet is a function there, and you most likely call on it with usingVIPSet(cid) somewhere else
 
@Zothion thats the point, tozikrulz's function does just the same and it cant index cid, it return playerGetLevel(cid) and playerGetVocation(cid) as a boolean (probably default scenario) because couldnt index this values, take a look at funcion getHeal(cid) here http://pastebin.com/eirrSGDb
 
and where do you call getHeal() in that pastebin? where you set condition params, and where are those? outside onUse, and where is cid defined? inside onUse
the scope where cid is defined in the pastebin is line 45-55. getHeal(cid) is called on 40/41, where cid doesnt exist in any way, so its essentially getHeal(nil)
 
look...
It calls all of this first:
Code:
local duration = 1
local tickRate = 1000

local function getHeal(cid)
    local level = getPlayerLevel(cid)
    local voc = getPlayerVocation(cid)
    local heal = 0

    if voc == 0 then
        return false
    end

    if level > 0 and level < 150 then
        if isInArray({1,5,9,2,6,10}, voc) then
            heal = level * 7.5
            return heal
        elseif isInArray({3,7,11}, voc) then
            heal = level * 10
            return heal
        elseif isInArray({4,8,12}, voc) then
            heal = level * 13
            return heal
        end
    elseif level > 149 then
        if isInArray({1,5,9,2,6,10}, voc) then
            heal = level * 10
            return heal
            elseif isInArray({3,7,11}, voc) then
                heal = level * 13
                return heal
            elseif isInArray({4,8,12}, voc) then
                heal = level * 17
                return heal
        end
    end
end

local regeneration = createConditionObject(CONDITION_REGENERATION)
setConditionParam(regeneration, CONDITION_PARAM_TICKS, duration * 60 * 1000)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, getHeal(cid))
setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, getHeal(cid))
setConditionParam(regeneration, CONDITION_PARAM_MANATICKS, tickRate)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHTICKS, tickRate)
before it even touches the onUse event, where you basicly declare cid as something.
That is why this will always throw an error:
Code:
setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, getHeal(cid))
setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, getHeal(cid))
as it's loaded way before you even use the event, where you declare cid.
 
hm get that, there is anyway to declare outside of an function? i used to do on tfs 1.x
local p = Player()
p:getLevel()
and works fine.
 
Code:
local duration = 60 * 1000
local tickRate = 1000
local level = {149, 150}

local x = {
    [{1,5,9,2,6,10}] = function(level) local multiplier = level < 150 and 7.5 or 10 return level * multiplier end,
    [{3,7,11}] = function(level) local multiplier = level < 150 and 10 or 13 return level * multiplier end,
    [{4,8,12}] = function(level) local multiplier = level < 150 and 13 or 17 return level * multiplier end,
}

local regeneration = {}

for vocation, func in pairs(x) do
    regeneration[vocation] = {}
    for n = 1, #level do
        regeneration[vocation][level[n]] = createConditionObject(CONDITION_REGENERATION)
        setConditionParam(regeneration[vocation][level[n]], CONDITION_PARAM_TICKS, duration)
        setConditionParam(regeneration[vocation][level[n]], CONDITION_PARAM_HEALTHGAIN, func(level[n]))
        setConditionParam(regeneration[vocation][level[n]], CONDITION_PARAM_MANAGAIN, func(level[n]))
        setConditionParam(regeneration[vocation][level[n]], CONDITION_PARAM_MANATICKS, tickRate)
        setConditionParam(regeneration[vocation][level[n]], CONDITION_PARAM_HEALTHTICKS, tickRate)
    end
end
--[[
function returnKey(a, f)
    for k, v in pairs(a) do
        if k == f then
            return k
        end
    end
    return false
end
]]
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local playerLevel = getPlayerLevel(cid)
    local playerVocation = getPlayerVocation(cid)
    if item.itemid == 7443 then
        if getPlayerSoul(cid) >= 100 then
            doSetCreatureOutfit(cid, {lookType = 12}, duration)
            doPlayerAddSoul(cid, -100)
            for possibleVocations, levelNeeded in pairs(regeneration) do
                if isInArray(possibleVocations, playerVocation) then
                    --local key = returnKey(levelNeeded, playerLevel <= level[1] and level[1] or level[2])
                    local key = playerLevel <= level[1] and level[1] or level[2]
                    --if key then
                        doAddCondition(cid, regeneration[possibleVocations][key])
                        doSendMagicEffect(fromPosition, CONST_ME_MORTAREA)
                        return true
                    --end
                end
            end
        else
            doPlayerSendCancel(cid, "Sorry, you don't have enough soul.")
        end
    end
    return true
end
:)

I edited it because I thought the function returnkey was redundant, since the argument being passed was exactly the value being return :p
Code:
local key = returnKey(levelNeeded, playerLevel <= level[1] and level[1] or level[2])
 
Last edited:
Back
Top