Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-05-2011, 03:15 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
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 ): 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
  
}

__________________
MY POSTS ARE PRONE TO EDITS!

Last edited by Jiroxys7; 02-05-2011 at 03:25 AM..
Reply With Quote
  #2  
Old 02-05-2011, 03:43 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #3  
Old 02-05-2011, 03:57 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
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?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #4  
Old 02-05-2011, 04:03 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #5  
Old 02-05-2011, 04:14 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by fowlplay4 View Post
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
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
Reply


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 +2. The time now is 10:20 PM.


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