Sort all arrays with one func
I'm trying to get the most knife kills/HS kills, etc just with one function
Thats what I have PHP Code:
|
Re: Sort all arrays with one func
?
Code:
|
Re: Sort all arrays with one func
No, I mean ALL ARRAYS with just one SortCustom. And I meant not the ShortCustom1D, its not possible, I mean another custom function for it. As I said.
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
Re: Sort all arrays with one func
No I don't understand.
You are looping a sorting function which is illogical. checkChance() means nothing to me. You can't supply a sorting function with an array that is related to one player. The whole point is that it is sorting all players. I think what you want to do is to send JUST "arKills", which is basically "2". and then use that as an offset in your internal code. What you are doing now: PlayerData[id][arKills] will return an integer basically that points to another integer which is NOT an array. You then tell the code it's an array, and since it's the last entry in the enumeration you will get an index out of bounds as soon as "elem1" or "elem2" in combination with the previously set player offset "i" + arArray >= the size of your enumeration array. What you want is the code that I wrote but I assume with more calculations inside. There's nothing that SortCustom1D can't sort, that's the point of SortCustom. You send a list of whatever you want sorted. You decide in the public function what criteria you want to be met and it does exactly that. It will return to you the array you sent it, sorted with the criteria you decided. If you want to combine the three you first have to decide which of the three is most important. For example "shoots" which I assume is "shots" may be 10000 but kills and items bought are probably more important. So either you select an order: if ( items of player 1 > items of player 2 || kills of player 1 > kills of player 2 || shots of player 1 > shots of player 2 ) return -1 Or you create some kind of calculation to balance them out to a kind of score (in this case 1 item is worth 2 kills, 1000 shots is worth 1 kill): if ( items of player 1 * 2 + kills of player 1 + shots of player 1 / 1000 > items of player 2 * 2 + kills of player 2 + shots of player 2 / 1000 ) return -1 Then you apply it: Code:
I might have misunderstood though. Maybe this is what you want: Code:
Creating a custom sorting function is not as easy as looping players once. Google "Bubble Sort" to find some basic code if you want to create your own function. I would stick with SortCustom1D. |
Re: Sort all arrays with one func
These codes just was for examples.
Obviously checkChance doesn't means nothing for you, I didn't say what it means, its my stock. Look what I got with that code: PHP Code:
When I start the map and type /kills, it returns 1, when one or more bots connect, it shows 2, when someone has killed, it shows sometimes 7 or 3. And after I died, it returns 2 again. Look: PHP Code:
PHP Code:
PHP Code:
|
Re: Sort all arrays with one func
Ops, a mistake is up.
Your format isn't showing the top, sometimes I got: EFFx killed 1 enemies. But i've killed 2-3. |
Re: Sort all arrays with one func
So add a few debug messages to show where the problem is.
For example, if the message is displaying less than expected kills: Log when it is supposed to register the kill count, preferably at more than one point until the variable is set. Including variable values if necessary. At the point of the printing of the message, log all the variable values related to the message to find anything unexpected. This is the best way to debug your code. It is also how you learn to understand the code. The code is kind of big for me to debug since I don't know anything about it. I also can't compile it because I'm missing "cl_buy". If you want me to debug, please tell me where to get the required files and how to reproduce the error and I will test with bots. |
Re: Sort all arrays with one func
Sorry about the cl_buy, I tought you knew where to download it - https://forums.alliedmods.net/showthread.php?t=149380
About the debug, that's what I was doing, Bugsy already told me to always do it when something return a invalid value: PHP Code:
|
Re: Sort all arrays with one func
Your sample code works fine for me, so does the big plugin as far as I can see. Is it just one event that has problems or multiple?
|
Re: Sort all arrays with one func
Yea, the code works fine inicially for me aswell. But example, when you has 7 kills, your name appears on the hud. But if a bot kill 3-4, it shows his name, the hud do not continue with mine. I don't know whats wrong, if the reason is because i'm using 1.8.3, I do not have any idea. And without your GetTop(), it doesn't happen, every value appear correctly. But when I tried to use your GetTop(), it get bugs. As I said, it appear: EFFx Killed 1 enemies while I have killed 2-3. Appear [P0D]Tommy_Lee_Jones (97) has finished off 0 woundest enemies or [P0D]Tommy_Lee_Jones (97) received attacks 0 before dying.
|
| All times are GMT -4. The time now is 20:58. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.