Author Topic: Sorting Scripts  (Read 1257 times)

0 Members and 1 Guest are viewing this topic.

Offline ExHunter

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 154
  • Speedy go!
Sorting Scripts
« on: March 26, 2011, 08:51:26 am »
Hello,

I've wrote a Sort Script which works very well. Untill the Script does reach an amount of Data (Like 125-175 players those got saved).

The Script sorts on every MapChange the whole list new, which does the Server very Unstable.

Code: [Select]
        for j := 0 to getarraylength(playerlist)-2 do begin
          for z := 0 to getarraylength(playerlist)-2-j do begin
            if AllScore[z] < AllScore[z+1] then begin
                Placeholder := PlayerList[z];
                Placeholder2 := AllScore[z];
                PlayerList[z] := Playerlist[z+1];
                AllScore[z] := AllScore[z+1];
                PlayerList[z+1] := Placeholder;
                AllScore[z+1] := Placeholder2;
            end;
          end;
        end;
        WriteFile('censored/list.txt',PlayerList[0]);
        WriteLnFile('censored/list.txt','');
        for n := 1 to getarraylength(playerlist)-2 do begin
          WriteLnFile('censored/list.txt',PlayerList[n]);
        end;

Before this happens, it Loads the PlayerList Array with all names those are in the list.txt file. Then it Loads for every Player the Score Array. (Also the Server does Read it shortly before it). So far so good. How I said, this Script does work well. I just need an Option to not lose the Stability over this amount. Is there a possible way to Limit the Sort? (for Example if its already sorted, it will just Sort the first 100 Players, BUT keeping the rest of the List.txt file, cause i want to keep the other Players saved. Their scores are seperated saved, but for "calling" their scores ingame i need their names in the list.txt file.)

I dont need someone who writes me it, I just need someone who can "brainstorm" with me, which ways I could use to not lose all the Players above the 100 Limit.

I hope someone can help me.

Greetings,
ExHunter

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Sorting Scripts
« Reply #1 on: March 26, 2011, 02:33:28 pm »
If this is for some kind of highscore table then you could just limit its size to 50 or so. You can do this by making your arrays that hold player info 32+DESIREDSIZE long and after sorting only saving 1-DESIREDSIZE elements. Also, you could use a more efficient sort than bubblesort: "Shell Sort".


Offline ExHunter

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 154
  • Speedy go!
Re: Sorting Scripts
« Reply #2 on: April 09, 2011, 09:42:25 am »
Hm... Well Okay ive found a solution. thx ^^

(I just did sorted one player, cause it just needs to sort one player everytime when this function is called.)

Offline ExHunter

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 154
  • Speedy go!
Re: Sorting Scripts
« Reply #3 on: May 07, 2011, 03:55:23 pm »
Herrow again:

This problem is also related to my sorting script (so i decided to write it also here):

My script does work like that, that it reads every Player, that is listed in my list.

for this I use those variables:
Code: [Select]
type tStats = record
        name: string;
        stats: integer;
end;

var
  Top: array of tStats;

as an example:

Top[0].name is ExHunter.
Top[0].stats is 50.

When now a Player does gain a Stat, then it needs for the Sorting function the Array Index.

Actually it does check it with an for loop, but i saw on the devs wiki a function that is called "GetStringIndex".

GetStringIndex(name,Top); <--- and there does the problem Start.

It gives me an error for "Top". Have I seriously rename all of my variables, or how else I could get this working?

ExHunter

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Sorting Scripts
« Reply #4 on: May 07, 2011, 06:36:23 pm »
Actually it does check it with an for loop, but i saw on the devs wiki a function that is called "GetStringIndex".
Code: [Select]
function GetStringIndex(needle: string; haystack: array of string): integerit needs an array of STRING. You have an array of tStats. Problem!

Just use a for loop.