Aller au contenu

Photo

Toggle Darkvision on/off via Script - how to?


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

#1
JockX

JockX
  • Members
  • 15 messages
Hi,
I am trying to give my PC a temporary darkvision ability, that wears off after several hours. I tried different approaches, and so far the best result i got with simple FeatAdd() / DelayCommand() / FeatRemove() functions, and just added racial/class darkvision to my PC, as it saved me the hassle with solving UI issues.

Or so I thought...

After I swich darkvision mode on - the blue 60feet circle appears and everything works great, and if I switch it off again and wait for few hours the feat disappears from the character sheet, UI icon from bottom-right corner vanishes and everything is just perfect.
Problem that if FEAT_DARKVISION is removed from PC while darkvision toggle is ON, the visual effect (light and 60feet circle around PC) are still on, and can't be turned off, since there is no UI icon anymore... :crying:

Can anyone help me figure out what exactly are these effects and how to create/remove them at will with scripting, or how to force PC to toggle off darkvision just before the feat is removed from character?

#2
Shaughn78

Shaughn78
  • Members
  • 637 messages
I don't know of a way to toggle on and off he darkvision via script. But with the remove script you could use a loop to check all the effects on the player and remove the darkvision. Not at the toolset and off hand not sure how you would identify the darkvision effect.



Just a general comment. Are you checking for the darkvision feat before you apply it to the player. Someone would be bummed if their race gave them darkvision and you stole it.

#3
JockX

JockX
  • Members
  • 15 messages

Shaughn78 wrote...

I don't know of a way to toggle on and off he darkvision via script. But with the remove script you could use a loop to check all the effects on the player and remove the darkvision. Not at the toolset and off hand not sure how you would identify the darkvision effect.

Hmm... Thats something - I'll look into it. Thanks.

Just a general comment. Are you checking for the darkvision feat before you apply it to the player. Someone would be bummed if their race gave them darkvision and you stole it.

Of course, I created checks just before applying it and just before removing it - in case PC leveled up as, say, Shadowdancer in the meantime.

EDIT: Am I doing something wrong? There seems not to be any valid effect on PC.
Also,

RemoveSEFFromObject(oCreature, "fx_dark_vision.sef");

didn't work.

Modifié par JockX, 04 décembre 2010 - 07:16 .


#4
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
This is how you set and get it...
SetActionMode(oCharacter,ACTION_MODE_STEALTH,bActive);
GetActionMode(oCharacter,ACTION_MODE_STEALTH);

Instead of ACTION_MODE_STEALTH use 24 ( or define a new constant )

This returns a string describing mode
/**  
* Description
* @author
* @param 
* @see 
* @return 
*/
string CSLTargetActionModeToString( object oTarget )
{
		string sMessage = "";
		if ( GetActionMode(oTarget, 0) ) { sMessage += "Detect, "; } // Known
		if ( GetActionMode(oTarget, 1) ) { sMessage += "Stealth, "; } // Known
		if ( GetActionMode(oTarget, 2) ) { sMessage += "Parry, "; } // Known
		if ( GetActionMode(oTarget, 3) ) { sMessage += "Power Attack, "; } // Known
		if ( GetActionMode(oTarget, 4) ) { sMessage += "Improved Power Attack, "; } // Known
		if ( GetActionMode(oTarget, 5) ) { sMessage += "Counter Spell, "; } // Known
		if ( GetActionMode(oTarget, 6) ) { sMessage += "Flurry of Blows, "; } // Known
		if ( GetActionMode(oTarget, 7) ) { sMessage += "Rapid Shot, "; } // Known
		if ( GetActionMode(oTarget, 8) ) { sMessage += "Combat Expertise, "; } // Known
		if ( GetActionMode(oTarget, 9) ) { sMessage += "Improved Combat Expertise, "; } // Known
		if ( GetActionMode(oTarget, 10) ) { sMessage += "Defensive Casting, "; } // Known
		if ( GetActionMode(oTarget, 11) ) { sMessage += "Dirty Fighting, "; } // Known
		if ( GetActionMode(oTarget, 12) ) { sMessage += "Defensive Stance, "; } // need to verify
		if ( GetActionMode(oTarget, 13) ) { sMessage += "Taunt, "; } // need to verify
		if ( GetActionMode(oTarget, 14) ) { sMessage += "Tracking, "; } // Known
		if ( GetActionMode(oTarget, 15) ) { sMessage += "Inspire Courage, "; } // need to verify
		if ( GetActionMode(oTarget, 16) ) { sMessage += "Inspire Competance, "; } // need to verify
		if ( GetActionMode(oTarget, 17) ) { sMessage += "Inspire Defense, "; } // need to verify
		if ( GetActionMode(oTarget, 18) ) { sMessage += "Regeneration, "; } // need to verify
		if ( GetActionMode(oTarget, 19) ) { sMessage += "Tougness, "; } // need to verify
		if ( GetActionMode(oTarget, 20) ) { sMessage += "Slowing, "; } // need to verify
		if ( GetActionMode(oTarget, 21) ) { sMessage += "Jarring, "; } // need to verify
		if ( GetActionMode(oTarget, 22) ) { sMessage += "MISSING 22, "; } // not even a guess
		if ( GetActionMode(oTarget, 23) ) { sMessage += "Rescue, "; } // need to verify
		if ( GetActionMode(oTarget, 24) ) { sMessage += "NightVision, "; }  // need to verify
		if ( GetActionMode(oTarget, 25) ) { sMessage += "Hellfire Blast, "; } // Known
		if ( GetActionMode(oTarget, 26) ) { sMessage += "Hellfire Shield, "; } // Known
		if ( GetActionMode(oTarget, 27) ) { sMessage += "Swimming, "; }  // This i am trying to add
		if ( GetActionMode(oTarget, 28) ) { sMessage += "Levitating, "; }  // This i am trying to add
		if ( GetActionMode(oTarget, 29) ) { sMessage += "Flying, "; }  // This i am trying to add
		if ( GetActionMode(oTarget, 30) ) { sMessage += "MISSING 30, "; }
		if ( GetActionMode(oTarget, 31) ) { sMessage += "MISSING 31, "; }
		
		if ( sMessage != "" )
		{
			return GetStringLeft(sMessage, GetStringLength(sMessage)-2);
		}
		return "";
}

Modifié par painofdungeoneternal, 05 décembre 2010 - 12:59 .


#5
JockX

JockX
  • Members
  • 15 messages

painofdungeoneternal wrote...

This is how you set and get it...

SetActionMode(oCharacter,ACTION_MODE_STEALTH,bActive);
GetActionMode(oCharacter,ACTION_MODE_STEALTH);

Instead of ACTION_MODE_STEALTH use 24 ( or define a new constant )

Well, I have tried to SetActionMode number 24 to my character - it didn't work for me. Not even if character was a dwarf and darkvision was natural for him. Tried with both Darkvision and Lowlightvision - did it work for you? Function implies it is not verified, and I sadly cannot veryfy it myself :( .

#6
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

JockX wrote...


RemoveSEFFromObject(oCreature, "fx_dark_vision.sef");

didn't work.


Hi JockX,

You almost have it. It is:

RemoveSEFFromObject(oControlled, "fx_low_light_vision");

However, you may still have a problem removing the SEF as the "feat" is constantly turning it back on again while it is still present. That said, I suspect careful timing of removing the effect and the feat may yield the result you are after.

I did a quick test, and this line *does* prevent the SEF from working but only after the first time it is toggled on again from being off. Like this ...

1) Low light vision is turned off.
2) This line of code is fired.
3) Toggle of the feat does not bring the vision back unless it is clicked twice.

This would suggest that a way that might work is as follows:

1) Remove the feat.
2) Apply the line of code.

In theory, this line may then work because the feat is no longer present/active and so the low light vision is not being constantly checked. However, you may also be stuck in the same position you were in that removing the feat does not mean stopping the vision action. Yet, you may then be able to use the SetActionState as previously reported just prior to removing the feat and then removing the SEF.

I hope that all makes sense.

Let me know if you have any success, or not.

Lance.

#7
JockX

JockX
  • Members
  • 15 messages

Lance Botelle wrote...
Let me know if you have any success, or not.

Well, at the end I decided to take entirely different approach, and I am satisfied with its results.  It works like this. My character has two separate feats, one of them represents drinking magical potion (SPELLABILITY_DARKVISION), and the other - taking concious control over body reflexes - this one works just like toggle button for SEF, only when potion feat has beed used (SPELL_DV_TOGGLE) .

Script for feat #1 gives certain bonuses to PC and fires "Toggle feat" script, which looks like this:

effect eVisFX = EffectNWN2SpecialEffectFile("fx_dark_vision_customised_for_my_feat.sef", oPC);                
        eVisFX = SetEffectSpellId(eVisFX, SPELL_DV_TOGGLE);
        eVisFX = SupernaturalEffect(eVisFX);

if(GetHasSpellEffect(SPELLABILITY_DARKVISION) == TRUE) [color="#00ff00"]//Can toggle DV on?[/color]
    {
        if(GetHasSpellEffect(SPELL_DV_TOGGLE) == TRUE) [color="#00ff00"]//Has toggled DV on?[/color]
        {
            RemoveSEFFromObject(oPC, "fx_dark_vision_customised_for_my_feat.sef");
            return;
        }
        
        ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVisFX, oPC, fDuration);[color="#00ff00"] [/color][color="#00ff00"]//If can, and not yet on, apply FX[/color]
        
        while(GetHasSpellEffect(SPELLABILITY_DARKVISION) == TRUE) [color="#00ff00"]//Postpone until potion wears off[/color]
        {
            ActionWait(HoursToSeconds(1)/20);  
        }
        
        RemoveSEFFromObject(oPC, "fx_dark_vision_customised_for_my_feat.sef");
        return;
    }
    
    FloatingTextStrRefOnCreature(235028, oPC); [color="#00ff00"]//StrRef informs PC that to use this feat, potion must be in effect[/color]
}

A player might abuse this script and allow "fx_dark_vision_customised_for_my_feat.sef" to be on for maximum of 3 minutes of game time (HoursToSeconds(1)/20) over the time potion should work if he uses toggle feat at the right moment, but at the end I've made myself my own switch :)

Modifié par JockX, 12 janvier 2011 - 11:11 .


#8
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages
Thanks for the feedback. :)



Lance.