Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Sorting (https://forums.graalonline.com/forums/showthread.php?t=134256998)

WhiteDragon 11-21-2009 10:19 PM

I haven't tested, but having a subvariable on an array or string literal seems a bit odd to me.

Why not just use a TStaticVar?

All that would need to be changed is that getGuildList() would need to return an array of TStaticVars, rather than say account names.

Note: If you are using a player object or something though, that would work as it extends a TGraalVar and should support subvariables.

sssssssssss 11-22-2009 02:35 AM

I have it when a guild registers, it sets up a ton of things like
this.guilds.GUILDNAME=members with access
this.guilds.GUILDNAME.kills
this.guilds.GUILDNAME.levels
this.guilds.GUILDNAME.deaths
this.guilds.GUILDNAME.rupees
this.guilds.GUILDNAME.ec
theres more too, just trying to pull the guilds with top 5 kills and post them in a gui with the code I posted a few before this.

so if SDE registered, it'd set up vars, like so:
this.guilds.SDE
this.guilds.SDE.kills
this.guilds.SDE.deaths
this.guilds.SDE.rupees

and say SNC

this.guilds.SNC
u get the picture. So Im trying to pull all the this.guilds.GUILDNAME.kills for each guild registered, sort it, get the top 5 kills, then say like "Guildname: Kills" line by line a gui.

Switch 11-22-2009 03:58 AM

PHP Code:

public function getTopAbyss(){
  
temp.guilds getGuildList();
  for (
i=0i<temp.guilds.size(); i++) {
    
temp.guilds[i].kills this.guilds.(@temp.guilds[i]).kills;
  }
  
temp.guilds.sortbyvalue("kills"nulltrue);
  echo(
temp.guilds);


Jer, I think you were a little messed up with your loop and setting the variable as temp.g.kills, because based off what Chris posted you need to save it as a subvariable in the array, though I've never used array.sortbyvalue() before.

fowlplay4 11-22-2009 04:15 AM

Quote:

Originally Posted by Switch (Post 1539590)
Jer, I think you were a little messed up with your loop and setting the variable as temp.g.kills, because based off what Chris posted you need to save it as a subvariable in the array, though I've never used array.sortbyvalue() before.

The code I posted works, as I tested it successfully.

This is basically what you'll need, you've tried enough to deserve it. :)

PHP Code:

public function getTop5() { 
  
// Initialize Array and Kills Structure  
  
temp.guildzname getGuildList();  
  
// Loop and Record Kills in the Array Member's sort variable  
  
for (temp.gtemp.guildzname) {  
    
temp.g.kills this.guilds.(@temp.g).kills;  
  }
  
// Sort 
  
temp.guildzname.sortbyvalue("kills"nullfalse);
  
// Loop through Sorted Data
  
for (temp.0temp.5temp.i++) {
    
// Determine Variables
    
temp.temp.guildzname[temp.i];
    
temp.kills this.guilds.(@temp.g).kills;
    
temp.str = (temp."'s kills: " temp.kills);
    
// Add formatted string to data array
    
temp.data.add(temp.str);
  }
  
// Return the data array  
  
return temp.data;  



Switch 11-22-2009 04:23 AM

Quote:

Originally Posted by fowlplay4 (Post 1539596)
The code I posted works, as I tested it successfully.

Well sort by value's 3rd param, in your posted script just now, has to be true for descending value.
But anyways.

PHP Code:

public function getTopAbyss(){
  
temp.guilds getGuildList();
  for (
temp.temp.guilds) {
    
temp.g.kills this.guilds.(@temp.g).kills;
  }
  
temp.guilds.sortbyvalue("kills"nulltrue);
  echo(
temp.guilds);


Echoed
NPC Code:
The script of NPC db_registeredguilds has been updated by Switch
Wolfs,Owner,Poop,SDE,BTK
The script of NPC db_registeredguilds has been updated by Switch
BTK,SDE,Poop,Wolfs,Owner
The script of NPC db_registeredguilds has been updated by Switch
SDE,BTK,Wolfs,Owner,Poop



While this
PHP Code:

public function getTopAbyss(){
  
temp.guilds getGuildList();
  for (
i=0i<temp.guilds.size(); i++) {
    
temp.guilds[i].kills this.guilds.(@temp.guilds[i]).kills;
  }
  
temp.guilds.sortbyvalue("kills"nulltrue);
  echo(
temp.guilds);


Echoed
NPC Code:
The script of NPC db_registeredguilds has been updated by Switch
BTK,Poop,Owner,Wolfs,SDE
The script of NPC db_registeredguilds has been updated by Switch
Owner,BTK,Poop,Wolfs,SDE
The script of NPC db_registeredguilds has been updated by Switch
Owner,BTK,Poop,Wolfs,SDE


Note that BTK, Owner, and Poop all have 0 kills, so they can have a random order, and Wolfs has 2 kills and SDE has 22 kills.


All times are GMT +2. The time now is 08:39 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.