Raised This Month: $ Target: $400
 0% 

Solved [ H3LP ] Position by votes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 07-11-2017 , 11:17   [ H3LP ] Position by votes
Reply With Quote #1

Hello. Could someone show me a hud example of how can i order strings by number of votes? I need that for a plugin that I'm working on and I tried my best, but I failed doing it and can't find any tuts on how to do it. Any help would be appreciated. Thanks !

Last edited by DarthMan; 07-13-2017 at 11:16. Reason: Solved
DarthMan is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-11-2017 , 11:26   Re: [ H3LP ] Position by votes
Reply With Quote #2

How do you handle votes and strings?
__________________
HamletEagle is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 07-11-2017 , 11:43   Re: [ H3LP ] Position by votes
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
How do you handle votes and strings?
Well, on the menu, when u press a key, it increases the keycount[key] value, and that value corresponds to s_Maps[key]. What I want is to display the maps depending on the vote value correctly, so the corect s_Maps and keycount should be displayed in the hud.

Here is what I did so far

Code:
public VotesHud() {           new szMaps[1024], szList[1024], iLen;         for(new x;x < MAX_MAPS+1;++x)     {         iLen += formatex(szMaps[iLen], charsmax(szMaps),"%s. %s - %i %s^n",map_position[x], s_Maps[x], keycount[x],(keycount[x] > 1) ? "votes" : "vote");     }         formatex(szList, charsmax(szList), "Vote Results:^n%s", szMaps);         set_hudmessage(0, 255, 0, 0.65 ,0.05, 0, 0.5, 0.5, 0.0, 0.0, -1);     ShowSyncHudMsg(0, gResultsVotes, szList); }
DarthMan is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 07-12-2017 , 05:39   Re: [ H3LP ] Position by votes
Reply With Quote #4

Any ideas anyone?
DarthMan is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-12-2017 , 09:17   Re: [ H3LP ] Position by votes
Reply With Quote #5

Have you searched for the various search algorithms? I know that there are threads that discuss sorting around here.
__________________
fysiks is online now
DarthMan
Veteran Member
Join Date: Aug 2011
Old 07-12-2017 , 09:30   Re: [ H3LP ] Position by votes
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
Have you searched for the various search algorithms? I know that there are threads that discuss sorting around here.
I looked, but couldn't find anything. Could u point me to a good thread?
DarthMan is offline
heroicpower7613
Member
Join Date: Nov 2016
Old 07-12-2017 , 14:30   Re: [ H3LP ] Position by votes
Reply With Quote #7

Quote:
Originally Posted by Rohanlogs View Post

Spoiler
check this?? it sorts hud by most money
heroicpower7613 is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 07-12-2017 , 15:31   Re: [ H3LP ] Position by votes
Reply With Quote #8

Quote:
Originally Posted by heroicpower7613 View Post
check this?? it sorts hud by most money
Thanks, will check this out
DarthMan is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 07-12-2017 , 15:58   Re: [ H3LP ] Position by votes
Reply With Quote #9

Quote:
Originally Posted by heroicpower7613 View Post
check this?? it sorts hud by most money
I did this, but ti doesn't sort instantly on the right position.

Code:
SortCustom1D( keycount, charsmax(keycount), "custom_compare" )         for( new i; i < MAX_MAPS+1; i++ )     {         formatex(szMaps, charsmax(szMaps), "%s. %s - %i %s^n",map_position[i], s_Maps[i], keycount[i],(keycount[i] > 1) ? "votes" : "vote");         add( buff, charsmax( buff ), szMaps )     }         if (f_TimeLeftBeforeDone >= 0 && (!g_voteIsDone))         formatex(szList, charsmax(szList), "Vote Results:^n%sTimeleft: %d", buff, floatround(f_TimeLeftBeforeDone));     else     {         formatex(szList, charsmax(szList), "Vote Results:^n%sTimeleft: 0", buff);         g_fLeft = get_gametime ();     }
DarthMan is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-12-2017 , 15:56   Re: [ H3LP ] Position by votes
Reply With Quote #10

A basic way of sorting an array is:
PHP Code:
new array[100], aux
for(new isizeof array - 1i++)
{
    for(new 
1sizeof array; j++)
    {
        if(array[
i] > array[j])
        {
            
aux = array[i]
            array[
i] = array[j]
            array[
j] = aux
        
}
    }

To reverse the sorting order, change > to <. Apply that to your votes array.
Ideally you would have an array that contains both the votes and the map name, by using an enum. Then you sort the array by the points and on the first/last slot(depending on how you sort) will be the most voted map name.
__________________
HamletEagle is offline
Reply


Thread Tools
Display Modes

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 23:08.


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