AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ Solved ] One from Ct goes to T (https://forums.alliedmods.net/showthread.php?t=77329)

xPaw 09-10-2008 13:05

[ Solved ] One from Ct goes to T
 
hi, i'm trying to make this: all t's come to ct, and one of them goes to T

but, sometimes who come to server, cant move, and teleporting to spec places, fix it please

my code
-REMOVED CODE-
P.S. sry for my bad english

Prajch 09-10-2008 13:51

Re: One from Ct goes to T
 
PHP Code:

for(new i=0i<get_maxplayers(); i++) { 
        if(
get_user_team(i) == && get_user_team(i) == 2
            
cs_set_user_team(iCS_TEAM_CT
 
        
g_Players++; 
    } 

You shouldn't put i<get_maxplayers() as the condition; the function gets called for every loop. Instead you should store get_maxplayer() in a variable before and use that.

Also, it seems like you're checking if the user is on T and CT at the same time. I think this would be better:

PHP Code:

if(get_user_team(i) == 1

Another problem... since you don't check to see if the player index is connected before doing g_Players++, your random number can have a player index that doesn't exist. If you have half your server full, roughly 50% of the time it won't work. You should do something like:

PHP Code:

    new maxplayers get_maxplayers()
 
    for(new 
i=1i<=maxplayersi++) { 
        if(
is_user_connected(i)
            
g_Players++
        if(
get_user_team(i) == 1)
            
cs_set_user_team(iCS_TEAM_CT
    } 

Notice it's starting at 1 because index 0 is the server.

[edit] Oh and you'll want to check i<=maxplayers, since if you have 32 slots, index 32 is a valid player index. Goes from 1 to maxplayers. Updated code to match.

Also I just realized the situation is somewhat more complicated, in that you could have empty spots in your player indexes. You'll have to create an array to store the valid player indexes connected to your server.

PHP Code:

    new maxplayers get_maxplayers()
    new 
indexArray[32]
 
    for(new 
i=1i<=maxplayersi++) { 
        if(
is_user_connected(i)
        {
            
indexArray[g_Players] = i
            g_Players
++
        }
 
        if(
get_user_team(i) == 1)
            
cs_set_user_team(iCS_TEAM_CT
    } 
 
    new 
g_ID indexArray[random_num(0g_Players 1)] 


xPaw 09-10-2008 14:08

Re: One from Ct goes to T
 
@Prajch: thanks

EDIT: works fine now! +k :)


All times are GMT -4. The time now is 03:10.

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