Aller au contenu

Photo

Timer?


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

#1
el.sombrero

el.sombrero
  • Members
  • 100 messages
Does anyone knows how could I create a timer, invisible to the player, but that registered the time he spends playing?  Minutes and seconds are what I need, my module is small.
I would need the timer to start at the beginning of the module and stop at the end of it, so I can now for sure how long the player played the game. Also, I would like to have some triggers along the way that would tell me how long the player took to reach that point.
I was told that I could use this functions to achive this, but I'm not quite sure how to use it... I'm still king of new to the toolset
GetTimeHour() 
GetTimeMinute() 

#2
Morbane

Morbane
  • Members
  • 1 883 messages
Not tested but a decent example nonetheless...

void main()
{
object oPC = GetEnteringObject(); //for first trigger

if(!GetIsPC(oPC) return;

SetLocalInt(oPC, "time_hour", GetTimeHour());
SetLocalInt(oPC, "time_mins", GetTimeMinute());
}

void main()
{
object oPC = GetEnteringObject(); //for check triggers

if(!GetIsPC(oPC) return;

int nCurrentHour = GetTimeHour();
int nCurrentMins = GetTimeMinute();

int nElapsedHour = nCurrentHour - GetLocalInt(oPC, "time_hour");
int nElapsedMins = nCurrentMins - GetLocalInt(oPC, "time_mins");

SendMessageToPC(GetFirstPC(), nElapsedHour + " Hours and " + nElapsedMins + " Minutes have passed.");
}

#3
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Note that those are game-world hours. In module properties, you can set the number of minutes per hour. There's always 24 hours in a game-day, though.

#4
el.sombrero

el.sombrero
  • Members
  • 100 messages
Uhm... the time elapsed shouldnt ever be visible to the player. I would like the time measures taken to be stored on a variable, So then I could retrieve it after the player has finnished playing.
At this script, the time would be stored at the variables "CurrentHour" and "CurentMins" is that it?

By the way, to retrieve the data after the player finishes the game I was considering to create an object that would "talk" to me those variables. Anyone has a better idea?

Thx dudes :0)

#5
Morbane

Morbane
  • Members
  • 1 883 messages
 Add this to the end of the above - and remove the SendMessage...

SetGlobalInt("total_hours", nElapsedHours);
SetGlobalInt("total_mins", nElapsedMins);

In the retrieval script (which is up to you to develop at this stage) use: GetGlobalInt(...) to retrieve the final total.
As I said this is all just for examples sake - give it a whack and see what you can do B)

Modifié par Morbane, 10 mai 2012 - 09:20 .


#6
Morbane

Morbane
  • Members
  • 1 883 messages

Lugaid of the Red Stripes wrote...

Note that those are game-world hours. In module properties, you can set the number of minutes per hour. There's always 24 hours in a game-day, though.

Remember this as well ^

#7
kamal_

kamal_
  • Members
  • 5 258 messages
This, except count up and don't make it visible.
http://nwvault.ign.c...I.Detail&id=141

It's used in the Easter Egg Hunt module.
http://neverwinter.n...ds.com/mods/124

#8
el.sombrero

el.sombrero
  • Members
  • 100 messages
I will check these out, thx!

#9
el.sombrero

el.sombrero
  • Members
  • 100 messages
Hey there,
I'm playing with these functions and just occured me... to recover the data, could I make a character "speak" the amount stored at the variable? How should be the conversation script for this function?

#10
el.sombrero

el.sombrero
  • Members
  • 100 messages
Ow...
When I try to compile Morbane's second function (the one for the check triggers) I'm getting this error
"Script1.nss (13): ERROR: ARITHMETHIC OPERATION HAS INVALID OPERANDS".

I tried to erase the "+" signals from 13 line of the function... but what I got was
"Script1.nss (13): ERROR: UNDEFINED IDENTIFIERS"

#11
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Second issue first: The SendMessageToPC function needs a string, or strings concatenated together with a '+'. But nElapsedHour is an integer, so you need to use IntToString(nElapsedHour) instead, and likewise for the second variable.

For your conversation, what you need is a custom token. Token are the variables you can throw into conversations, the <sir/madam> things. Custom tokens are set using a script run anytime prior to the actual conversation, so you can add a script to the conversation action tab of the particular line and it will work.

Basically, you just need to use the function SetCustomToken(1234, "string"), where '1234' is the four-digit "tag" of the token, and "string" is whatever bit of text you want to throw into the conversation (like IntToString(nElapsedHours) ). In the conversation, you just write <CUSTOM1234>, with your number in the '1234', and your bit of text will show up.

Custom tokens will also work in the journal, but only update when a new journal entry is added.

#12
Morbane

Morbane
  • Members
  • 1 883 messages
SendMessageToPC(GetFirstPC(), IntToString(nElapsedHour) + " Hours and " + IntToString(nElapsedMins) + " Minutes have passed.")

This is what LotRS was referring to - sorry 'bout that :\\

#13
el.sombrero

el.sombrero
  • Members
  • 100 messages
Hey Morbane, thanks!
It's working perfectly now! Just one last doubt (I hope so :0)... I would like that the first script (the one that initiates the timer) would run on module start, and only once per game. I noticed that on module properties tab, there is a line where I can choose a script that will run under this conditions... is there any change that has to be made to the script so he can be called from this tab?

#14
Morbane

Morbane
  • Members
  • 1 883 messages
Give it a try - it should work - I looked up OnModuleLoad and I hope that the player will be recognised by the GetEnteringObject()