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

In- & decrement a integer by 1 every second event


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Rirre
Veteran Member
Join Date: Nov 2006
Old 02-24-2016 , 13:40   In- & decrement a integer by 1 every second event
Reply With Quote #1

What I'm trying to do is to increment a integer by 1 every second player join a team and decrement on disconnects. Not sure how to do it though.
Code:
int iJoin; void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) {     iJoin = 0; } void Client_CS_TeamInfo (void *p, int) {     static int iPlayerIndex;     switch (state)     {     case 0:         iPlayerIndex = *(int *)p - 1;         break;     case 1:         if ((strcmp((char *) p, "TERRORIST") == 0) && (iPlayerIndex > -1) && (iPlayerIndex < gpGlobals->maxClients))         {             (*g_engfuncs.pfnServerPrint)("Terrorist\n");         }         else if ((strcmp((char *) p, "CT") == 0) && (iPlayerIndex > -1) && (iPlayerIndex < gpGlobals->maxClients))         {             (*g_engfuncs.pfnServerPrint)("Counter Terrorist\n");         }         break;     } } void ClientDisconnect (edict_t *pEntity) {     iJoin--; // decrease it here }

Last edited by Rirre; 02-24-2016 at 13:41.
Rirre is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 02-25-2016 , 02:25   Re: In- & decrement a integer by 1 every second event
Reply With Quote #2

Quote:
Originally Posted by http://stackoverflow.com/a/10807706/4934640

Use sleep() : http://www.gnu.org/software/libc/man.../Sleeping.html

Code:
int count = 0; while(true) {     count++;     cout << count << endl; // print every 10 second     sleep(10); }
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline
Rirre
Veteran Member
Join Date: Nov 2006
Old 02-25-2016 , 03:41   Re: In- & decrement a integer by 1 every second event
Reply With Quote #3

I'm pretty sure sleep cause the server to freeze (sleep) from last time I remember I used it.
And I need it to increment on every 2nd player join event and vice versa (decrement on disconnect). Not in a timer.

Last edited by Rirre; 02-25-2016 at 03:53.
Rirre is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 02-25-2016 , 05:19   Re: In- & decrement a integer by 1 every second event
Reply With Quote #4

To create a think entity or look for the set_task implementation.

https://forums.alliedmods.net/showpo...83&postcount=5
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline
Old 02-28-2016, 20:32
Bugsy
This message has been deleted by Bugsy. Reason: nvm
Old 03-02-2016, 08:39
Rirre
This message has been deleted by Rirre.
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 03-02-2016 , 19:33   Re: In- & decrement a integer by 1 every second event
Reply With Quote #5

NEVER use sleep in a game loop!

You can just hook disconnect and some team join event to increment and decrement your variables.
Other way is, on each frame, count how many players on each team.

But remember. NEVER NEVER NEVER use sleep() in a game loop.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Rirre
Veteran Member
Join Date: Nov 2006
Old 03-02-2016 , 19:46   Re: In- & decrement a integer by 1 every second event
Reply With Quote #6

Quote:
Originally Posted by addons_zz View Post
To create a think entity or look for the set_task implementation.

https://forums.alliedmods.net/showpo...83&postcount=5
Do you really not get the idea of what I am saying? NOT in a timer.
Quote:
Originally Posted by joropito
NEVER use sleep in a game loop!

You can just hook disconnect and some team join event to increment and decrement your variables.
Other way is, on each frame, count how many players on each team.

But remember. NEVER NEVER NEVER use sleep() in a game loop.
That's the answer I wanted. I've never had a good experience with sleep() since the game server just froze until the sleep time was over and I've never seen it done by anyone else.
I already figured it out though by checking the player count. Thanks for your reply.
Rirre is offline
Old 03-02-2016, 22:37
addons_zz
This message has been deleted by addons_zz. Reason: too late
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 10:44.


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