Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Need help with player.attr sorting/queueing system. (https://forums.graalonline.com/forums/showthread.php?t=134261958)

Jiroxys7 02-05-2011 03:15 AM

Need help with player.attr sorting/queueing system.
 
Well, ~20 to a little less than 30 attributes don't really work for me. Especially if it requires dedicating certain ganis to each slot (and memorizing/documenting them..). SO I've developed a system that, when told, will actively search for a free slot within a range of slot numbers (in this case, 10-29. assuming there is no [30] as I hear it's 30 slots, and 0-29 is 30 slots.), and if it finds one, will place a gani into a client.attr slot (Then will use that list to place ganis into player.attr). And when told, will search for any ganis within that range and remove them. As well as storing an internal queue if slots 10-29 are full, and as soon as a slot opens up, places the next gani in line into the queue.

edit for clarification (and cuz I dont feel like editing the entire paragraph above :p): it actually searches between client.attr 0-19, then offsets the difference by +10 when applying it to player.attr.

I excecute the add gani command with AttrSys.addAttr(<ganiname>) and oddly enough, this was somewhat working (displaying the ganis) when I accidentally had it set up as player.attr[11] = AttrSys.addAttr(ganiname). But as of fixing that, the ganis stopped displaying when I try setting them. So I'm not sure what's up with that.

So here's my script. Can anyone figure out what I'm doing wrong this time?

PHP Code:

//#CLIENTSIDE
function onCreated(){
  
AttrSys this;
  
client.attr = {
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
    
"",
  };
  
this.queue null;
  
setTimer(0.05);
}

function 
onTimeout(){
  
doApplyAttributes();
  
setTimer(0.05);
}

public function 
addAttr(ganiname){
  if(
ganiname in client.attr){//Return if the gani is already there.
    
return;
  }
  for(
i=0;i<19;i++){
    if(
client.attr[i] == ""){//If the slot is empty, set it.
      
client.attr[i] = ganiname;
      
player.chat ganiname SPC "added to attr[" "]!";
      return;
    }
    if(
== 19 && client.attr[i] != ""){//If all slots are full, store the gani in a queue.
      
this.queue.add(ganiname);
      
player.chat "All attributes are currently taken!";
      return;
    }
  }
}

public function 
delAttr(ganiname){
  for(
i=0;i<19;i++){
    if(
client.attr[i] == ganiname){//If the slot is empty, set it.
      
client.attr[i] = "";
      
player.attr[i+10] = "";
      
player.chat "Removed" SPC ganiname SPC "from " " !";
      return;
    }
  }
}

function 
doApplyAttributes(){
  if(
this.queue == null){
    for(
i=0;i<19;i++){//If no attributes are stored, apply them.
      
if(player.attr[i+10] != client.attr[i]){
        
player.attr[i+10] = client.attr[i];
      }
    }
  }
  else{
    
//If we have stored attributes, attempt to apply the first one in the queue.
    
addAttribute(this.queue[0]);//Attempt to add the first one into the attributes.
    
temp.placeholder null;
    for(
i=1;i<this.queue.size();i++){//Shift all of the queued params down one place by copying the queue with everything one position down then..
      
temp.placeholder[i-1] = this.queue[i];
    }
    
this.queue null;
    for(
i=0;i<temp.placeholder.size();i++){//..Pasting the copied queue back into this.queue.
      
this.queue[i] = temp.placeholder[i];
    }
    
temp.placeholder null;//Clear the placeholder.
    
doApplyattributes();//Try again.
  
}
}

function 
onPlayerchats(){
    
//In case part of client.attr is cut off due to setting player attributes with RC, resulting in an undeletable client.attr slot.
  
if(player.chat == "/resetattrs"){
    
onCreated();//Run onCreated to clear client.attr
  
}



fowlplay4 02-05-2011 03:43 AM

Typically you aren't/shouldn't be going over more than 10 effects.

PHP Code:

//#CLIENTSIDE

public function clearEffects() {
  for (
temp.10temp.30temp.i++) player.attr[i] = "";
}

public function 
addAttrEffect(ganilength) {
  
temp.findOpenAttr();
  
player.attr[i] = gani;
  
this.scheduleevent(length"HideAttrEffect"temp.i);
  return 
temp.i;
}

public function 
hideAttrEffect(gani) {
  for (
temp.10temp.30temp.i++) {
    if (
player.attr[i] == ganiplayer.attr[i] = "";
  }
}

function 
onHideAttrEffect(i) {
  
player.attr[i] = "";
}

function 
findOpenAttr() {
  for (
temp.10temp.30temp.i++) {
    if (
player.attr[temp.i] == "") return temp.i;
  }
  return 
10;


Your effects should be applied to other systems using their data (gani, params, and how long it needs to be there) and not by a continuous 20 FPS loop using a client array, which allows me to simplify your system to above.

Jiroxys7 02-05-2011 03:57 AM

Ah, alright. Thanks. However, although the player.attr is being set, the particle still refuses to show.
I can do player.chat = player.attr[i], and it'll return the correct name of the gani.
I've even tried setting player.attr[11] in onCreated() with the system I posted above (making sure to disable the rest of the script from clearing anything) and for some reason it STILL won't show again. Am I forgetting something?

fowlplay4 02-05-2011 04:03 AM

Post the gani, and what the attr is getting set to exactly. I.e:

player.attr[11] = "idle.gani";

should display a gani idle on the player.

Jiroxys7 02-05-2011 04:14 AM

Quote:

Originally Posted by fowlplay4 (Post 1628092)
Post the gani, and what the attr is getting set to exactly. I.e:

player.attr[11] = "idle.gani";

should display a gani idle on the player.

Augh, I just had some stuff typed out when I remembered that It had only worked when I added +4 to the 11.

And remembering something else: since I had been reserving player.attr[11] in the past and it's on a loop that clears it as soon as it's a variable stops showing up in the bufflist, would explain why It was not showing up normally during the tests. And would explain why just now testing player.attr 12 and up worked fine.
Man I feel like an idiot.. Thanks for your help though :)


All times are GMT +2. The time now is 10:51 AM.

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