Aller au contenu

Photo

Random selection in script question.


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

#1
PJ156

PJ156
  • Members
  • 2 988 messages
I wrote the script below to play a random animation on heartbeat for an npc.

It sort of works but the randomness does not. It only plays case 2 "tired" can anyone see what I have done wrong.

Cheers,

PJ

void main()
{
object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
if (IsInConversation(OBJECT_SELF) || GetIsInCombat()) return;
int iRand = Random (3);
  {switch (iRand)
   {
   case 0:
   PlayCustomAnimation (OBJECT_SELF, "getlow",1,6.0);
   break;
   case 1:
   PlayCustomAnimation (OBJECT_SELF, "standidle",1,6.0);
   break;
   case 2:
   PlayCustomAnimation (OBJECT_SELF, "tired",1,6.0);
   break;
   }
  }  


#2
kevL

kevL
  • Members
  • 4 078 messages
I think you have to knock him out of the loop

PlayCustomAnimation(OBJECT_SELF, "%", 0);


before moving onto the next one,

ref: How Do You Stop A Looping Animation?

#3
MasterChanger

MasterChanger
  • Members
  • 686 messages
That curly brace before your "switch" statement is making me uncomfortable. I don't like it, I don't like it one bit! Get rid of it, throw it in the garbage, and let us never speak of it again! And its matching one at the end, too!

But seriously, you're not bracketing anything there. Keep the one after the switch and the matching one below. I don't know if this would make any difference, but it's good practice to get rid of anything unnecessary when you're debugging.

#4
kevL

kevL
  • Members
  • 4 078 messages
yeah i can't see anything that would specificly break the code, but the curly braces before and at the end of the switch() block are unnecessary. So is the object oPC def'n -- lose it unless it's needed ;|


MC, ya got me playing around:

I was getting a reasonably bored guard, so bored he kept sticking himself in the neck on the "bored" animation ... with these timings


( note: fSpeed doesn't seem to work in this implementation )


link to Pastebin

btw PJ, i think you misunderstood the meaning of the last two parameters of PlayCustomAnimation() - not sure tho; also the animation labels were incorrect, it seems.

#5
PJ156

PJ156
  • Members
  • 2 988 messages
Thanks KevL that does the trick. I can see where I was going wrong too.

I did have an animation label incorrect, I looked up the animation 2da and got the right ones after I posted.

I need to look at playCustomAnimation again :)

PJ