AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Comparing values of variable (https://forums.alliedmods.net/showthread.php?t=50785)

raa 02-03-2007 17:34

Comparing values of variable
 
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.

[ --<-@ ] Black Rose 02-03-2007 18:10

Re: Comparing values of variable
 
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 }

raa 02-03-2007 19:52

Re: Comparing values of variable
 
koo.. ty, i'll give that a go. plus karma


All times are GMT -4. The time now is 00:41.

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