Raised This Month: $ Target: $400
 0% 

remove single player or single ID


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
liryck
Senior Member
Join Date: Mar 2007
Location: Venezuela
Old 03-09-2010 , 22:20   remove single player or single ID
Reply With Quote #1

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
liryck is offline
Send a message via MSN to liryck
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-09-2010 , 22:24   Re: remove single player or single ID
Reply With Quote #2

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;
     }

__________________

Last edited by Bugsy; 03-09-2010 at 22:28.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-09-2010 , 22:35   Re: remove single player or single ID
Reply With Quote #3

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; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
liryck
Senior Member
Join Date: Mar 2007
Location: Venezuela
Old 03-09-2010 , 22:46   Re: remove single player or single ID
Reply With Quote #4

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 =(
liryck is offline
Send a message via MSN to liryck
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-09-2010 , 22:54   Re: remove single player or single ID
Reply With Quote #5

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.
__________________

Last edited by Bugsy; 03-09-2010 at 22:59.
Bugsy is offline
liryck
Senior Member
Join Date: Mar 2007
Location: Venezuela
Old 03-09-2010 , 22:58   Re: remove single player or single ID
Reply With Quote #6

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
liryck is offline
Send a message via MSN to liryck
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-09-2010 , 23:02   Re: remove single player or single ID
Reply With Quote #7

Quote:
Originally Posted by liryck View Post
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
__________________

Last edited by Bugsy; 03-09-2010 at 23:40.
Bugsy is offline
Old 03-09-2010, 23:07
Exolent[jNr]
This message has been deleted by Exolent[jNr]. Reason: Delete.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-10-2010 , 00:11   Re: remove single player or single ID
Reply With Quote #8

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;

__________________

Last edited by Bugsy; 03-10-2010 at 01:01.
Bugsy is offline
liryck
Senior Member
Join Date: Mar 2007
Location: Venezuela
Old 03-10-2010 , 13:12   Re: remove single player or single ID
Reply With Quote #9

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
        }
        

liryck is offline
Send a message via MSN to liryck
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-10-2010 , 13:36   Re: remove single player or single ID
Reply With Quote #10

show the full plugin
__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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