Raised This Month: $32 Target: $400
 8% 

[SNIPPET/CODE] How to properly check Team score.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-24-2016 , 23:55   [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #1

Using the next code example i'm going to show you a good way to get team scores, based on my tests, this is working even if is planting bomb/ hostage save, etc ...

First, create 2 new global variables, inside of them will store the actual score of teams:
PHP Code:
new TeroScore;
new 
CtScore

Register these events in the plugin_init:
PHP Code:
public plugin_init( )
{

    
// Events when Terrorists and Counter-terrorists win ( hostage saved, bomb exploded, all are already included in these ... )            
    
register_event("TeamScore""Event_TeroWin""a""1=TERRORIST")
    
register_event("TeamScore""Event_CTWin""a""1=CT")

    
// This event is called when Round is restarted, we need to reset TeroScore and CtScore variables when the game are restarted.
    
register_event("TextMsg""fwEvGameWillRestart""a""2=#Game_will_restart_in")

    
// We register a 'test' command to see if is completly work and show the good score:
    
register_clcmd"say /test""test" );

In Game restart public:
PHP Code:
public fwEvGameWillRestart( )
{
          
// We reset the variables at server restart:
          
TeroScore 0;
          
CtScore 0;

We get the real score inside of the events:
PHP Code:
public Event_CTWin( ) CtScore read_data);
public 
Event_TeroWin( ) TeroScore read_data); 
An example inside of 'test' public:
PHP Code:
public testid )
{
    
client_printidprint_chat"Tero score: %i, Ct score: %i"TeroScoreCtScore );

The whole code without comments:
Code:
#include <amxmodx>             new TeroScore; new CtScore; public plugin_init( ) {             register_event("TeamScore", "Event_TeroWin", "a", "1=TERRORIST")     register_event("TeamScore", "Event_CTWin", "a", "1=CT")     register_event("TextMsg", "fwEvGameWillRestart", "a", "2=#Game_will_restart_in")         register_clcmd( "say /test", "test" ); } public fwEvGameWillRestart( ) {     TeroScore = 0;     CtScore = 0; }     public Event_CTWin( ) CtScore = read_data( 2 ); public Event_TeroWin( ) TeroScore = read_data( 2 ); public test( id ) {     client_print( id, print_chat, "Tero score: %i, Ct score: %i", TeroScore, CtScore ); }
__________________
Project: Among Us

Last edited by Craxor; 07-23-2017 at 17:48.
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-25-2016 , 05:23   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #2

PHP Code:
 // We also empty the variables in plugin_init because plugin_init is called at 'map change' / 'server start'  .
    
TeroScore 0;
    
CtScore 0
FYI, pawn is not C++
__________________

Last edited by HamletEagle; 09-25-2016 at 05:23.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-25-2016 , 11:36   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #3

Ohh my god.. isnt there a native for such already?
__________________
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-25-2016 , 13:13   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #4

In 1.8.3, since it has gamedata natives check m_iNumTerroristWins and m_iNumCTWins, no new native needed. Or you can use orpheu/okapi and check this members.
__________________

Last edited by HamletEagle; 09-25-2016 at 13:14.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-25-2016 , 13:33   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
PHP Code:
 // We also empty the variables in plugin_init because plugin_init is called at 'map change' / 'server start'  .
    
TeroScore 0;
    
CtScore 0
FYI, pawn is not C++
Test it, it's working to empty the variables.
__________________
Project: Among Us

Last edited by Craxor; 09-25-2016 at 13:38.
Craxor is offline
Send a message via ICQ to Craxor
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-25-2016 , 13:40   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #6

It does work, but has no effect. You don't need those 2 lines.
klippy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-25-2016 , 13:48   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #7

Quote:
Originally Posted by KliPPy View Post
It does work, but has no effect. You don't need those 2 lines.
they become empty automatcly at map start so i don't realy need them.

topic edited.
__________________
Project: Among Us

Last edited by Craxor; 09-27-2016 at 01:53.
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-25-2016 , 13:53   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #8

You are trying to empty something that's already empty. Not a big deal, anyway.
__________________
HamletEagle is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 09-26-2016 , 19:42   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #9

Quote:
Originally Posted by Craxor View Post
if you also say 'why' base on the logic i write on the comments, we would avoid looot of coments, but anyway:

Explain my way, there i'm trying to 'empty' the variables when map change,server start ...

But i think you're right because anyway they become empty automatcly at map start so i don't realy need them.
Sir, plugins are reloaded every map change. That's a valid reason.

Also, Fakemeta didn't add get_gamerules_* natives for retrieving members values from the gamerules class? Or it has another purpose?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-27-2016 , 01:51   Re: [SNIPPET/CODE] How to properly check Team score.
Reply With Quote #10

Quote:
Originally Posted by meTaLiCroSS View Post
Sir, plugins are reloaded every map change. That's a valid reason.

Also, Fakemeta didn't add get_gamerules_* natives for retrieving members values from the gamerules class? Or it has another purpose?
About that, i already i know, is just a small mistake i miss it, i just wanne tell everybody to directly say the reasons without 'skipping' and getting in LONG-useless-conversation.

About get_gamerules ... That's in 1.8.3, i show a way for 1.8.2 or less.
__________________
Project: Among Us

Last edited by Craxor; 09-27-2016 at 01:53.
Craxor is offline
Send a message via ICQ to Craxor
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 19:03.


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