Raised This Month: $ Target: $400
 0% 

[Help] "FOR" Cycle.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 12-25-2008 , 12:53   Re: [Help] "FOR" Cycle.
Reply With Quote #4

FOR - repetitive function with known number of steps.
General form:
PHP Code:
for( inittestincrement ); 
1. 'init' is evaluated
2. 'test' is evaluated
3. 'increment' is evaluated
4. If 'test' is true, the function goes to nr 2, 'test'.

For instance, there are equal:

While:
PHP Code:
new 10;

while( 
<= 10 )
{
    
i;
    
// s += i;
    
    
i++;

For:
PHP Code:
new 0;

for( new 
1<= 10i++)
    
+= i
Both examples are storing int variabile 's' the sum from 1 to 10.

Or a countdown:
PHP Code:
// 1. While
new 10;

while(
0)
{
    
server_print("x = %i"x);
    
x--;
}

//2. For
for( 100x-- )
    
server_print("x = "x); 
In your example above:
PHP Code:
new players32 ], numi;
get_playersplayersnum );

for( 
0numi++ )
    
cs_set_user_moneyplayers], 16000); 
The loop/cycle stars from 0 to num- 1...because is an array, wich starts from 0 (first slot) to last_slot - 1. If you use >= last_slot, you'll get 'index out bounds'.
So, it takes every player and sets his cash to 16000.

I hope you understood a bit.

Know, your request.
PHP Code:
#include <amxmodx>
#include <fakemeta>

#define OFFSET_TEAM         114

enum
{
    
FM_TEAM_UNASSIGNED,
    
FM_TEAM_T,
    
FM_TEAM_CT,
    
FM_TEAM_SPECTATOR,
    
    
FM_TEAM_MAX
};

new 
bool:g_Special33 ];
new 
index32 ], playersidi;
new 
g_maxplayersg_msgteaminfo;

public 
plugin_init()
{
    
register_logevent"roundstart"2"1=Round_Start" );
    
    
g_msgteaminfo get_user_msgid"TeamInfo" );
    
g_maxplayers get_maxplayers();
}

public 
roundstart()
{
    
    
/* the loop stars from 1, not an array
    for(i = 1; i <= g_maxplayers; i++)
    {
        if( is_user_connected( i ) )
        {
            index[ players ] = i;
            players++;
        }
        
        if( get_user_team( i ) != 1 )
            continue;
        
        fm_set_user_team( i, FM_TEAM_CT );
        g_Special[ i ] = false;
    }*/
    
    
new gplayers32 ], playernumj;
    
get_playersgplayersnum"h" ); // h -  skip HLTV
    
    
for( 0numj++ )
    {
        
player gplayers];
        
        if( 
is_user_connectedplayer ) )
        {
            
indexplayers ] = player;
            
players++;
        }
        
        if( 
get_user_teamplayer ) != )
            continue;
        
        
fm_set_user_teamplayerFM_TEAM_CT );
        
g_Specialplayer ] = false;
    }
    
    
set_task5.0"choose" );
}

public 
choose()
{
    
id indexrandom_num0players ) ];
    
    if( 
get_user_teamid ) == )
    {
        
fm_set_user_teamidFM_TEAM_T );
        
g_Specialid ] = true;
        
        
client_printidprint_chat"You're the special guy!" );
    }
}

fm_set_user_teamindexteam 
{
    
set_pdata_intindex OFFSET_TEAMteam );

    static const 
TeamInfoFM_TEAM_MAX ][ ] =
    {
        
"UNASSIGNED",
        
"TERRORIST",
        
"CT",
        
"SPECTATOR"
    
};

    
message_beginMSG_ALLg_msgteaminfo );
    
write_byteindex );
    
write_stringTeamInfoteam ] );
    
message_end();

__________________

anakin_cstrike is offline
 



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 09:06.


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