• 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 Spell heal Guild and Party

kennyubuntu

Member
Joined
May 20, 2016
Messages
150
Reaction score
13
I would like to have 2 spells but idk how to do:

1- party heal
2- guild heal

Those spells should heal everyone on screen in your party or in your guild

Is it easy to do?
 
Solution
I guess this:
Lua:
if getPlayerGuildId(pid) > getPlayerGuildId(cid) then

to this:
Lua:
if getPlayerGuildId(pid) == getPlayerGuildId(cid) then
Since this isn't in requests but support I'm not going to write it but I will help you with writing it

So first you should check if player has a party with getPlayerParty(cid) (it returns nil if not)

if yes then you should get party members with getPartyMembers() (returns cids array or false on failure) then you should check if those party members are on the players screen comparing with getSpectators(centerPos, rangex, rangey) (returns array of cids or nil if there aren't any) centerPos being the player position, rangeX the screen width in tiles, rangeY the screen height in tiles for every matching one heal them

if not then check if player has a guild with getPlayerGuildId(cid) then you should check if those guild members are on the players screen comparing with getSpectators(centerPos, rangex, rangey) (returns array of cids or nil if there aren't any) centerPos being the player position, rangeX the screen width in tiles, rangeY the screen height in tiles for every matching one heal them
 
Since this isn't in requests but support I'm not going to write it but I will help you with writing it

So first you should check if player has a party with getPlayerParty(cid) (it returns nil if not)

if yes then you should get party members with getPartyMembers() (returns cids array or false on failure) then you should check if those party members are on the players screen comparing with getSpectators(centerPos, rangex, rangey) (returns array of cids or nil if there aren't any) centerPos being the player position, rangeX the screen width in tiles, rangeY the screen height in tiles for every matching one heal them

if not then check if player has a guild with getPlayerGuildId(cid) then you should check if those guild members are on the players screen comparing with getSpectators(centerPos, rangex, rangey) (returns array of cids or nil if there aren't any) centerPos being the player position, rangeX the screen width in tiles, rangeY the screen height in tiles for every matching one heal them

can u help me to go more far?

party_healing.lua
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

function onCastSpell(cid, var)
    if getPlayerParty(cid) == nil then
        doPlayerSendCancel(cid, "You are not in a Party.")
        return true
    end
    local min = 100
    local max = 200
    -- whole screen
    for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 5, 5, false)) do
        if(isPlayer(tid) and tid ~= cid) then
            -- getPartyMembers()
                -- add hp
        end
    end
    return doCombat(cid, combat, var)
end

guild_healing.lua
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

function onCastSpell(cid, var)
    if getPlayerParty(cid) == nil then
        doPlayerSendCancel(cid, "You are not in a Guild.")
        return true
    end
    local min = 100
    local max = 200
    -- whole screen
    for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 5, 5, false)) do
        if(isPlayer(tid) and tid ~= cid) then
            if getPlayerGuildId(cid) == getPlayerGuildId(tid)
                -- add hp
            end
        end
    end
    return doCombat(cid, combat, var)
end
 
For the healing you should add a callback:
Lua:
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "getMinMax")

And the function that returns minimum healing value and maximum healing value
Lua:
function getMinMax(cid, level, maglevel)
    return 100, 200
end

then you should doCombat in the loop:
Lua:
doCombat(PARTY_MEMBER_ID/GUILD_MEMBER_ID, combat, var)
and after that at the end
Lua:
return true
instead of
Lua:
return doCombat(cid, combat, var)

It should work I guess

Also there:
Lua:
    if getPlayerParty(cid) == nil then
        doPlayerSendCancel(cid, "You are not in a Party.")
        return true
    end
you should
Lua:
return false
because the spell failed

Oh also I forgot about that part:

Lua:
-- getPartyMembers()
You should get the party members array before the loop and then check if their id is in the array, try something like this:
 
Last edited:
For the healing you should add a callback:
Lua:
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "getMinMax")

And the function that returns minimum healing value and maximum healing value
Lua:
function getMinMax(cid, level, maglevel)
    return 100, 200
end

then you should doCombat in the loop:
Lua:
doCombat(PARTY_MEMBER_ID/GUILD_MEMBER_ID, combat, var)
and after that at the end
Lua:
return true
instead of
Lua:
return doCombat(cid, combat, var)

It should work I guess

Also there:
Lua:
    if getPlayerParty(cid) == nil then
        doPlayerSendCancel(cid, "You are not in a Party.")
        return true
    end
you should
Lua:
return false
because the spell failed

Oh also I forgot about that part:

Lua:
-- getPartyMembers()
You should get the party members array before the loop and then check if their id is in the array, try something like this:

party_healing.lua is good now?
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "getMinMax")

function getMinMax(cid, level, maglevel)
    return 100, 200
end

function onCastSpell(cid, var)
    -- check if is in a party
    if getPlayerParty(cid) == nil then
        doPlayerSendCancel(cid, "You are not in a Party.")
        return false
    end
    -- get members around
    local membersList = getPartyMembers(cid)
    local affectedList = {}
    for _, pid in ipairs(membersList) do
        if(getDistanceBetween(getCreaturePosition(pid), pos) <= 36) then
            table.insert(affectedList, pid)
        end
    end
    -- check members size
    if(table.maxn(affectedList) <= 1) then
        doPlayerSendCancel(cid, "There is no party members around.")
        doSendMagicEffect(pos, CONST_ME_POFF)
        return false
    end
    -- add hp
    for _, pid in ipairs(affectedList) do
        doAddCondition(pid, condition)
    end
    return true
end
 
Well yeah, you can also use
Lua:
getDistanceBetween()
but you should keep in mind that number 36

also you need to get the pos after the affectedList like:
Lua:
local pos = getPlayerPosition(cid)

also instead of
Lua:
doAddCondition(pid, condition)
you should use
Lua:
doCombat(pid, combat)

then it should finally work
 
Well yeah, you can also use
Lua:
getDistanceBetween()
but you should keep in mind that number 36

also you need to get the pos after the affectedList like:
Lua:
local pos = getPlayerPosition(cid)

also instead of
Lua:
doAddCondition(pid, condition)
you should use
Lua:
doCombat(pid, combat)

then it should finally work

what are u mean?
how should be that line
if(getDistanceBetween(getCreaturePosition(pid), pos) <= 36) then

???
 
The line is fine, I'm just saying 36 is a distance far longer than the screen size.
You are able to heal someone than isn't on your screen.
If you don't want that then just lower this number.
 
The line is fine, I'm just saying 36 is a distance far longer than the screen size.
You are able to heal someone than isn't on your screen.
If you don't want that then just lower this number.

What should be the number?

What do i doing wrong here?

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
function getMinMax(cid, level, maglevel)
    return 100, 200
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "getMinMax")

function onCastSpell(cid, var)
    -- check if is in a party
    if getPlayerParty(cid) == nil then
        doPlayerSendCancel(cid, "You are not in a Party.")
        return false
    end
    -- get members around
    local pos, membersList = getCreaturePosition(cid), getPartyMembers(cid)
    local affectedList = {}
    for _, pid in ipairs(membersList) do
        if(getDistanceBetween(getCreaturePosition(pid), pos) <= 36) then
            table.insert(affectedList, pid)
        end
    end
    -- check members size
    if(table.maxn(affectedList) <= 1) then
        doPlayerSendCancel(cid, "There is no party members around.")
        doSendMagicEffect(pos, CONST_ME_POFF)
        return false
    end
    -- add hp
    for _, pid in ipairs(affectedList) do
        doCombat(pid, combat)
    end
    return true
end

Code:
[10:13:42.662] [Error - LuaInterface::loadFile] data/spells/scripts/healing/guild_healing.lua:18: 'then' expected near 'end'
[10:13:42.662] [Warning - Event::loadScript] Cannot load script (data/spells/scripts/healing/guild_healing.lua)
[10:13:42.662] data/spells/scripts/healing/guild_healing.lua:18: 'then' expected near 'end'
 
Are you sure it's the correct script because it's the party heal and the problem is in guild_healing.lua

Oh my bad, its the other spell
I posted the wronge error message, the right is:
Code:
[10:21:20.457] [Error - Spell Interface] 
[10:21:20.457] data/spells/scripts/healing/party_healing.lua:onCastSpell
[10:21:20.457] Description: 
[10:21:20.457] attempt to index a number value
[10:21:20.457] stack traceback:
[10:21:20.457]     [C]: in function 'doCombat'
[10:21:20.457]     data/spells/scripts/healing/party_healing.lua:32: in function <data/spells/scripts/healing/party_healing.lua:10>
 
Okay I guess I don't remember those things after all.
Let's just do it the simplest way possible and that's it.
You've tried enough, here's your solution:

Lua:
function onCastSpell(cid, var)
    if getPlayerParty(cid) == nil then
        doPlayerSendCancel(cid, "You are not in a party.")
        return false
    end

    local pos, membersList = getCreaturePosition(cid), getPartyMembers(cid)
    local affectedList = {}
    local positionList = {}
    for _, pid in ipairs(membersList) do
        local pidPos = getCreaturePosition(pid)
        if(getDistanceBetween(pidPos, pos) <= 8) then
            table.insert(affectedList, pid)
            table.insert(positionList, pidPos)
        end
    end

    if(table.maxn(affectedList) <= 1) then
        doPlayerSendCancel(cid, "There is no party members around.")
        doSendMagicEffect(pos, CONST_ME_POFF)
        return false
    end

    for i = 1, #affectedList, 1 do
        doCreatureAddHealth(affectedList[i], math.random(100,200))
        doSendMagicEffect(positionList[i], CONST_ME_MAGIC_BLUE)
    end
    return true
end
 
Okay I guess I don't remember those things after all.
Let's just do it the simplest way possible and that's it.
You've tried enough, here's your solution:

Lua:
function onCastSpell(cid, var)
    if getPlayerParty(cid) == nil then
        doPlayerSendCancel(cid, "You are not in a party.")
        return false
    end

    local pos, membersList = getCreaturePosition(cid), getPartyMembers(cid)
    local affectedList = {}
    local positionList = {}
    for _, pid in ipairs(membersList) do
        local pidPos = getCreaturePosition(pid)
        if(getDistanceBetween(pidPos, pos) <= 8) then
            table.insert(affectedList, pid)
            table.insert(positionList, pidPos)
        end
    end

    if(table.maxn(affectedList) <= 1) then
        doPlayerSendCancel(cid, "There is no party members around.")
        doSendMagicEffect(pos, CONST_ME_POFF)
        return false
    end

    for i = 1, #affectedList, 1 do
        doCreatureAddHealth(affectedList[i], math.random(100,200))
        doSendMagicEffect(positionList[i], CONST_ME_MAGIC_BLUE)
    end
    return true
end

Thank you so much!!!

But what about guild_heal:
Code:
function GetMyGuildMembers(cid)
    local membersList = {}
    for _, name in ipairs(getOnlinePlayers()) do -- Loop through all online players
        local pid = getPlayerByName(name)
        if isPlayer(pid) then
            if getPlayerGuildId(pid) > getPlayerGuildId(cid) then
                table.insert(membersList, pid)
            end
        end
    end
    return membersList
end

function onCastSpell(cid, var)
    if getPlayerGuildId(cid) == 0 then
        doPlayerSendCancel(cid, "You are not in a Guild.")
        return false
    end

    local pos, membersList = getCreaturePosition(cid), GetMyGuildMembers(cid)
    print(membersList)
    local affectedList = {}
    local positionList = {}
    for _, pid in ipairs(membersList) do
        local pidPos = getCreaturePosition(pid)
        if(getDistanceBetween(pidPos, pos) <= 8) then
            table.insert(affectedList, pid)
            table.insert(positionList, pidPos)
        end
    end

    if(table.maxn(affectedList) <= 1) then
        doPlayerSendCancel(cid, "There is no guild members around.")
        doSendMagicEffect(pos, CONST_ME_POFF)
        return false
    end

    for i = 1, #affectedList, 1 do
        doCreatureAddHealth(affectedList[i], math.random(100,200))
        doSendMagicEffect(positionList[i], CONST_ME_MAGIC_BLUE)
    end
    return true
end
 
Thank you so much!!!

But what about guild_heal:
Code:
function GetMyGuildMembers(cid)
    local membersList = {}
    for _, name in ipairs(getOnlinePlayers()) do -- Loop through all online players
        local pid = getPlayerByName(name)
        if isPlayer(pid) then
            if getPlayerGuildId(pid) > getPlayerGuildId(cid) then
                table.insert(membersList, pid)
            end
        end
    end
    return membersList
end

function onCastSpell(cid, var)
    if getPlayerGuildId(cid) == 0 then
        doPlayerSendCancel(cid, "You are not in a Guild.")
        return false
    end

    local pos, membersList = getCreaturePosition(cid), GetMyGuildMembers(cid)
    print(membersList)
    local affectedList = {}
    local positionList = {}
    for _, pid in ipairs(membersList) do
        local pidPos = getCreaturePosition(pid)
        if(getDistanceBetween(pidPos, pos) <= 8) then
            table.insert(affectedList, pid)
            table.insert(positionList, pidPos)
        end
    end

    if(table.maxn(affectedList) <= 1) then
        doPlayerSendCancel(cid, "There is no guild members around.")
        doSendMagicEffect(pos, CONST_ME_POFF)
        return false
    end

    for i = 1, #affectedList, 1 do
        doCreatureAddHealth(affectedList[i], math.random(100,200))
        doSendMagicEffect(positionList[i], CONST_ME_MAGIC_BLUE)
    end
    return true
end

the only difference on guild_heal from party_heal is that there is no function like getPartyMembers (I THINK SO) so i tried to create this GetMyGuildMembers...
but i did something wrong! do u know what?
 
Back
Top