AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [ H3LP ] Position by votes (https://forums.alliedmods.net/showthread.php?t=299332)

DarthMan 07-11-2017 11:17

[ H3LP ] Position by votes
 
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 !

HamletEagle 07-11-2017 11:26

Re: [ H3LP ] Position by votes
 
How do you handle votes and strings?

DarthMan 07-11-2017 11:43

Re: [ H3LP ] Position by votes
 
Quote:

Originally Posted by HamletEagle (Post 2534624)
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 07-12-2017 05:39

Re: [ H3LP ] Position by votes
 
Any ideas anyone?

fysiks 07-12-2017 09:17

Re: [ H3LP ] Position by votes
 
Have you searched for the various search algorithms? I know that there are threads that discuss sorting around here.

DarthMan 07-12-2017 09:30

Re: [ H3LP ] Position by votes
 
Quote:

Originally Posted by fysiks (Post 2534835)
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?

heroicpower7613 07-12-2017 14:30

Re: [ H3LP ] Position by votes
 
Quote:

Originally Posted by Rohanlogs (Post 2527524)

Spoiler

check this?? it sorts hud by most money

DarthMan 07-12-2017 15:31

Re: [ H3LP ] Position by votes
 
Quote:

Originally Posted by heroicpower7613 (Post 2534909)
check this?? it sorts hud by most money

Thanks, will check this out :)

HamletEagle 07-12-2017 15:56

Re: [ H3LP ] Position by votes
 
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.

DarthMan 07-12-2017 15:58

Re: [ H3LP ] Position by votes
 
Quote:

Originally Posted by heroicpower7613 (Post 2534909)
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 ();     }


All times are GMT -4. The time now is 23:08.

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