Aller au contenu

Photo

AdjustAlignment() confusion - cant make using a door be the trigger


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
Morbane

Morbane
  • Members
  • 1 883 messages
void main()
{
object oPC = GetLastUsedBy();

if(GetLocalInt(oPC, "divide") == TRUE) return;
AdjustAlignment(oPC, ALIGNMENT_EVIL, 50);

SetLocalInt(oPC, "divide", TRUE);
}
This code should shift oPC's allignment towardf Evil by 50 - but instead nothing happens - it is supposed to happen after a door is actually used to transition not just opening the door - so I guess GetLastUsedBy() is the way to go?

Any known bugs and or fixes or simply better code is welcome

#2
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
The way I think of doors (and i could be wrong here) is something like this. The door itself is just an object that can be opened or closed so you can use the open or close events. And then the actual transition is more like a trigger just standing upright instead of laying on the ground. So you would use the OnClickScript to handle any transition stuff. And the player or what not will be defined as "GetClickingObject();"
I don't think the OnUsed of the door works since you are really just either opening or closing it. And then there is of course the OnFailToOpen if it is locked.
Hopefully this helps. Again I could be wrong about stuff but I think that is generally how it works with doors.

P.S. I beleive there is also a default script that is fired in the OnClick event of all doors and triggers but I can't remember what is it. You would want to execute that script in your custom OnClick script that alters the players alignment. Either that or make sure you add the lines to find the transition destination target and then jump to it.

P.S.S. This is the script that is automatically put into transitions in NWN1 once you set up the transition(Not sure it will help you here but it might since the scripting is similar):


#include "x3_inc_horse"
#include "x0_inc_henai"


void main()
{
    object oClicker=GetClickingObject();
    object oTarget=GetTransitionTarget(OBJECT_SELF);
    location lPreJump=HORSE_SupportGetMountLocation(oClicker,oClicker,0.0); // location before jump
    int bAnim=GetLocalInt(OBJECT_SELF,"bDismountFast"); // community requested fast dismount for transitions if variable is not set (use X3_G0_Transition for animated)
    int nN=1;
    object oOb;
    object oAreaHere=GetArea(oClicker);
    object oAreaTarget=GetArea(oTarget);
    object oHitch;
    int bDelayedJump=FALSE;
    int bNoMounts=FALSE;
    float fX3_MOUNT_MULTIPLE=GetLocalFloat(GetArea(oClicker),"fX3_MOUNT_MULTIPLE");
    float fX3_DISMOUNT_MULTIPLE=GetLocalFloat(GetArea(oClicker),"fX3_DISMOUNT_MULTIPLE");
    if (GetLocalFloat(oClicker,"fX3_MOUNT_MULTIPLE")>fX3_MOUNT_MULTIPLE) fX3_MOUNT_MULTIPLE=GetLocalFloat(oClicker,"fX3_MOUNT_MULTIPLE");
    if (fX3_MOUNT_MULTIPLE<=0.0) fX3_MOUNT_MULTIPLE=1.0;
    if (GetLocalFloat(oClicker,"fX3_DISMOUNT_MULTIPLE")>0.0) fX3_DISMOUNT_MULTIPLE=GetLocalFloat(oClicker,"fX3_DISMOUNT_MULTIPLE");
    if (fX3_DISMOUNT_MULTIPLE>0.0) fX3_MOUNT_MULTIPLE=fX3_DISMOUNT_MULTIPLE; // use dismount multiple instead of mount multiple
    float fDelay=0.1*fX3_MOUNT_MULTIPLE;
    if (!GetLocalInt(oAreaTarget,"X3_MOUNT_OK_EXCEPTION"))
    { // check for global restrictions
        if (GetLocalInt(GetModule(),"X3_MOUNTS_EXTERNAL_ONLY")&&GetIsAreaInterior(oAreaTarget)) bNoMounts=TRUE;
        else if (GetLocalInt(GetModule(),"X3_MOUNTS_NO_UNDERGROUND")&&!GetIsAreaAboveGround(oAreaTarget)) bNoMounts=TRUE;
    } // check for global restrictions
    if (GetLocalInt(oAreaTarget,"X3_NO_MOUNTING")||GetLocalInt(oAreaTarget,"X3_NO_HORSES")||bNoMounts)
    { // make sure all transitioning are not mounted
        if (HorseGetIsMounted(oClicker))
        { // dismount clicker
            bDelayedJump=TRUE;
            AssignCommand(oClicker,HORSE_SupportDismountWrapper(bAnim,TRUE));
            fDelay=fDelay+0.2*fX3_MOUNT_MULTIPLE;
        } // dismount clicker
        oOb=GetAssociate(ASSOCIATE_TYPE_HENCHMAN,oClicker,nN);
        while(GetIsObjectValid(oOb))
        { // check each associate to see if mounted
            if (HorseGetIsMounted(oOb))
            { // dismount associate
                bDelayedJump=TRUE;
                DelayCommand(fDelay,AssignCommand(oOb,HORSE_SupportDismountWrapper(bAnim,TRUE)));
                fDelay=fDelay+0.2*fX3_MOUNT_MULTIPLE;
            } // dismount associate
            nN++;
            oOb=GetAssociate(ASSOCIATE_TYPE_HENCHMAN,oClicker,nN);
        } // check each associate to see if mounted
        if (fDelay>0.1) SendMessageToPCByStrRef(oClicker,111989);
        if (bDelayedJump)
        { // some of the party has/have been mounted, so delay the time to hitch
            fDelay=fDelay+2.0*fX3_MOUNT_MULTIPLE; // non-animated dismount lasts 1.0+1.0=2.0 by default, so wait at least that!
            if (bAnim) fDelay=fDelay+2.8*fX3_MOUNT_MULTIPLE; // animated dismount lasts (X3_ACTION_DELAY+HORSE_DISMOUNT_DURATION+1.0)*fX3_MOUNT_MULTIPLE=4.8 by default, so wait at least that!
        } // some of the party has/have been mounted, so delay the time to hitch
    } // make sure all transitioning are not mounted
    if (GetLocalInt(oAreaTarget,"X3_NO_HORSES")||bNoMounts)
    { // make sure no horses/mounts follow the clicker to this area
        bDelayedJump=TRUE;
        oHitch=GetNearestObjectByTag("X3_HITCHING_POST",oClicker);
        DelayCommand(fDelay,HorseHitchHorses(oHitch,oClicker,lPreJump));
        if (bAnim) fDelay=fDelay+1.8*fX3_MOUNT_MULTIPLE;
    } // make sure no horses/mounts follow the clicker to this area

    SetAreaTransitionBMP(AREA_TRANSITION_RANDOM);

    if (bDelayedJump)
    { // delayed jump
        DelayCommand(fDelay,AssignCommand(oClicker,ClearAllActions()));
        DelayCommand(fDelay+0.1*fX3_MOUNT_MULTIPLE,AssignCommand(oClicker,JumpToObject(oTarget)));
    } // delayed jump
    else
    { // quick jump
        AssignCommand(oClicker,JumpToObject(oTarget));
    } // quick jump
    DelayCommand(fDelay+4.0*fX3_MOUNT_MULTIPLE,HorseMoveAssociates(oClicker));
}

Modifié par GhostOfGod, 17 juillet 2011 - 03:49 .


#3
Morbane

Morbane
  • Members
  • 1 883 messages
GetClickingObject doesnt seem to work either with the way I am trying to do this - I have used AdjustAlignment before and had no problems but it was being called in a conversation so oPC would always be the PCSpeaker. I think my definition of oPC in this script is the problem - the Adjust Alignment function is pretty simple just choose the alignment to Adjust and away we go - or so it would seem.
I will continue to experiment the is a solution I just have to find it.

#4
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Interesting. I tested it in the NWN2 tool set and it worked for me. Just put the script in the OnClick script of the door and define oPC as GetClickingObject.

#5
Morbane

Morbane
  • Members
  • 1 883 messages
doh! forgot to put it in the onclick event - trying it again.........

#6
Morbane

Morbane
  • Members
  • 1 883 messages
The working script:
void main()
{
object oPC = GetClickingObject();

AssignCommand(oPC, ActionJumpToLocation(GetLocation(GetObjectByTag("good_up"))));

if(GetLocalInt(oPC, "divide") == TRUE) return;

AssignCommand(OBJECT_SELF, AdjustAlignment(oPC, ALIGNMENT_EVIL, 50));

SetLocalInt(oPC, "divide", TRUE);
}
Thanks GoG

#7
The Fred

The Fred
  • Members
  • 2 516 messages
I think GetEnteringObject() ~ GetClickingObject() - that is, they're synonymous. It probably makes sense to use the most descriptively appropriate one, though.

#8
Morbane

Morbane
  • Members
  • 1 883 messages
ya i guess technically one would be entering the door as much as they would be clicking it - at least I got it working now - I have been tweaking the area now filling in the gaps to explain such a dramatic alignment change - that is almost as fun as getting a stubborn script to work.