AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help add. (https://forums.alliedmods.net/showthread.php?t=237898)

Maladca 03-31-2014 12:23

Help add.
 
Help add.
Need to add a message when the player receives the admin chat must issue such a message:

You got admin.

PHP Code:

#include <amxmodx>
#include <csstats>

#define IGNORE_FLAG ADMIN_LEVEL_A    /* flag "m" */

new pRankspFlags

public plugin_init() {
    
register_plugin"Test""0.11c""Test" )
    
register_dictionary"test.txt" )
    
pRanks register_cvar"top_ranks""10" )
    
pFlags register_cvar"top_flags""t" )
    
register_event("HLTV""eventNewRound""a""1=0""2=0");
}

public 
client_putinserver(id) {
    
set_task0.3"CheckStats"id )    // we need to use delay otherwise we will get rank = 0
}

public 
CheckStats(id) {
    new 
iFlags get_user_flags(id)
    new 
szAddFlags[16]
    
get_pcvar_stringpFlagsszAddFlags15 )
    new 
iAddFlags  read_flags(szAddFlags)

    if ( 
iFlags IGNORE_FLAG || iFlags iAddFlags == iAddFlags )
    
// ignore player with IGNORE_FLAG or having all additional flags
    
return

    new 
iRanks get_pcvar_num(pRanks)
    if ( !
iRanks )
    return

    new 
szStats[8], szBodyHits[8]
    new 
iRank get_user_statsidszStatsszBodyHits )

    if ( 
iRank && iRank <= iRanks ) {
        
// 1st check for safety. may be player not ranked at all yet
        
set_user_flagsidiFlags iAddFlags )
        new 
data[2]
        
data[0] = id
        data
[1] = iRanks
        set_task
5.0"PrintMessage"_data)
    }
}

public 
PrintMessagedata[2] ) {
    if ( !
is_user_connected(data[0]) )
    return

    
ColorPrintdata[0], "%L"data[0], "TEST"data[1] )
}

public 
eventNewRound()
    
set_task(2.0"delayedMessage");

public 
delayedMessage() {
    new 
players[32], playersnum;
    
get_players(playersplayersnum"ch");
    new 
szStats[8], szBodyHits[8];
    
    for ( new 
playersnum i++ ) {
        
get_user_statsplayers[i], szStatsszBodyHits )
        if ( 
szStats[0] < 1000 )
        
ColorPrint(players[i], "Your frags %d - %d, after 1000 frags you get admin"szStats[0], szStats[1]);
    }
}

ColorPrintiReceiver, const szRawMessage[ ], any:... ) {
    static 
iMsgSayText 0
    
if( !iMsgSayText )
    
iMsgSayText get_user_msgid"SayText" )

    new 
szMessage[192]
    
vformatszMessagecharsmax(szMessage) - 1szRawMessage)
    
replace_allszMessagecharsmax(szMessage) - 1"!n""^1" )
    
replace_allszMessagecharsmax(szMessage) - 1"!t""^3" )
    
replace_allszMessagecharsmax(szMessage) - 1"!g""^4" )
    if ( 
szMessage[0] != '^1' || szMessage[0] != '^3' || szMessage[0] != '^4' )
    
formatszMessagecharsmax(szMessage) - 1"^1%s"szMessage )    // we must set initial default color if it is not provided explicitly

    
message_beginMSG_ONE_UNRELIABLEiMsgSayText_iReceiver )
    
write_byte(iReceiver)    // use target player as sender to see colors at all (and his own team color for ^3)
    
write_string(szMessage)
    
message_end()



Baws 03-31-2014 21:51

Re: Help add.
 
Not tested.

Code:
#include <amxmodx> #include <csstats> #define IGNORE_FLAG ADMIN_LEVEL_A    /* flag "m" */ new pRanks, pFlags public plugin_init() {     register_plugin( "Test", "0.11c", "Test" )     register_dictionary( "test.txt" )     pRanks = register_cvar( "top_ranks", "10" )     pFlags = register_cvar( "top_flags", "t" )     register_event("HLTV", "eventNewRound", "a", "1=0", "2=0"); } public client_putinserver(id) {     set_task( 0.3, "CheckStats", id )    // we need to use delay otherwise we will get rank = 0 } public CheckStats(id) {     new iFlags = get_user_flags(id)     new szAddFlags[16]     get_pcvar_string( pFlags, szAddFlags, 15 )     new iAddFlags  = read_flags(szAddFlags)     if ( iFlags & IGNORE_FLAG || iFlags & iAddFlags == iAddFlags )     // ignore player with IGNORE_FLAG or having all additional flags     return     new iRanks = get_pcvar_num(pRanks)     if ( !iRanks )     return     new szStats[8], szBodyHits[8]     new iRank = get_user_stats( id, szStats, szBodyHits )     if ( iRank && iRank <= iRanks ) {         // 1st check for safety. may be player not ranked at all yet         set_user_flags( id, iFlags | iAddFlags )         new data[2]         data[0] = id         data[1] = iRanks         set_task( 5.0, "PrintMessage", _, data, 2 )     } } public PrintMessage( data[2] ) {     if ( !is_user_connected(data[0]) )     return     ColorPrint( data[0], "%L", data[0], "TEST", data[1] ) } public eventNewRound()     set_task(2.0, "delayedMessage"); public delayedMessage() {     new players[32], playersnum;     get_players(players, playersnum, "ch");     new szStats[8], szBodyHits[8];         for ( new i ; i < playersnum ; i++ ) {         get_user_stats( players[i], szStats, szBodyHits )         if ( szStats[0] < 1000 )         ColorPrint(players[i], "Your frags %d - %d, after 1000 frags you get admin", szStats[0], szStats[1]);         else if ( szStats[0] >= 1000 )         ColorPrint(players[i], "Congratulations! Your frags %d - %d, you got now admin!", szStats[0], szStats[1]);     } } ColorPrint( iReceiver, const szRawMessage[ ], any:... ) {     static iMsgSayText = 0     if( !iMsgSayText )     iMsgSayText = get_user_msgid( "SayText" )     new szMessage[192]     vformat( szMessage, charsmax(szMessage) - 1, szRawMessage, 3 )     replace_all( szMessage, charsmax(szMessage) - 1, "!n", "^1" )     replace_all( szMessage, charsmax(szMessage) - 1, "!t", "^3" )     replace_all( szMessage, charsmax(szMessage) - 1, "!g", "^4" )     if ( szMessage[0] != '^1' || szMessage[0] != '^3' || szMessage[0] != '^4' )     format( szMessage, charsmax(szMessage) - 1, "^1%s", szMessage )    // we must set initial default color if it is not provided explicitly     message_begin( MSG_ONE_UNRELIABLE, iMsgSayText, _, iReceiver )     write_byte(iReceiver)    // use target player as sender to see colors at all (and his own team color for ^3)     write_string(szMessage)     message_end() }


All times are GMT -4. The time now is 05:54.

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