Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with chain spells #3160

Open
2 of 5 tasks
Regeton5306 opened this issue Nov 28, 2024 · 10 comments · Fixed by jprzimba/crystalserver#11
Open
2 of 5 tasks

Problem with chain spells #3160

Regeton5306 opened this issue Nov 28, 2024 · 10 comments · Fixed by jprzimba/crystalserver#11
Labels
Priority: Low Minor impact Status: Pending Test This PR or Issue requires more testing Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@Regeton5306
Copy link

Priority

Medium

Area

  • Datapack
  • Source
  • Map
  • Other

What happened?

When you apply chain spell to a creature, the spell activates for other creatures, including NPCs, Although it doesn't damage them, it just activates the chaining and the effect on them.

image

What OS are you seeing the problem on?

Windows

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Regeton5306 Regeton5306 added the Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Nov 28, 2024
@github-actions github-actions bot added Priority: Medium This issue may be impactful and needs some attention. Status: Pending Test This PR or Issue requires more testing labels Nov 28, 2024
@murilo09 murilo09 added Priority: Low Minor impact and removed Priority: Medium This issue may be impactful and needs some attention. labels Dec 3, 2024
@lBaah
Copy link

lBaah commented Dec 8, 2024

Chain spells have a function called canChain where you can select who is going to be part of the chain:

Example to select only players:

function canChain(creature, target)
	if target:isPlayer() then
		return true
	end
	return false
end

Remember to set the callback:
combat:setCallback(CALLBACK_PARAM_CHAINPICKER, "canChain")

@Regeton5306
Copy link
Author

Chain spells have a function called canChain where you can select who is going to be part of the chain:

Example to select only players:

function canChain(creature, target)
	if target:isPlayer() then
		return true
	end
	return false
end

Remember to set the callback: combat:setCallback(CALLBACK_PARAM_CHAINPICKER, "canChain")

Does that also apply to player summons and that the chain spell effect does not come out within the safe zone?

@lBaah
Copy link

lBaah commented Dec 9, 2024

The script is going to do what you tell it to do. In my example it will pick only players to chain: if target:isPlayer() then.

@Mortera-world
Copy link

below this line in combat.cpp

for (const auto &spectator : spectators) {
            if (!spectator || visited.contains(spectator->getID())) {
                continue;
            } 

ADD

            if (spectator->getZoneType() == ZONE_PROTECTION) {
                visited.insert(spectator->getID());
                continue;
            }
            if (spectator->getNpc()) {
                visited.insert(spectator->getID());
                continue;
            }
            if (spectator == caster) {
                visited.insert(spectator->getID());
                continue;
            }
            const auto& casterPlayer = caster->getPlayer();
            const auto& casterMonster = caster->getMonster();
            const auto& spectatorPlayer = spectator->getPlayer();
			const auto& spectatorSummon = spectator->isSummon();

            if (casterPlayer) {
                if (casterPlayer->hasSecureMode()) {
                    if (spectatorPlayer) {
                        visited.insert(spectator->getID());
                        continue;
                    }
                    if (spectatorSummon && spectator->getMaster() && spectator->getMaster()->getPlayer()) {
                        visited.insert(spectator->getID());
                        continue;
                    }
                }
            } else if (casterMonster) {
                if (spectatorSummon) {
                    const auto& master = spectator->getMaster();
                    if (!master || !master->getPlayer()) {
                        visited.insert(spectator->getID());
                        continue;
                    }
                } else if (!spectator->getPlayer()) {
                    visited.insert(spectator->getID());
                    continue;
                }
            } 

This worked for me, already tested in chain attack, amp res, weapons with chain, everything seems to be fine

@Regeton5306
Copy link
Author

below this line in combat.cpp

for (const auto &spectator : spectators) {
            if (!spectator || visited.contains(spectator->getID())) {
                continue;
            } 

ADD

            if (spectator->getZoneType() == ZONE_PROTECTION) {
                visited.insert(spectator->getID());
                continue;
            }
            if (spectator->getNpc()) {
                visited.insert(spectator->getID());
                continue;
            }
            if (spectator == caster) {
                visited.insert(spectator->getID());
                continue;
            }
            const auto& casterPlayer = caster->getPlayer();
            const auto& casterMonster = caster->getMonster();
            const auto& spectatorPlayer = spectator->getPlayer();
			const auto& spectatorSummon = spectator->isSummon();

            if (casterPlayer) {
                if (casterPlayer->hasSecureMode()) {
                    if (spectatorPlayer) {
                        visited.insert(spectator->getID());
                        continue;
                    }
                    if (spectatorSummon && spectator->getMaster() && spectator->getMaster()->getPlayer()) {
                        visited.insert(spectator->getID());
                        continue;
                    }
                }
            } else if (casterMonster) {
                if (spectatorSummon) {
                    const auto& master = spectator->getMaster();
                    if (!master || !master->getPlayer()) {
                        visited.insert(spectator->getID());
                        continue;
                    }
                } else if (!spectator->getPlayer()) {
                    visited.insert(spectator->getID());
                    continue;
                }
            } 

This worked for me, already tested in chain attack, amp res, weapons with chain, everything seems to be fine

That worked, thanks

@murilo09 murilo09 reopened this Dec 9, 2024
@murilo09
Copy link
Contributor

murilo09 commented Dec 9, 2024

@Mortera-world can you open a PR?

@lBaah
Copy link

lBaah commented Dec 9, 2024

@Mortera-world can you open a PR?

The reason why CALLBACK_PARAM_CHAINPICKER exists is to resolve this. No PR needed. This is not an issue, as the spell is misconfigured.

@Mortera-world
Copy link

@Mortera-world can you open a PR?

The reason why CALLBACK_PARAM_CHAINPICKER exists is to resolve this. No PR needed. This is not an issue, as the spell is misconfigured.

Sorry, I tried many ways to correct this from the spell but I had no results

I tried this and it crashed, I tried in several ways and it crashed, from the spell you can't make the chain magic not enter safe zones

function canChain(creature, target)
    if not creature or not target then
        return false
    end

    if target:isPlayer() then
        return true
    elseif target:isSummon() then
        local master = target:getMaster()
        if master and master:isPlayer() and master == creature then
            return true
        end
    end

    return false
end

combat:setCallback(CALLBACK_PARAM_CHAINPICKER, "canChain")

sorry I don't know how I can correct this from the spell because many ways I tried gave me a crash on the server

@lBaah
Copy link

lBaah commented Dec 9, 2024

The chain enters protection zone because you don't check if the target is in protection zone.

if target:getPosition():isProtectionZoneTile() then
        return false -- false means it will not chain this target
end

When you do

if target:isPlayer() then
        return true
end

it will chain the player, because you are telling it is TRUE to chain this target regardless of it's position.

@Mortera-world
Copy link

-- false means it will not chain this target

I repeat, I tried it in many ways including safe zone checks, if the caster has pz or skull, the fact is that being a target it only works with the target, what follows after is the chain and that does not apply that target order, I imagine why it always hit in a safe zone even having verification that it does not

In fact, I had that problem for a long time and no matter how much I asked for help, I didn't find a solution or no one wanted to share it. That was the solution for me and it worked for me. So far, it hasn't given me any problems.
I tested the script with many canChain and onChain checks, I even tried to test some things from the Chivalrous Challenge magic and the result for the chain magic of the creatures was always the same, I couldn't make it not cast the chain at NPCs, at other creatures, at the summons, that it didn't enter the safe zone.

If later there is someone who shares the spell correctly I will use them, as long as that works well for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low Minor impact Status: Pending Test This PR or Issue requires more testing Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants