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

Trying to identify a party member

Joined
Apr 11, 2015
Messages
98
Reaction score
5
Hello guys, Im having trouble trying to identify a party member in this script:

Lua:
function onStatsChange(cid, attacker, type, combat, value)
    if getCreatureStorage(cid, 1111111) >= 1 then
    if isInParty(cid) == true then
    for _, party in ipairs(getPartyMembers(cid)) do
        if type == STATSCHANGE_HEALTHLOSS and value >= 1 then
            if math.random(1, 100) <= 50 then
           
        print ("worked")
            end
        end
    end

This script works fine, it only activates if the person in the party with the storage takes damage, but I want something different. I want: If the Party Member takes a hit, the script should activate.
I just want the STATSCHANGE_HEALTHLOSS work for the party members, not only when the storage player takes a hit

If this may have been confusing for you, ask me and I will try to explain in another way
 
Solution
@Xikini Sure, I want this way:

There is a Party group, if someone in the party has the storage x, the script start to work. If a random player in the party get hurt, the script will heal him, using this: doCreatureAddHealth(partyMembers, math.random(min, max)).
As it is now, if a player takes damage, the script works for all the party members, and all of them get healed. I want only the player who got damage gets the healing
Lua:
local min, max = 50, 100

function onStatsChange(cid, attacker, type, combat, value)
    if type == STATSCHANGE_HEALTHLOSS then
        if not getPlayerParty(cid) then
            print(getCreatureName(cid) .. " is not in a party.")
            return true
        end
        local...
Lua:
function onStatsChange(cid, attacker, type, combat, value)
    if type == STATSCHANGE_HEALTHLOSS then
        if not getPlayerParty(cid) then
            print(getCreatureName(cid) .. " is not in a party.")
            return true
        end
        local partyMembers = getPartyMembers(cid)
        for i = 1, #partyMembers do
            print(getCreatureName(partyMembers[i]) .. " was affected by the script.")
        end
    end
    return true
end
 
@Xikini Thx for the answer.
It's kinda worked, but I need this storage check (if getCreatureStorage(cid, 1111111) >= 1 then), and if i put it, it does not work, only if the player who has the storage takes a hit. I want if the player who has the storage is in a party, the script works for all the party when someone takes damage
 
@Xikini Thx for the answer.
It's kinda worked, but I need this storage check (if getCreatureStorage(cid, 1111111) >= 1 then), and if i put it, it does not work, only if the player who has the storage takes a hit. I want if the player who has the storage is in a party, the script works for all the party when someone takes damage
Lua:
function onStatsChange(cid, attacker, type, combat, value)
    if type == STATSCHANGE_HEALTHLOSS then
        if not getPlayerParty(cid) then
            print(getCreatureName(cid) .. " is not in a party.")
            return true
        end
        local partyMembers = getPartyMembers(cid)
        local storageFound = 0
        for i = 1, #partyMembers do
            if getCreatureStorage(partyMembers[i], 1111111) >= 1 then
                storageFound = 1
                break
            end
        end
        if storageFound == 1 then
            for i = 1, #partyMembers do
                print(getCreatureName(partyMembers[i]) .. " was affected by the script.")
            end
        end
    end
    return true
end
 
@Xikini Worked perfectly. thank you very much.
One more thing, maybe I am asking to much, but there is a way that only the player who got damaged activates the script just for him, and not for the entire party?
 
@Xikini Worked perfectly. thank you very much.
One more thing, maybe I am asking to much, but there is a way that only the player who got damaged activates the script just for him, and not for the entire party?
Can you tell me exactly how you want that to work?
Normally it's really easy, but seeing as you have the party system, just want to be sure on how you want it.
 
@Xikini Sure, I want this way:

There is a Party group, if someone in the party has the storage x, the script start to work. If a random player in the party get hurt, the script will heal him, using this: doCreatureAddHealth(partyMembers, math.random(min, max)).
As it is now, if a player takes damage, the script works for all the party members, and all of them get healed. I want only the player who got damage gets the healing
 
@Xikini Sure, I want this way:

There is a Party group, if someone in the party has the storage x, the script start to work. If a random player in the party get hurt, the script will heal him, using this: doCreatureAddHealth(partyMembers, math.random(min, max)).
As it is now, if a player takes damage, the script works for all the party members, and all of them get healed. I want only the player who got damage gets the healing
Lua:
local min, max = 50, 100

function onStatsChange(cid, attacker, type, combat, value)
    if type == STATSCHANGE_HEALTHLOSS then
        if not getPlayerParty(cid) then
            print(getCreatureName(cid) .. " is not in a party.")
            return true
        end
        local partyMembers = getPartyMembers(cid)
        local storageFound = 0
        for i = 1, #partyMembers do
            if getCreatureStorage(partyMembers[i], 1111111) >= 1 then
                storageFound = 1
                break
            end
        end
        if storageFound == 1 then
            local amount = math.random(min, max)
            doCreatureAddHealth(cid, amount)
            print(getCreatureName(cid) .. " was healed by the script for " .. amount .. " health.")
        end
    end
    return true
end
 
Solution
@Xikini , worked perfectly, thank you very much.
Do you think this script will cause lag on the server? Not alot of players will have this storage tho
It depends when is stats change called, but in general this code will stop at first if not party check anyway, so it should have no impact on performance.
 
Back
Top