AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get playername (optimize this?) (https://forums.alliedmods.net/showthread.php?t=225789)

colossus 09-09-2013 07:07

How to get playername (optimize this?)
 
How to optimize getname last ct?

funcion: GetCTLastName()

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <cstrike> #define PLUGIN "Get Name Last CT" #define VERSION "1.0" #define AUTHOR "colossus" new g_maxplayers new szName[33][32] new szText[32] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         // Add your code here...     register_srvcmd("function", "GoFunction")         g_maxplayers = get_maxplayers() } public client_putinserver(id) {     get_user_name(id, szName[id], charsmax(szName[])) } public GoFunction() {     if(fnGetCTs() == 1)     {         GetCTLastName()     } } fnGetCTs() {     static iCTs, id     iCTs = 0         for (id = 1; id <= g_maxplayers; id++)     {         if(!is_user_alive(id))             continue                     if (cs_get_user_team(id) != CS_TEAM_CT)             continue                     iCTs++     }         return iCTs; } GetCTLastName() {     for(new id = 1; id <= g_maxplayers; id++)     {         if(!is_user_alive(id))             continue                     if (cs_get_user_team(id) != CS_TEAM_CT)             continue                             formatex(szText, charsmax(szText), "%s", szName[id])     } }

RapZzw3rR 09-09-2013 07:52

Re: How to get playername (optimize this?)
 
PHP Code:

new szText[32];

public 
GoFunction( )
{
    new 
iPlayers[32], iNumszName[32];
    
    
get_players(iPlayersiNum"aceh""CT");
    
    if( 
iNum == )
    {
        
get_user_name(iPlayers[0], szNamecharsmax(szName));
        
formatex(szTextcharsmax(szText), szName[id]);
    }


Try this.

colossus 09-09-2013 09:41

Re: How to get playername (optimize this?)
 
Quote:

Originally Posted by RapZzw3rR (Post 2031296)
PHP Code:

new szText[32];

public 
GoFunction( )
{
    new 
iPlayers[32], iNumszName[32];
    
    
get_players(iPlayersiNum"aceh""CT");
    
    if( 
iNum == )
    {
        
get_user_name(iPlayers[0], szNamecharsmax(szName));
        
formatex(szTextcharsmax(szText), szName[id]);
    }


Try this.

What is "aceh" ???

SpaWn2KiLl 09-09-2013 09:48

Re: How to get playername (optimize this?)
 
Quote:

Originally Posted by colossus (Post 2031340)
What is "aceh" ???

If specified, you can constrain which players are returned by flags:
"a" - Don't return dead players
"b" - Don't return alive players
"c" - Skip bots
"d" - Skip real players
"e" - Match with passed team
"f" - Match with part of name
"g" - Ignore case sensitivity
"h" - Skip HLTV

ConnorMcLeod 09-09-2013 12:10

Re: How to get playername (optimize this?)
 
"ae" is enough, there is no reason to filter bots, and there is no way to collect an alive HLTV.

And last code contains mistakes on name

get_user_name(players[0], name, charsmax(name)) is all you need when num == 1, the next format line is completely wrong/

SpaWn2KiLl 09-09-2013 12:21

Re: How to get playername (optimize this?)
 
Quote:

Originally Posted by ConnorMcLeod (Post 2031422)
"ae" is enough, there is no reason to filter bots, and there is no way to collect an alive HLTV.

And last code contains mistakes on name

get_user_name(players[0], name, charsmax(name)) is all you need when num == 1, the next format line is completely wrong/

I don't agree with you...

If he uses bots... probably he doesn't want them name

Yes it is possible to collect an alive HLTV... Transfer it to one team and then use a plugin to revive... :D

ConnorMcLeod 09-09-2013 18:26

Re: How to get playername (optimize this?)
 
Last ct is last ct, bot or not.

colossus 09-09-2013 22:13

Re: How to get playername (optimize this?)
 
The final code:

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #define PLUGIN "Get Name Last CT" #define VERSION "1.0" #define AUTHOR "colossus" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         // Add your code here...     register_srvcmd("function", "GoFunction") } public GoFunction() {     new iPlayers[32], iNum, szName[32];         get_players(iPlayers, iNum, "ae", "CT");         if( iNum == 1 )     {         get_user_name(iPlayers[0], szName, charsmax(szName))         client_print(0, print_chat, "%s Ultimate CT", szName)     }     }

No Job plugin if players in game > 1....



And other question... How to check the same code but with boolean variable ej: g_Winner[Index]???

Example:

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #define PLUGIN "Get Name Last CT" #define VERSION "1.0" #define AUTHOR "colossus" new g_Winner[33] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         // Add your code here...     register_srvcmd("function", "GoFunction") } public client_authorized(id) { if(is_user_admin(id)) g_Winner[id] = true; } public GoFunction() {     new iPlayers[32], iNum, szName[32];         get_players(iPlayers, iNum, "ae", "CT");         if( iNum == 1 )     {         if(g_Winner[iPlayers[0]])         {             get_user_name(iPlayers[0], szName, charsmax(szName))             client_print(0, print_chat, "%s Ultimate CT and variable g_Winner == true", szName)         }     }     }

This is correct code or not??

ConnorMcLeod 09-10-2013 01:01

Re: How to get playername (optimize this?)
 
It is not correct.

Explain what you are trying to do.

colossus 09-10-2013 13:23

Re: How to get playername (optimize this?)
 
I want to get last player alive CT and g_Winner variable == true.


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

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