Raised This Month: $ Target: $400
 0% 

Getting random id


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sputnik53
Senior Member
Join Date: Jun 2005
Old 10-17-2007 , 17:51   Getting random id
Reply With Quote #1

How can I get a random id of a player in CT team?
I tried using get_players but it didn't work for me.
Sputnik53 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-17-2007 , 18:04   Re: Getting random id
Reply With Quote #2

Try this :

Code:
new players[32], ctnum, random_ct_player get_players(players, ctnum, "e", "CT") switch(ctnum) {     case 0:return     case 1:random_ct_player = players[0]     default:random_ct_player = players[random(ctnum)] }

Last edited by ConnorMcLeod; 10-18-2007 at 06:12. Reason: M249-M4A1 found an error && Arkshine says bulls##t
ConnorMcLeod is offline
Sputnik53
Senior Member
Join Date: Jun 2005
Old 10-17-2007 , 19:57   Re: Getting random id
Reply With Quote #3

Yeah, only I can be dumb enough to forgot to check if there's no CTs.
Thanks connorr.

Last edited by Sputnik53; 10-17-2007 at 20:21.
Sputnik53 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-17-2007 , 20:18   Re: Getting random id
Reply With Quote #4

Code edited, it should be better with switch.

Last edited by ConnorMcLeod; 10-17-2007 at 21:36. Reason: lol sputnik89
ConnorMcLeod is offline
Sputnik53
Senior Member
Join Date: Jun 2005
Old 10-17-2007 , 20:22   Re: Getting random id
Reply With Quote #5

Code:
random_ct_player = players[random(1, ctnum)]
Number of arguments doesn't not match definition.
Sputnik53 is offline
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 10-17-2007 , 21:07   Re: Getting random id
Reply With Quote #6

Change random to random_num
__________________
M249-M4A1 is offline
Sputnik53
Senior Member
Join Date: Jun 2005
Old 10-18-2007 , 05:46   Re: Getting random id
Reply With Quote #7

I'm only afraid that random_num(1, ctnum) has a chance of returning the id as 1, and you know there's not always someone who has it.
Sputnik53 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-18-2007 , 05:52   Re: Getting random id
Reply With Quote #8

You're retrieve a player list with get_players().

players[x] return a player id where 0 <= x <= ctnum - 1.

also players[random_num(1, ctnum)] should be players[random(ctnum)] since players[] start at 0.



It should work fine.

Code:
    get_randomCT_id()     {         static iPlayers[32], iCT_num;         get_players( iPlayers, iCT_num, "e", "CT" );                 if( !iCT_num )             return;                 return iCT_num > 1 ? iPlayers[ random( iCT_num ) ] : iPlayers[ iCT_num - 1 ];     }
__________________

Last edited by Arkshine; 10-18-2007 at 06:06.
Arkshine is offline
Sputnik53
Senior Member
Join Date: Jun 2005
Old 10-18-2007 , 06:25   Re: Getting random id
Reply With Quote #9

Code:
return iCT_num > 1 ? iPlayers[random(iCT_num)] : iPlayers[iCT_num-1]
Warning: Function get_randomCT_id should return a value on line #
Error: Function uses both "return" and "return <value>" on line #
Sputnik53 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-18-2007 , 06:31   Re: Getting random id
Reply With Quote #10

Code:
if( !iCT_num )             return -1

Then when you call the function, make sure to do nothing if it returns -1.
ConnorMcLeod 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 01:19.


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