Raised This Month: $ Target: $400
 0% 

Comparing values of variable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
raa
Senior Member
Join Date: Oct 2005
Old 02-03-2007 , 17:34   Comparing values of variable
Reply With Quote #1

Ok so you lets say you have a variable named Player_totalkills[id].
There are four people in the server, each with a value present in their Player_totalkills[index].

How would you compare those four index's to see who's has the biggest number, then call a function to award whoever has the biggest.
__________________
raa is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 02-03-2007 , 18:10   Re: Comparing values of variable
Reply With Quote #2

Code:
new a, b, tempid, pId[32], pNum; get_players(pId, pNum) for ( new c ; c < pNum ; c++ ) {     tempid = pId[c]     if ( Player_totalkills[tempid] > b ) {         a = tempid         b = Player_totalkills[tempid]     } }
most kills: Player_totalkills[a]

Notice this only works if there are one with the highest kills. If two players has the same and highest score, the second one would be ignored.

EDIT: Another, better way.
Code:
new a, tempid, pId[32], pNum; get_players(pId, pNum) for ( new b ; b < pNum ; b++ ) {     tempid = pId[b]     if ( Player_totalkills[tempid] > Player_totalkills[a] )         a = tempid }

Last edited by [ --<-@ ] Black Rose; 02-06-2007 at 07:10.
[ --<-@ ] Black Rose is offline
raa
Senior Member
Join Date: Oct 2005
Old 02-03-2007 , 19:52   Re: Comparing values of variable
Reply With Quote #3

koo.. ty, i'll give that a go. plus karma
__________________
raa 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 00:41.


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