• 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:
Nope, no errors. it changes outfit/removes soul/shows effect but it does not add any regen. I thought it might be caused by trying to find player info before function but that usually returns errors whereas this script returns no errors.
 
Code:
local duration = 1
local tickRate = 1000

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

local regeneration = createConditionObject(CONDITION_REGENERATION)
    setConditionParam(regeneration, CONDITION_PARAM_TICKS, duration * 60 * 1000)
    setConditionParam(regeneration, CONDITION_PARAM_MANATICKS, tickRate)   
    setConditionParam(regeneration, CONDITION_PARAM_HEALTHTICKS, tickRate)
   
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local level = getPlayerLevel(cid)
    local voc = getPlayerVocation(cid)
    local heal = getHeal(voc)
    setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, heal)
    setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, heal)
    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
try this, your code was a giant mess and many things did not work, such as using cid outside onUse where its not defined, etc
 
One edit though. You need to add level into the function to get heal...so it would be this..

Code:
local duration = 1
local tickRate = 1000

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

local regeneration = createConditionObject(CONDITION_REGENERATION)
    setConditionParam(regeneration, CONDITION_PARAM_TICKS, duration * 60 * 1000)
    setConditionParam(regeneration, CONDITION_PARAM_MANATICKS, tickRate)  
    setConditionParam(regeneration, CONDITION_PARAM_HEALTHTICKS, tickRate)
   
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local level = getPlayerLevel(cid)
    local voc = getPlayerVocation(cid)
    local heal = getHeal(voc, level)
    setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, heal)
    setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, heal)
    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
 
Last edited:
Thanks both of you it looks great, there is one problem occurring now:

[29/05/2016 19:02:47] data/actions/scripts/other/soulpotion.lua:6: unexpected symbol near '<'
 
For anyone else that wants the code.

Code:
local duration = 1
local tickRate = 1000

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

local regeneration = createConditionObject(CONDITION_REGENERATION)
setConditionParam(regeneration, CONDITION_PARAM_TICKS, duration * 60 * 1000)
setConditionParam(regeneration, CONDITION_PARAM_MANATICKS, tickRate)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHTICKS, tickRate)

function onUse(cid, item, fromPosition, itemEx, toPosition)
local level = getPlayerLevel(cid)
local voc = getPlayerVocation(cid)
local heal = getHeal(voc, level)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, heal)
setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, heal)
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


For figuring out errors....

This is your error:
Code:
[29/05/2016 19:02:47] data/actions/scripts/other/soulpotion.lua:6: unexpected symbol near '<'


This is what you should look at:
Code:
data/actions/scripts/other/soulpotion.lua:6: unexpected symbol near '<'

Means on line 6 there is an error that is why the 6 is there. If you looked on that line I think you would see that level was missing.
 
the script functions except it still doesn't add the regen and returns this error

[29/05/2016 23:02:00] [Error - Action Interface]
[29/05/2016 23:02:00] data/actions/scripts/other/soulpotion.lua:eek:nUse
[29/05/2016 23:02:00] Description:
[29/05/2016 23:02:00] (luaSetConditionParam) This function can only be used while loading the script.
 
Last edited:
Code:
local duration = 1
local tickRate = 1000

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

local regeneration = createConditionObject(CONDITION_REGENERATION)
setConditionParam(regeneration, CONDITION_PARAM_TICKS, duration * 60 * 1000)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, heal)
setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, heal)
setConditionParam(regeneration, CONDITION_PARAM_MANATICKS, tickRate)
setConditionParam(regeneration, CONDITION_PARAM_HEALTHTICKS, tickRate)

function onUse(cid, item, fromPosition, itemEx, toPosition)
local level = getPlayerLevel(cid)
local voc = getPlayerVocation(cid)
local heal = getHeal(voc, level)
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

Are you even trying to fix the errors yourself?
 
ofcourse i'm trying to fix it myself, it's just that whatever i try it just doesn't work which is why i have turned to the good people on otland who are much much better at scripting than me.
the script now doesn't return any errors but still no regen
 
@tozikrulz
setConditionParam(regeneration, CONDITION_PARAM_HEALTHGAIN, heal) setConditionParam(regeneration, CONDITION_PARAM_MANAGAIN, heal)
1: heal are not on scope to get his value, because of that your condition doesnt works, instead call the function.
local level = getPlayerLevel(cid)
local voc = getPlayerVocation(cid)
local heal = getHeal(voc, level)
2: what purpose of these variables?

3: Also the function getHeal() should get ONLY cid as parameter to get player level and voc.
 
Last edited:
Thank you everyone for helping, i really appreciate it, being a novice scripter.
@Shyzoul this version returned this error:

[30/05/2016 11:26:04] [Error - Action Interface]
[30/05/2016 11:26:04] data/actions/scripts/other/soulpotion.lua
[30/05/2016 11:26:04] Description:
[30/05/2016 11:26:04] (internalGetPlayerInfo) Player not found when requesting player info #3

[30/05/2016 11:26:04] [Error - Action Interface]
[30/05/2016 11:26:04] data/actions/scripts/other/soulpotion.lua
[30/05/2016 11:26:04] Description:
[30/05/2016 11:26:04] (internalGetPlayerInfo) Player not found when requesting player info #6

[30/05/2016 11:26:04] [Error - Action Interface]
[30/05/2016 11:26:04] data/actions/scripts/other/soulpotion.lua
[30/05/2016 11:26:04] Description:
[30/05/2016 11:26:04] data/actions/scripts/other/soulpotion.lua:13: attempt to compare number with boolean
[30/05/2016 11:26:04] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/other/soulpotion.lua)
[30/05/2016 11:26:04] data/actions/scripts/other/soulpotion.lua:6: unexpected symbol near '<'
[30/05/2016 11:26:04] Reloaded actions.
 
these line erros dont match with script i gave you, could you paste whole script, also try to remove local keyword from function.
 
this is the script, from the link you gave.

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)
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

and this returns, with or without local keyword in function.

Code:
[30/05/2016 11:49:48] [Error - Action Interface]
[30/05/2016 11:49:48] data/actions/scripts/other/soulpotion.lua
[30/05/2016 11:49:48] Description:
[30/05/2016 11:49:48] (internalGetPlayerInfo) Player not found when requesting player info #3

[30/05/2016 11:49:48] [Error - Action Interface]
[30/05/2016 11:49:48] data/actions/scripts/other/soulpotion.lua
[30/05/2016 11:49:48] Description:
[30/05/2016 11:49:48] (internalGetPlayerInfo) Player not found when requesting player info #6

[30/05/2016 11:49:48] [Error - Action Interface]
[30/05/2016 11:49:48] data/actions/scripts/other/soulpotion.lua
[30/05/2016 11:49:48] Description:
[30/05/2016 11:49:48] data/actions/scripts/other/soulpotion.lua:13: attempt to compare number with boolean
[30/05/2016 11:49:48] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/other/soulpotion.lua)
[30/05/2016 11:49:48] data/actions/scripts/other/soulpotion.lua:6: unexpected symbol near '<'
[30/05/2016 11:49:48] Reloaded actions.
 
Back
Top