Lever animation script
Zephirius
Member Posts: 419
Trying to have the lever play its animation every time its pulled. Not just once! I'm all over the map on this one. I have the code, but it's a mess.
Thanks for any help...
code so far:
Told you it was a messs.
I don't understand what values to assign to this script, so that the lever aniamtion always plays. As it stands now the animation runs only once....?
Thanks for any help...
code so far:
void main() { object oPC = GetLastUsedBy(); if (!GetIsPC(oPC)) return; object oSound = GetObjectByTag("EYEBALL"); SoundObjectSetPosition(oSound, GetPosition(oPC)); SoundObjectSetVolume(oSound, 127); SoundObjectPlay(oSound); AssignCommand(GetObjectByTag("TALK_01"), ActionSpeakString("Muhahaha...")); // Set a local integer. SetLocalInt(oPC, "LeverPulled", 0); if ( GetLocalInt(oPC, "LeverPulled")) { AssignCommand(OBJECT_SELF, ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE)); ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect ( VFX_IMP_GLOBE_USE ), GetObjectByTag("TALK_01")); return; } if ( GetLocalInt(oPC, "LeverPulled") == 0 ) { SetLocalInt(oPC, "LeverPulled", 1); AssignCommand(OBJECT_SELF, ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE)); ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect ( VFX_IMP_GLOBE_USE ), GetObjectByTag("TALK_01")); } }
Told you it was a messs.
I don't understand what values to assign to this script, so that the lever aniamtion always plays. As it stands now the animation runs only once....?
Post edited by Zephirius on
0
Comments
Right now you have "activate" in both cases.
Also, setting "LeverPulled" to 0 unconditionally means only the second case ever runs.
The logic you need is - if "LeverPulled" is not set, set "LeverPulled" & activate, else clear "LeverPulled" & deactivate.
This is assuming you want the level to move one way at first and the other way on the next attempt.
Edit:
It's working now, if a bit clunky, but then again - I'm no coder.
Code so far -
Evertyhing works as it should, except for the sound files. When the sound plays, it plays two sound files simultaneously. That's no beuno...
new code -
If you see any glaring errors, please holler. In fact, shout it at the roof tops if it'll help.
Something like this (which I have not tested...) maybe?:
Also, is it odd that you are having the PC play the sound? I left it that way.
Thanks again.
I've taken to never starting a floor lever in its default starting position but always setting it explicitly to either "activated" or "deactivated" before positioning it the way I want it.