Custom altar script not working as intended

so i have a script in my custom module where if you do a certain action based on your alignment, 3 things are supposed to happen;

visual effect plays
pc plays an animation
alignment changes 1 point

now i can either make the alignment change by 1 or i can make the visual effect play with the animation, but all 3 will not work together, here is my script here;

void main()
{
effect eVFX;

// Get the PC who is in this conversation.
object oPC = GetPCSpeaker();

// Have the PC perform a sequence of actions.
AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_WORSHIP, 1.0, 3.0));

// Apply a visual effect.
eVFX = EffectVisualEffect(VFX_FNF_SUNBEAM);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oPC);

}
void main()
{
object oPC = GetPCSpeaker();
if (GetIsPC(oPC) == TRUE && GetLocalInt(OBJECT_SELF, “nChaosHit”) != 1)

{
    AdjustAlignment(oPC, ALIGNMENT_CHAOTIC, 1);
    SetLocalInt(OBJECT_SELF, "nChaosHit", 1);
    }
}

with this script here, only the visual effect and bowing works, but the alignment change doesnt, which is weird because i used this alignment change everywhere else and it works just fine

also, this is based out of a conversation

You have two scripts there. Which one are you using?

If they are both in the same file maybe the compiler is too stupid to notice and is just running the first main() routine. But really it should fail to compile.

the formatting makes this a bit confusing for me, but if this is one single script, you shouldn’t have two main(). try this :

void main()
{
	object oPC = GetPCSpeaker();	// if object returned is valid, will always be a PC
	effect eVFX = EffectVisualEffect(VFX_FNF_SUNBEAM);
	
	if (GetIsObjectValid(oPC)	// test against being called while character not in conversation
		 && !GetLocalInt(OBJECT_SELF, “nChaosHit”))	// ...& we haven't done this yet
	{
		ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oPC);
		AdjustAlignment(oPC, ALIGNMENT_CHAOTIC, 1);
		SetLocalInt(OBJECT_SELF, "nChaosHit", 1);
	}
}

note that this could present problems if you’re using it in a multi-player environment because it will affect only the first player to access the altar. to make it suitable for multiplayer, you’d have to change the variable name to use a non-ambiguous player identifier.

this is missing the “pray” animation and also i get an error saying;
ERROR: VARIABLE DEFINED WITHOUT TYPE
and it’s highlighting;
&& !GetLocalInt(OBJECT_SELF, “nChaosHit”)) // …& we haven’t done this yet

the goal of the script is this;
have the visual effect play
have the character bow down for 3 seconds
and then have their alignment increase by 1 in the given direction

so if i have too much fluff in there, then by all means it can be taken out, for the alignment part the reason why i have all that “nChaosHit” stuff is because that is the only way an alignment shift would work at all, when using just a normal 1 line of code alignment shift, it never seemed to work

holy flying fignewton sticks boys and jewels, somehow my smooth brain figured it out, to get the outcome of; play visual effect, worship for 3 seconds and have alignment move 1 the script was this;

void main()
{
effect eVFX;

// Get the creature who triggered this event.
object oPC = GetLastUsedBy();

// Apply a visual effect.
eVFX = EffectVisualEffect(VFX_FNF_SUNBEAM);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oPC);

// Have the PC perform a sequence of actions.
AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_WORSHIP, 1.0, 3.0));

// The PC (only) has become more Lawful.

{
object oUsedBy = GetLastUsedBy();
AdjustAlignment(oUsedBy, ALIGNMENT_LAWFUL, 1, FALSE);
}
}

ah. when i copied/pasted your code, i should have noticed that the web site had ‘helpfully’ formatted the variable name, placing it between ‘smart’ quotes rather than ‘straight’ quotes, and unfortunately i didn’t have an nwn in front of me at the time to test-compile it. in any case, i see that in the meantime you’ve found a solution that works for you.  great!   :slight_smile:

1 Like