AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [SNIPPET/CODE] How to properly check Team score. (https://forums.alliedmods.net/showthread.php?t=288220)

Craxor 09-24-2016 23:55

[SNIPPET/CODE] How to properly check Team score.
 
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 ); }

HamletEagle 09-25-2016 05:23

Re: [SNIPPET/CODE] How to properly check Team score.
 
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++

Depresie 09-25-2016 11:36

Re: [SNIPPET/CODE] How to properly check Team score.
 
Ohh my god.. isnt there a native for such already?

HamletEagle 09-25-2016 13:13

Re: [SNIPPET/CODE] How to properly check Team score.
 
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.

Craxor 09-25-2016 13:33

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

Originally Posted by HamletEagle (Post 2456844)
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.

klippy 09-25-2016 13:40

Re: [SNIPPET/CODE] How to properly check Team score.
 
It does work, but has no effect. You don't need those 2 lines.

Craxor 09-25-2016 13:48

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

Originally Posted by KliPPy (Post 2456982)
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.

HamletEagle 09-25-2016 13:53

Re: [SNIPPET/CODE] How to properly check Team score.
 
You are trying to empty something that's already empty. Not a big deal, anyway.

meTaLiCroSS 09-26-2016 19:42

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

Originally Posted by Craxor (Post 2456985)
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?

Craxor 09-27-2016 01:51

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

Originally Posted by meTaLiCroSS (Post 2457339)
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.


All times are GMT -4. The time now is 18:26.

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