Raised This Month: $ Target: $400
 0% 

[ Solved ] One from Ct goes to T


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 09-10-2008 , 13:05   [ Solved ] One from Ct goes to T
Reply With Quote #1

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
__________________

Last edited by xPaw; 09-10-2008 at 14:18.
xPaw is offline
Prajch
Senior Member
Join Date: Dec 2007
Location: anger++
Old 09-10-2008 , 13:51   Re: One from Ct goes to T
Reply With Quote #2

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)] 

Last edited by Prajch; 09-10-2008 at 14:03.
Prajch is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 09-10-2008 , 14:08   Re: One from Ct goes to T
Reply With Quote #3

@Prajch: thanks

EDIT: works fine now! +k
__________________

Last edited by xPaw; 09-10-2008 at 14:16.
xPaw is offline
Reply


Thread Tools
Display Modes

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 03:10.


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