AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   remove single player or single ID (https://forums.alliedmods.net/showthread.php?t=120955)

liryck 03-09-2010 22:20

remove single player or single ID
 
k i have this. getting the players from the server, what i want to know is how i do for remove a single player or id.

i put the players in a menu so when you choose a player remove that player from menu. so if other person open the menu can't select it

PHP Code:

get_players(iPlayersiNum); 

i try this but not working
PHP Code:

iPlayers[ptempid] = iPlayers[--iNum


Bugsy 03-09-2010 22:24

Re: remove single player or single ID
 
Just be careful when setting these indices to 0 if other functions are iterating through and calling functions on these players. If you try to call a function on a 0 player id you will get an error. Before taking action a player in this array, do a if ( iPlayers[ X ] ) check.

If you know the id location in the iPlayers array:
PHP Code:

iPlayersindex ] = 0

or

Suppose id is the id of player you want to remove from iPlayers:
PHP Code:

for ( new iNum i++ )
{
     if ( 
iPlayers] == id )
     {
          
iPlayers] = 0;
          break;
     }



Exolent[jNr] 03-09-2010 22:35

Re: remove single player or single ID
 
If you want to remove an index from an array and reduce the size as well, you can do one of two ways:
Code:
new iPlayers[ 32 ], iNum; get_players( iPlayers, iNum ); // iIndex is the index you want removed // 1 // this way only replaces the current index with the last one iPlayers[ iIndex ] = iPlayers[ --iNum ]; // 2 // this way shifts all indexes for( new i = iIndex; i < iNum; i++ ) {     iPlayers[ i ] = ( ( i + 1 ) < iNum ) ? iPlayers[ i + 1 ] : 0; }

liryck 03-09-2010 22:46

Re: remove single player or single ID
 
ok will try the code where i want to applied this is.

where iPlayers and iNum are global variables,

PHP Code:

cs_set_user_team(ptempidCS_TEAM_CT)
        
get_user_name(ptempid,name,31)
        
client_print(0,print_chat,"%s Has Sido Elegido Por el Capitan de los CT's",name)
        
selectedct[count++] = iPlayers[ptempid]
        
iPlayers[ptempid] = iPlayers[--iNum]// here i should remove the player that was selected it is correct?
        
ct_team++
        if(
count == ct_team && ct_team <= 4)
            {
                
menu_destroy(menu);
                
AwesomeMenu(t_cap)
                return 
PLUGIN_HANDLED;
            } 

if im correct at my comment line. there must be something wrong caus when i reedisplay the menu the player is still in the menu and another was deleted from it =(

Bugsy 03-09-2010 22:54

Re: remove single player or single ID
 
get_players retrieves connected players and stores their player id's in the passed array. Now this doesn't mean you will always end up with ids in order. The array, for example, can look like this:

iPlayers[] = { 2 , 3 , 5 , 7 , 10 , 15 }

Accessed with index 0 through 5. [ 0=2 , 1=3 , 2=5 , 3=7 , 4=10 , 5=15 ]

So with your method, if you try to remove player with id 4, you are really accessing iPlayers[ 4 ] which is actually player id 10.

liryck 03-09-2010 22:58

Re: remove single player or single ID
 
uhmm ya, will try it ty the think is that im still doesn't understand this part of code

i know that in other threat i ask the same and some one link another threat with an explain but still with that don't understand it xD. so if is not to much could you?
PHP Code:

iPlayers] : 0


Bugsy 03-09-2010 23:02

Re: remove single player or single ID
 
Quote:

Originally Posted by liryck (Post 1113329)
uhmm ya, will try it ty the think is that im still doesn't understand this part of code

i know that in other threat i ask the same and some one link another threat with an explain but still with that don't understand it xD. so if is not to much could you?
PHP Code:

iPlayers] : 0


condition ? value if true : value if false

PHP Code:

iValue = ( == ) ? 10//(1 == 1) is true, iValue would be 5
iValue = ( == ) ? 10//(1 == 2) is false, iValue would be 10 

Hope this helps
PHP Code:

iPlayers] = ( ( ) < iNum ) ? iPlayers] : 0;

// is the same as

if ( ( ) < iNum )
     
iPlayers] = iPlayer];
else
     
iPlayers] = 0


Bugsy 03-10-2010 00:11

Re: remove single player or single ID
 
Replace
PHP Code:

selectedct[count++] = iPlayers[ptempid]
iPlayers[ptempid] = iPlayers[--iNum

with

PHP Code:

new iIndex GetPlayerIndexptempid );

//Just to be safe. If ptempid is not found in iPlayers[], you will
//get an 'index out of bounds' error with these 2 lines.
if ( iIndex > -
{
     
selectedctcount++ ] = iPlayersiIndex ];
     
iPlayersiIndex ] = iPlayers[ --iNum ];


PHP Code:

//Returns -1 if a player with the passed id is not found in iPlayers[]
GetPlayerIndexid )
{
    for ( new 
iNum i++ )
        if ( 
iPlayers] == id )
            return 
i;

    return -
1;



liryck 03-10-2010 13:12

Re: remove single player or single ID
 
i dont know what more to do! hell T_T

[IMG]http://img53.**************/img53/1530/sinttulouf.th.png[/IMG]

as u can see in the image haba was selected by CT cap T cap and again by CT Cap, the player still in the choose menu T_T im stuck
PHP Code:


 
if(cap_id == ct_cap is_user_connected(ptempid){

        
cs_set_user_team(ptempidCS_TEAM_CT)
        
get_user_name(ptempid,name,31)
        
client_print(0,print_chat,"%s Has Sido Elegido Por el Capitan de los CT's",name)
       new 
iIndex GetPlayerIndexptempid );
        if ( 
iIndex > -
        {
            
selectedctcount++ ] = iPlayersiIndex ];
            
iPlayersiIndex ] = iPlayers[ --iNum ];
        }  
      
                
menu_destroy(menu);
                
AwesomeMenu(t_cap)
                return 
PLUGIN_HANDLED;
  
    }
 if(
cap_id == t_cap is_user_connected(ptempid)
{
      .
      .
      .
       
//menu option for t_cap same as ct_cap just that player slected is going to T
}
GetPlayerIndexid )
{
    new 
name[32]
        for( new 
0iNumi++ )
        {
                if ( 
iPlayers] == id ){
                    return 
i;
                    
get_user_name(id,name,31)
                    
client_print(0,print_chat,"%s fue borrado de la lista",name)
                }
                return -
1
        }
        



Bugsy 03-10-2010 13:36

Re: remove single player or single ID
 
show the full plugin


All times are GMT -4. The time now is 08:37.

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