dhudmessage.inc
Original include source with line numbers.
| 1 | #if defined _dhudmessage_included |
| 2 | #endinput |
| 3 | #endif |
| 4 | |
| 5 | #define _dhudmessage_included |
| 6 | |
| 7 | #include <amxmodx> |
| 8 | |
| 9 | stock __dhud_color; |
| 10 | stock __dhud_x; |
| 11 | stock __dhud_y; |
| 12 | stock __dhud_effect; |
| 13 | stock __dhud_fxtime; |
| 14 | stock __dhud_holdtime; |
| 15 | stock __dhud_fadeintime; |
| 16 | stock __dhud_fadeouttime; |
| 17 | stock __dhud_reliable; |
| 18 | |
| 19 | stock set_dhudmessage( red = 0, green = 160, blue = 0, Float:x = -1.0, Float:y = 0.65, effects = 2, Float:fxtime = 6.0, Float:holdtime = 3.0, Float:fadeintime = 0.1, Float:fadeouttime = 1.5, bool:reliable = false ) |
| 20 | { |
| 21 | #define clamp_byte(%1) ( clamp( %1, 0, 255 ) ) |
| 22 | #define pack_color(%1,%2,%3) ( %3 + ( %2 << 8 ) + ( %1 << 16 ) ) |
| 23 | |
| 24 | __dhud_color = pack_color( clamp_byte( red ), clamp_byte( green ), clamp_byte( blue ) ); |
| 25 | __dhud_x = _:x; |
| 26 | __dhud_y = _:y; |
| 27 | __dhud_effect = effects; |
| 28 | __dhud_fxtime = _:fxtime; |
| 29 | __dhud_holdtime = _:holdtime; |
| 30 | __dhud_fadeintime = _:fadeintime; |
| 31 | __dhud_fadeouttime = _:fadeouttime; |
| 32 | __dhud_reliable = _:reliable; |
| 33 | |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | stock show_dhudmessage( index, const message[], any:... ) |
| 38 | { |
| 39 | new buffer[ 128 ]; |
| 40 | new numArguments = numargs(); |
| 41 | |
| 42 | if( numArguments == 2 ) |
| 43 | { |
| 44 | send_dhudMessage( index, message ); |
| 45 | } |
| 46 | else if( index || numArguments == 3 ) |
| 47 | { |
| 48 | vformat( buffer, charsmax( buffer ), message, 3 ); |
| 49 | send_dhudMessage( index, buffer ); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | new playersList[ 32 ], numPlayers; |
| 54 | get_players( playersList, numPlayers, "ch" ); |
| 55 | |
| 56 | if( !numPlayers ) |
| 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | new Array:handleArrayML = ArrayCreate(); |
| 62 | |
| 63 | for( new i = 2, j; i < numArguments; i++ ) |
| 64 | { |
| 65 | if( getarg( i ) == LANG_PLAYER ) |
| 66 | { |
| 67 | while( ( buffer[ j ] = getarg( i + 1, j++ ) ) ) {} |
| 68 | j = 0; |
| 69 | |
| 70 | if( GetLangTransKey( buffer ) != TransKey_Bad ) |
| 71 | { |
| 72 | ArrayPushCell( handleArrayML, i++ ); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | new size = ArraySize( handleArrayML ); |
| 78 | |
| 79 | if( !size ) |
| 80 | { |
| 81 | vformat( buffer, charsmax( buffer ), message, 3 ); |
| 82 | send_dhudMessage( index, buffer ); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | for( new i = 0, j; i < numPlayers; i++ ) |
| 87 | { |
| 88 | index = playersList[ i ]; |
| 89 | |
| 90 | for( j = 0; j < size; j++ ) |
| 91 | { |
| 92 | setarg( ArrayGetCell( handleArrayML, j ), 0, index ); |
| 93 | } |
| 94 | |
| 95 | vformat( buffer, charsmax( buffer ), message, 3 ); |
| 96 | send_dhudMessage( index, buffer ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | ArrayDestroy( handleArrayML ); |
| 101 | } |
| 102 | |
| 103 | return 1; |
| 104 | } |
| 105 | |
| 106 | stock send_dhudMessage( const index, const message[] ) |
| 107 | { |
| 108 | message_begin( __dhud_reliable ? ( index ? MSG_ONE : MSG_ALL ) : ( index ? MSG_ONE_UNRELIABLE : MSG_BROADCAST ), SVC_DIRECTOR, _, index ); |
| 109 | { |
| 110 | write_byte( strlen( message ) + 31 ); |
| 111 | write_byte( DRC_CMD_MESSAGE ); |
| 112 | write_byte( __dhud_effect ); |
| 113 | write_long( __dhud_color ); |
| 114 | write_long( __dhud_x ); |
| 115 | write_long( __dhud_y ); |
| 116 | write_long( __dhud_fadeintime ); |
| 117 | write_long( __dhud_fadeouttime ); |
| 118 | write_long( __dhud_holdtime ); |
| 119 | write_long( __dhud_fxtime ); |
| 120 | write_string( message ); |
| 121 | } |
| 122 | message_end(); |
| 123 | } |
| 124 | |