Raised This Month: $51 Target: $400
 12% 

[SOLVED]How to print the time remaining with printcentertextall?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vingbbit
Junior Member
Join Date: Nov 2009
Location: Gaga
Old 03-15-2010 , 08:55   [SOLVED]How to print the time remaining with printcentertextall?
Reply With Quote #1

Hello

I Don't know How can I print the time remaining with PrintCenterTextAll(like countdown).

I was made this

PHP Code:
public OnMapStart()
{
 
CreateTimer(tremainingShowTime);
}
public 
Action:ShowTime(Handle:timer)
{
 switch(
tremaining)
 {
  case 
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29:
   
PrintCenterTextAll("Time Remaining %d secs"tremaining);
  case 
30:
   
PrintCenterTextAll("Game Start!");
 }

But I think it is very wrong and It didn't work.
Teach me what is it wrong.

Last edited by vingbbit; 03-18-2010 at 08:10. Reason: I was solve this topic's issue :D
vingbbit is offline
miniman
Senior Member
Join Date: Aug 2009
Location: Israel
Old 03-15-2010 , 09:10   Re: How to print the time remaining with printcentertextall?
Reply With Quote #2

switch(tremaining)
{
case 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1 8,19,20,21,22,23,24,25,26,27,28,29:
PrintCenterTextAll("Time Remaining %d secs", tremaining);
case 30:
PrintCenterTextAll("Game Start!");
}

Replace it with
if(0<=tremaining&&tremainin<=29)
PrintCenterTextAll("Time Remaining %d secs", tremaining);
else if(tremaining==30)
PrintCenterTextAll("Game Start!");
miniman is offline
cmptrwz
Member
Join Date: Dec 2008
Old 03-15-2010 , 10:30   Re: How to print the time remaining with printcentertextall?
Reply With Quote #3

I think you are wrong miniman.

The problem is that you need to make a timer that goes off every second and repeats until tremaining is 0 or 30. (usually you count these things DOWN, yours is going to count UP)

Your timer will thus need to change tremaining, unless you are pulling that from somewhere else.
cmptrwz is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 03-15-2010 , 10:37   Re: How to print the time remaining with printcentertextall?
Reply With Quote #4

In an Action:Blahblah() statement, you should return a value.

PHP Code:
enum Action
{
    
Plugin_Continue 0,    /**< Continue with the original action */
    
Plugin_Changed 1,        /**< Inputs or outputs have been overridden with new values */
    
Plugin_Handled 3,        /**< Handle the action at the end (don't call it) */
    
Plugin_Stop 4,        /**< Immediately stop the hook chain and handle the original */
}; 
Afronanny is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 03-15-2010 , 11:10   Re: How to print the time remaining with printcentertextall?
Reply With Quote #5

Quote:
Originally Posted by miniman View Post
switch(tremaining)
{
case 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1 8,19,20,21,22,23,24,25,26,27,28,29:
PrintCenterTextAll("Time Remaining %d secs", tremaining);
case 30:
PrintCenterTextAll("Game Start!");
}

Replace it with
if(0<=tremaining&&tremainin<=29)
PrintCenterTextAll("Time Remaining %d secs", tremaining);
else if(tremaining==30)
PrintCenterTextAll("Game Start!");
if(tremaining==30)
PrintCenterTextAll("Game Start!");
else
PrintCenterTextAll("Time Remaining %d secs", tremaining);



Quote:
Originally Posted by Afronanny View Post
In an Action:Blahblah() statement, you should return a value.

PHP Code:
enum Action
{
    
Plugin_Continue 0,    /**< Continue with the original action */
    
Plugin_Changed 1,        /**< Inputs or outputs have been  overridden with new values */
    
Plugin_Handled 3,        /**< Handle the action at the end  (don't call it) */
    
Plugin_Stop 4,        /**< Immediately stop the hook chain and  handle the original */
}; 
Return value isn't required for timers.
Sammy-ROCK! is offline
miniman
Senior Member
Join Date: Aug 2009
Location: Israel
Old 03-15-2010 , 12:25   Re: How to print the time remaining with printcentertextall?
Reply With Quote #6

Quote:
Originally Posted by cmptrwz View Post
I think you are wrong miniman.

The problem is that you need to make a timer that goes off every second and repeats until tremaining is 0 or 30. (usually you count these things DOWN, yours is going to count UP)

Your timer will thus need to change tremaining, unless you are pulling that from somewhere else.
I have just replaced the wrong case ...
miniman is offline
retsam
Veteran Member
Join Date: Aug 2008
Location: so-cal
Old 03-15-2010 , 15:31   Re: How to print the time remaining with printcentertextall?
Reply With Quote #7

Hum.. Question. Maybe im retarded but, how are you going to display the messages if the timer doesnt repeat? As far as I can tell, its going to display it once, then stop...

Code:
public OnMapStart()
{
 CreateTimer(tremaining, ShowTime);
}
public Action:ShowTime(Handle:timer)
{
Quote:
Originally Posted by Sammy-ROCK! View Post
if(tremaining==30)
PrintCenterTextAll("Game Start!");
else
PrintCenterTextAll("Time Remaining %d secs", tremaining);


Return value isn't required for timers.
For this, I guess I could be wrong but, I was told by a number of SM people, that you always want to have return plugin_continue; for repeating timers, or else it will cause memory leaks..... For non-repeat timers, you dont need it.

Last edited by retsam; 03-15-2010 at 15:35.
retsam is offline
vingbbit
Junior Member
Join Date: Nov 2009
Location: Gaga
Old 03-16-2010 , 06:03   Re: How to print the time remaining with printcentertextall?
Reply With Quote #8

Quote:
Originally Posted by retsam View Post
Hum.. Question. Maybe im retarded but, how are you going to display the messages if the timer doesnt repeat? As far as I can tell, its going to display it once, then stop...

Code:
public OnMapStart()
{
CreateTimer(tremaining, ShowTime);
}
public Action:ShowTime(Handle:timer)
{
For this, I guess I could be wrong but, I was told by a number of SM people, that you always want to have return plugin_continue; for repeating timers, or else it will cause memory leaks..... For non-repeat timers, you dont need it.
First, Sorry for my bad english.

I was edit some code

PHP Code:
public OnPluginStart()
{
 
HookEvent("round_start",RST);
}
public 
Action:RST(Handle:event, const String:name[], bool:dontBroadcast)
{
 
CreateTimer(tremainingShowTime);
}
public 
Action:ShowTime(Handle:timer)
{
 
tremaining 1;
 
 if(
tremaining==30)
 {
  
PrintCenterTextAll("Game Start!");
 } else {
  
PrintCenterTextAll("Time Remaining %d secs"tremaining);
 }
 return 
Plugin_Handled;

I could see "Game Start!" but i couldn't see the time remaining text(Time Remaining %d secs)
and I think My timer plugin is a method of 'up count'.

I want to cowntdown timer.
So I added code "tremaining - 1;" like ES
Absolutely I know ES isn't Similar to Sourcemod or C
is it wrong?

(Need I Learn C?.....Actually I don't know Scripting C...)
vingbbit is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 03-16-2010 , 13:59   Re: How to print the time remaining with printcentertextall?
Reply With Quote #9

PHP Code:
new tremaining 30;
public 
OnPluginStart()
{
 
HookEvent("round_start",RST);
}
public 
Action:RST(Handle:event, const String:name[], bool:dontBroadcast)
{
 
CreateTimer(float(tremaining), ShowTime_TIMER_REPEAT);
}
public 
Action:ShowTime(Handle:timer)
{
 
tremaining--;
 
 if(
tremaining==30)
 {
  
PrintCenterTextAll("Game Start!");
 } else if (
tremaining 0) {
  
PrintCenterTextAll("Time Remaining %d secs"tremaining);
 } else if (
tremaining == 0) {
  
PrintCenterTextAll("Finished");
  return 
Plugin_Stop;
 }
 return 
Plugin_Continue;

This is assuming you want the timer to occur every second until it reaches 0, at which point it will output "Finished" or whatever you change that to.

What you weren't doing is setting the TIMER_REPEAT flag in CreateTimer, so the timer only fires once.
Afronanny is offline
vingbbit
Junior Member
Join Date: Nov 2009
Location: Gaga
Old 03-18-2010 , 08:04   Re: How to print the time remaining with printcentertextall?
Reply With Quote #10

Quote:
Originally Posted by Afronanny View Post
PHP Code:
new tremaining 30;
public 
OnPluginStart()
{
 
HookEvent("round_start",RST);
}
public 
Action:RST(Handle:event, const String:name[], bool:dontBroadcast)
{
 
CreateTimer(float(tremaining), ShowTime_TIMER_REPEAT);
}
public 
Action:ShowTime(Handle:timer)
{
 
tremaining--;
 
 if(
tremaining==30)
 {
  
PrintCenterTextAll("Game Start!");
 } else if (
tremaining 0) {
  
PrintCenterTextAll("Time Remaining %d secs"tremaining);
 } else if (
tremaining == 0) {
  
PrintCenterTextAll("Finished");
  return 
Plugin_Stop;
 }
 return 
Plugin_Continue;

This is assuming you want the timer to occur every second until it reaches 0, at which point it will output "Finished" or whatever you change that to.

What you weren't doing is setting the TIMER_REPEAT flag in CreateTimer, so the timer only fires once.

Thank you Afronny! and Thanks all for wrote answer in my post

Afronny. I was edit with your answer.
After that I could see the time remaining message. and It works as countdown!!
BUT I don't understand yet about timer doesn't work when fire "round_start" event

CreateTimer(blah, commandblah, _, TIMER_REPEAT);

I wrote TIMER_REPEAT, but Why It work only once?

You shouldn't answer about this.
I just wondering...


by the way Thanks All!!
vingbbit is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode