Raised This Month: $51 Target: $400
 12% 

[HOW TO] Retrieve random values from an array without retreiving the same twice


Post New Thread Reply   
 
Thread Tools Display Modes
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-15-2010 , 14:47   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #41

It sure does. Just if you did following( which has nothing to do with your thing ), the selected[ count ] wouldn't get incremented.
PHP Code:
players[rand] = selected[count]++; 
SnoW is offline
Send a message via MSN to SnoW
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-15-2010 , 15:24   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #42

Quote:
Originally Posted by SnoW View Post
It sure does. Just if you did following( which has nothing to do with your thing ), the selected[ count ] wouldn't get incremented.
PHP Code:
players[rand] = selected[count]++; 
Yes it would, I'm sure you meant to put:
Code:
selected[ count++ ];
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-16-2010 , 09:49   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #43

Actually no I didn't. It just happened that the real bug was in printing native. For example if you did following the cell wouldn't get incremented:
PHP Code:
server_print"%i"iArrayiVar ]++ ); 
SnoW is offline
Send a message via MSN to SnoW
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-16-2010 , 10:29   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #44

Quote:
Originally Posted by SnoW View Post
Actually no I didn't. It just happened that the real bug was in printing native. For example if you did following the cell wouldn't get incremented:
PHP Code:
server_print"%i"iArrayiVar ]++ ); 
Interesting, I wasn't aware of that.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-16-2010 , 11:56   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #45

Quote:
Originally Posted by Emp` View Post
Interesting, I wasn't aware of that.
It does the same thing with dynamic natives.

Code:
new count; public plugin_natives( ) {     register_native( "increase", "_increase" ); } public _increase( ) {     return count++; }

That won't work properly.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
flamin
BANNED
Join Date: Jul 2009
Location: Los Teques
Old 03-21-2010 , 00:26   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #46

hi! i want to make a code to make a random map as could do?
flamin is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-04-2010 , 16:48   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #47

Here are some useful functions that I wrote up.
It allows you to just copy these functions and implement anything you needed from the first post.

EDIT:

Removed and added to first post.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 11-27-2010 at 15:44.
Exolent[jNr] is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-04-2011 , 20:22   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #48

Quote:
Originally Posted by SnoW View Post
Actually no I didn't. It just happened that the real bug was in printing native. For example if you did following the cell wouldn't get incremented:
PHP Code:
server_print"%i"iArrayiVar ]++ ); 
that's not a bug, it's the feature of this operation.
b = a++;
means:
b = a;
a = a + 1;

server_print("%d", b= a++);
=>
b = a;
a = a + 1;
server_print("%d", b);
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-04-2011 , 20:56   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #49

Quote:
Originally Posted by jim_yang View Post
that's not a bug, it's the feature of this operation.
b = a++;
means:
b = a;
a = a + 1;

server_print("%d", b= a++);
=>
b = a;
a = a + 1;
server_print("%d", b);
I think he meant that a = a from that native call, rather than a = a + 1.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-04-2011 , 21:07   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #50

that's the same thing, it's called expression evaluation.
first make "a" as the value of that expression, then a+1 assign to a, server_print(expression value);

also same in return value;
int foo(int a)
{
return a++;
//step 1: calculate the value of expression, result is a
//step 2: a + 1 assign to a;
//step 3: return the value of expression ( a );
}
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>

Last edited by jim_yang; 08-04-2011 at 21:10.
jim_yang 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:11.


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