Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-02-2009, 10:24 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Thanks for the advice Chompy. I was actually thinking to myself in Maths today: "Crap, I forgot to add functionality to update the list! Damn...", lol.

Anyway, enjoy!

EDIT: Holy crap, I didn't expect the percentage symbols to work!

Instructions & Code
Add this to Control-NPC - if event exists, just copy the function call and do whatever you wish.

PHP Code:
function onRCChat() {
  if ( 
params[0] == "updateweaponlist" ) ( @ globalWeaponTrigger ).updateWeaponList();

This is the updated code:

PHP Code:
function onCreated() {
  
updateWeaponList();
  
globalTriggerName this.name;
}

public function 
triggerAlleventNameparameters ) {
  for ( 
temp.weaponthis.weapons ) {
    ( @ 
temp.weapon ).triggereventNameparameters );
  }
}

public function 
updateWeaponList() {
  
this.weapons NULL;
  
  
temp.charMap = {
                  {
"%045""-"},
                  {
"%042""*"},
                  {
"%047""/"},
                  {
"%032"" "}
                 }; 
  
  
temp.weaponsFolder.loadfolder"weapons/*.txt");
  
  for (
temp.weapontemp.weaponsFolder) {
    
removeescapesfromfilenametemp.weapon );
    
this.weapons.addtemp.weapon.substring6temp.weapon.length() - ) );
  }
  
  echo( 
this.name ": weapon list updated." );


Last edited by Codein; 12-03-2009 at 02:22 PM..
Reply With Quote
  #2  
Old 12-05-2009, 01:55 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Codein View Post
PHP Code:
this.weapons.addtemp.weapon.substring6temp.weapon.length() - ) ); 
Wouldn't it need to be temp.weapon.length()-11?
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #3  
Old 12-05-2009, 11:36 AM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Switch View Post
Wouldn't it need to be temp.weapon.length()-11?
To take out the "weapon" prefix and the ".txt" suffix?
Reply With Quote
  #4  
Old 12-05-2009, 10:35 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Codein View Post
To take out the "weapon" prefix and the ".txt" suffix?
Yes since it'd still include "weapon", right? But I get what you were trying to do.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #5  
Old 12-05-2009, 10:40 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Switch View Post
Yes since it'd still include "weapon", right? But I get what you were trying to do.
o_O

Start = 6, so ommitting the 'weapon' prefix.
End = length - 4; omitting the '.txt' suffix.
Reply With Quote
  #6  
Old 12-05-2009, 11:52 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by Codein View Post
Start = 6, so ommitting the 'weapon' prefix.
End = length - 4; omitting the '.txt' suffix.
Never knew the second param in substring() took off whatever the first param didn't include.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #7  
Old 12-06-2009, 02:54 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Switch View Post
Never knew the second param in substring() took off whatever the first param didn't include.
How substring works:

"testingfoobarbaz".substring(3, 5)

It starts at 3, so it excludes the red

tes
tingfoobarbaz


Then it will extract the text between starting index 3 and the length from this index.

tes
tingfoobarbaz


The text inbetween the colored text is what you end up with
__________________
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 09:11 PM.


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