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

[L4D1] How to create timers for each player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ZBzibing
Senior Member
Join Date: Dec 2012
Old 11-13-2023 , 05:01   [L4D1] How to create timers for each player
Reply With Quote #1

Code:
CreateTimer(60.0, weapon_fire1, 60, TIMER_FLAG_NO_MAPCHANGE);

public Action weapon_fire1(Handle timer, int time)
{
	if(time >= 0)
	{
		CreateTimer( 1.0, weapon_fire1, --time);
		PrintCenterText(client,"%i sec",time );
	}
	return Plugin_Stop;
}
PrintCenterText(client,"%i sec",time );
I need to have each player show his timer, but I don't know how he wrote it.
__________________
Please forgive, If I'm not describing it accurately. I use google translate
Functional tests are all from L4D1, and are only keen to solve and fix various bugs of L4D1:

Last edited by ZBzibing; 11-13-2023 at 05:02.
ZBzibing is offline
ProjectSky
AlliedModders Donor
Join Date: Aug 2020
Old 11-13-2023 , 05:40   Re: [L4D1] How to create timers for each player
Reply With Quote #2

PHP Code:
Handle g_hTimer[MAXPLAYERS+1];

// client index
g_hTimer[client] = CreateTimer(60.0Weapon_fire160TIMER_FLAG_NO_MAPCHANGE); 
ProjectSky is offline
ZBzibing
Senior Member
Join Date: Dec 2012
Old 11-15-2023 , 23:17   Re: [L4D1] How to create timers for each player
Reply With Quote #3

Quote:
Originally Posted by ProjectSky View Post
PHP Code:
Handle g_hTimer[MAXPLAYERS+1];

// client index
g_hTimer[client] = CreateTimer(60.0Weapon_fire160TIMER_FLAG_NO_MAPCHANGE); 
Thanks, but it can't reach every player.
I'd like each player to be able to print their own timer, showing the countdown time.
__________________
Please forgive, If I'm not describing it accurately. I use google translate
Functional tests are all from L4D1, and are only keen to solve and fix various bugs of L4D1:
ZBzibing is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 11-16-2023 , 12:19   Re: [L4D1] How to create timers for each player
Reply With Quote #4

https://wiki.alliedmods.net/Timers_(...#Simple_Values
__________________

Last edited by Marttt; 11-16-2023 at 12:24.
Marttt is offline
101
Member
Join Date: Nov 2023
Old 12-04-2023 , 01:20   Re: [L4D1] How to create timers for each player
Reply With Quote #5

Example 1
PHP Code:
#include <sourcemod>

#define WHATEVER 120 

new player_value[MAXPLAYERS+1];

public 
OnClientPostAdminCheck(client)    //this usually called in sourcemod when client join the game OR client passed new map 
{
    
CreateTimer(1.0 player_Timer client TIMER_REPEAT);    //repeated timer runs every 1 second (Repeted-Timers won't be stopped until you kill the handle)
}

public 
Action:player_Timer(Handle:Timer,any:client)
{
    if (
IsClientConnected(client)    &&    player_value[client] <= WHATEVER )
    {
        
PrintCenterText(client "%d sec" , ++player_value[client] );    // 1 sec ... 2 sec ... 3sec ...
    
}
    else 
    {
        
// in case Client Disconnected OR the timer finished its mission  : 
        
        
player_value[client]=0;        // reset the value 
        
return Plugin_Stop;            //kill the repeated-timer
    
}

Some people prefer to Carry The Repeated Timer in a Specified Handle (SO THEY CAN LATERLY CHECK IF IS STILL RUNNING OR NOT) , here is an example 2 :
PHP Code:
#include <sourcemod>

#define WHATEVER 120 

new player_value[MAXPLAYERS+1];
Handle player_hTimer[MAXPLAYERS+1];        // This Is The New Touch , Note : this will be automatically filled by values: INVALID_HANDLE;

public OnClientPostAdminCheck(client)
{
    
player_hTimer[client]= CreateTimer(1.0 player_Timer client TIMER_REPEAT);        //we attached the timer to a specific handle
}

public 
Action:player_Timer(Handle:Timer,any:client)
{
    if (
IsClientConnected(P)    &&    player_value[client] <= WHATEVER )
    {
        
PrintCenterText(client "%d sec" , ++player_value[client] );    // 1 sec ... 2 sec ... 3sec ...
    
}
    else 
    {
        
// in case Client Disconnected OR the timer finished its mission  : 
        
        
player_value[client]=0;                    // reset the value 
        
player_hTimer[client]=INVALID_HANDLE;    //its important to reset our handle To bring benefit from Check_Player_Timer() 
        
return Plugin_Stop;                        //kill the repeated-timer
    
}
}

Check_Player_Timer(client)
{
    if (
player_hTimer[client]!=INVALID_HANDLE)
    {
        
//in this case we got sure that timer of client is still running 
        //to kill it imediatelly We have to do this : 
        
CloseHandle(player_hTimer[client]);        //CloseHandle(Avaliabe_handle) Or KillTimer(Avaliabe_handle) so the repeated-timer above will return Plugin_Stop and stop working
        
player_hTimer[client]=INVALID_HANDLE;    //reset our handle to null so We can get benefit again from Check_Player_Timer() function; 
        
player_value[client]=0;    
    }

101 is offline
101
Member
Join Date: Nov 2023
Old 12-04-2023 , 01:31   Re: [L4D1] How to create timers for each player
Reply With Quote #6

Quote:
Originally Posted by Marttt View Post
All explanations don't satisfy beginners .
there must be a main source site that explain every f thing with details and "at least" 5 examples .
Most Plugins here are so complicated and not coded well in both sections (sourcemod and amxmodx)
Most Usually Write a book of scriptng included unnecessary bullshit things , i think there is a lack of knowladge here, but WHO CARES ?

Last edited by 101; 12-04-2023 at 01:41.
101 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-04-2023 , 03:45   Re: [L4D1] How to create timers for each player
Reply With Quote #7

Pretty sure that the example requested is in the link...

Anyway, you can always download plugins from known good authors like Silvers, which mainly does L4D1/L4D2 plugins and has a clean, easy to ready, working code and also has the timer/client stuff explained in his scripting TUTORIAL thread.
__________________

Last edited by Marttt; 12-04-2023 at 03:48.
Marttt 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 09:53.


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