How do you randomise a timer?
#1
Posté 24 juin 2012 - 01:02
#2
Posté 24 juin 2012 - 01:46
if (!GetLocalInt (OBJECT_SELF, "AMBIENT_SHOUT") )
{
SetLocalInt (OBJECT_SELF, "AMBIENT_SHOUT", TRUE);
DelayCommand (30.0+ IntToFloat (d20() ), DeleteLocalInt (OBJECT_SELF, "AMBIENT_SHOUT") );
// Do talking here;
}
#3
Posté 24 juin 2012 - 04:21
Is that a good idea, though? I tend to avoid Heartbeat scripts so as not to lag up the game; this was a spawn script. Thanks, though!Failed.Bard wrote...
If you're calling that behaviour from its heartbeat script, set a variable each time the NPC says something, and have the variable unset (or deleted) on a delay. Something like:
if (!GetLocalInt (OBJECT_SELF, "AMBIENT_SHOUT") )
{
SetLocalInt (OBJECT_SELF, "AMBIENT_SHOUT", TRUE);
DelayCommand (30.0+ IntToFloat (d20() ), DeleteLocalInt (OBJECT_SELF, "AMBIENT_SHOUT") );
// Do talking here;
}
#4
Posté 24 juin 2012 - 04:45
That's how I work in my module to check for tiredness every minute or reputation, alccolization etc...
#5
Posté 25 juin 2012 - 05:46
But how would I randomise the time taken?Krevett wrote...
If you don't want to use heartbeat tou can create a custom function for the npc to speak its random line and at the end of the function call it again with a DelayCommand(put random timer her, your function);
That's how I work in my module to check for tiredness every minute or reputation, alccolization etc...
#6
Posté 25 juin 2012 - 06:24
{
float fRand = IntToFloat(Random(10) + 11); // gives random timer between 11.0 and 20.0 seconds for example
....do your speaking here....
Delaycommand(fRand, DoSpeak());
}
not tested but that should work...you just need to adjust the random timer as it fits you
#7
Posté 26 juin 2012 - 05:53
I would like to point out that the Random() core function of NWScript is not as random as you would expect. The Lexicon explains it quite well.
Given the same unmodified Area, the same number of Players in the module, and the same number of calls to Random() made *before* a call such as:
float fRand = IntToFloat(Random(10) + 11);
and the above code will return always the same random amount.
You can not directly change the seed, but you can -at least- do something to force the random sequence being played to look like something different everytime.
It is sufficient to use a numeric value you really have no control over, such as the current time milliseconds. Then use it in some creative way to force an unpredictable number of calls to Random(). For example:
int nMsec = GetTimeMillisecond () & 0x3F;
while (nMsec--) { Random (1); }
The ideal moment to execute the above snippet is when a PC enters the Area. Everytime a PC enters, the random sequence for that Area shall be offsetted to something that nobody can promptly recognize. And the illusion of true randomness is achieved.
-fox
Modifié par the.gray.fox, 26 juin 2012 - 06:00 .
#8
Posté 26 juin 2012 - 08:56
the.gray.fox wrote... Per. Lexicon.
Given the same unmodified Area, the same number of Players in the module, and the same number of calls to Random() made *before* a call such as:float fRand = IntToFloat(Random(10) + 11);
and the above code will return always the same random amount.
The Lexicon is not often wrong. But it is in this case. The above statment is false.
I tested it in single player, New module, One area, Only A single placeable with a single script to report the random number OnOpen, All module events removed.
Every time I started a new game, fully shutting down NWN between tries, The chest reported a new string of random numbers.
It would appear that NWN reseeds with at least every restart.
Or did I miss something in my testing?
L8
#9
Posté 26 juin 2012 - 09:37
#10
Posté 26 juin 2012 - 10:15
It appears I had bad knowledge on this. And yet I am sure I had seen it with my own eyes. Probably dreamed.
Anyway, you are correct.
And I see that the random sequence also changes if you switch between 2 areas, no need to fully shut the game.
I wonder... is this an accident or a signal? Am I to conclude that I am getting -hhhh!- senile? gray not without reason, but... this soon? It is worrying that I fail on tiny details such as this. Should it be more pills or more fish? A good neurologist, perhaps.
They say you can measure your intellectual "age" (maybe "freshness" is a better word) judging by the games you can complete. On the solid and worldwide accepted assumption that an 8 years old kid is virtually able to complete any game with an arm tied on his back and ask for second, I shall embark on a journey to complete the first Quake game on Nightmare difficulty. The globally agreed on parameters (for Quake 1) are that an 8yo kid can conquer it all in just 3 days, dispersing 1 quarter of gallon of sweat per game level on his worst day. I will use these values for comparison, and eventually determine what my true brain age is.
Wish me good luck.
-fox
#11
Posté 27 juin 2012 - 08:52
#12
Posté 29 juin 2012 - 08:03





Retour en haut






