AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Event_DeathMsg if server (https://forums.alliedmods.net/showthread.php?t=228815)

Debesėlis 10-27-2013 13:30

Event_DeathMsg if server
 
PHP Code:

iKiller read_data);
g_iKillsiKiller ] ++; 

How to return if iKiller is SERVER?

ConnorMcLeod 10-27-2013 13:37

Re: Event_DeathMsg if server
 
Add in register_event filter "1>0" so you won't collect when killer is 0
In callback, check killer against maxplayers value
PHP Code:

new g_iMaxPlayers;

public 
plugin_init()
{
    
register_event("DeathMsg""Event_DeathMsg""a""1>0");
    
g_iMaxPlayers get_players();
}
    
public 
Event_DeathMsg()
{
    new 
killer read_data(1);
    if( 
killer g_iMaxPlayers )
    {
        return;
    }

    
g_iKillskiller ] ++;



Debesėlis 10-27-2013 13:41

Re: Event_DeathMsg if server
 
What if i use this?

PHP Code:

#define IsPlayer(%1)    ( 1 <= %1 <= g_iMaxPlayers )

    
if ( IsPlayeriKiller ) )
    {
        if ( 
g_iKillsiKiller ] == 99 )
        {
             
// do something
        
}
    } 

What is doing this one? :)
PHP Code:

#define IsPlayer(%1)    ( 1 <= %1 <= g_iMaxPlayers ) 


lein 10-27-2013 13:57

Re: Event_DeathMsg if server
 
#define IsPlayer(%1) ( 1 <= %1 <= g_iMaxPlayers )
we call it 预编译。 \(^o^)/

PreProcessor
You can buy a book about C,then you'll konw these:
#include
#define
#if、#else、#endif
......
Lexical preprocessors are the lowest-level of preprocessors, in so far as they only require lexical analysis, that is, they operate on the source text, prior to any parsing, by performing simple substitution of tokenized character sequences for other tokenized character sequences, according to user-defined rules. They typically perform macro substitution, textual inclusion of other files, and conditional compilation or inclusion.
C preprocessor[edit]
Main article: C preprocessor
The most common example of this is the C preprocessor, which takes lines beginning with '#' as directives. Because it knows nothing about the underlying language, its use has been criticized and many of its features built directly into other languages. For example, macros replaced with aggressive inlining and templates, includes with compile-time imports (this requires the preservation of type information in the object code, making this feature impossible to retrofit into a language); conditional compilation is effectively accomplished with if-then-else and dead code elimination in some languages.

DWIGHTpN 10-27-2013 14:55

Re: Event_DeathMsg if server
 
Code:

#define IsPlayer(%1)    ( 1 <= %1 <= g_iMaxPlayers )
In hlds , players get a number (id). This id can be 1,2, ..., max players (32 is max on HLDS).

So, this function check if iKiller (id) is player and not something else (fall, world , etc).
Than to write
Code:

if( 1 <= iKiller <= g_iMaxPlayers )
, with this function can write
Code:

if( IsPlayer( iKiller ) )
.

You understand :)?

ConnorMcLeod 10-27-2013 15:40

Re: Event_DeathMsg if server
 
Quote:

Originally Posted by Debesėlis (Post 2053520)
What if i use this?

PHP Code:

#define IsPlayer(%1)    ( 1 <= %1 <= g_iMaxPlayers )

    
if ( IsPlayeriKiller ) )
    {
        if ( 
g_iKillsiKiller ] == 99 )
        {
             
// do something
        
}
    } 

What is doing this one? :)
PHP Code:

#define IsPlayer(%1)    ( 1 <= %1 <= g_iMaxPlayers ) 


It is same as checking : if( 1 <= iKiller <= g_iMaxPlayers )

But, since we added filter 1>0 in register_event, we already know iKiller is >= 1, so we only need to check if iKiller <= g_iMaxPlayers

Debesėlis 10-27-2013 16:59

Re: Event_DeathMsg if server
 
Ok i understand. Thanks guys.


All times are GMT -4. The time now is 23:20.

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