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, 02:23 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
Global Trigger Weapons

Why?

I admit, it's rather simple but if you ever run into needing something like this then atleast you won't have to reinvent the wheel :P

Serverside Global Weapon Trigger

Methods:
void GlobalEvents.triggerAll( string eventName, array parameters[] );
This triggers an event on every weapon serverside. GlobalEvents should be replaced by your NPC name.

PHP Code:
function onCreated() {
  
//IMPORTANT - ASSIGN THE PERCENTSIGN
  
temp.percentSymbol "percent";

  
this.weapons NULL;
  
  
temp.charMap = {
                  {
temp.percentSymbol "045""-"},
                  {
temp.percentSymbol "042""*"},
                  {
temp.percentSymbol "047""/"},
                  {
temp.percentSymbol "032"" "}
                 }; 
  
  
temp.weaponsFolder.loadfolder("weapons/*.txt"1);
  
  for (
temp.weapontemp.weaponsFolder) {
    
temp.weapon temp.weapon.substring);
    
    for ( 
temp.chartemp.charMap )
      
temp.weapon replacetexttemp.weapontemp.char[0], temp.char[1] );
   
    
this.weapons.addtemp.weapon.substring0temp.weapon.length() - ) );
  }
}

public function 
triggerAlleventNameparameters ) {
  for ( 
temp.weaponthis.weapons ) {
    ( @ 
temp.weapon ).triggereventNameparameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5], parameters[6], parameters[7], parameters[8], parameters[9] );
  }
}

//Thanks to Dusty
function replacetext(txt,a,b) {
  if (
txt.pos(a)<0) return txt;
  
temp.txtpos txt.positions(a);
  
temp.newtxt txt.substring(0,txtpos[0]);
  for (
temp.i=0;i<txtpos.size();i++) {
    
newtxt @= b;
    
newtxt @= txt.substring(txtpos[i]+a.length(),txt.substring(txtpos[i]+a.length()).pos(a));
  }
  return 
newtxt;

Clientside Global Weapon Trigger

Same syntax as serverside. This is actually rather simple but it's one less tediuous task for yourself

PHP Code:
function onPlayerLoginpl ) {
  
findPlayerpl ).addWeaponthis.name );
}

//#CLIENTSIDE

function onCreated() {
  
GlobalEvents this;
}

public function 
triggerAlleventNameparameters ) {
   for ( 
temp.weaponplayer.weapons ) {
    
temp.weapon.triggereventNameparameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5], parameters[6], parameters[7], parameters[8], parameters[9] );
  }

I'll be posting the functionality for NPCs soon - I should have been working on an Events System instead of this, haha.

Thanks for reading!
Reply With Quote
  #2  
Old 12-02-2009, 05:11 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Hey, works. Rep for you.
__________________
Stan.
Reply With Quote
  #3  
Old 12-02-2009, 05:30 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
Would be nice if there was some way to detect files outside of levels/ being updated, as it could then auto update list. So, only suggestion I got atm is some way to update the list, ie. RC Command, a timer (deprecated though, first thing I said would be much better, but I guess we have to wait?)

edit; http://forums.graalonline.com/forums...62#post1541962
__________________
Reply With Quote
  #4  
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
  #5  
Old 12-02-2009, 11:50 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
The NPCServer also need R(ead) rights to the weapons/ folder for this to work
__________________
Reply With Quote
  #6  
Old 12-03-2009, 12:25 AM
Riot Riot is offline
Delteria Management
Join Date: Nov 2003
Location: Seminole County, Florida
Posts: 280
Riot is on a distinguished road
As a note, you can use the "removeescapesfromfilename" function to removing the escaping used in filenames (rather than the charMap you have).

removeescapesfromfilename(str) - returns string

echo(removeescapesfromfilename("weapon%045Test.txt "));
outputs: weapon-Test.txt
Reply With Quote
  #7  
Old 12-03-2009, 12:32 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Chompy View Post
The NPCServer also need R(ead) rights to the weapons/ folder for this to work
Nope, you can loadFolder() even without read rights.

Quote:
Originally Posted by Riot View Post
As a note, you can use the "removeescapesfromfilename" function to removing the escaping used in filenames (rather than the charMap you have).

removeescapesfromfilename(str) - returns string

echo(removeescapesfromfilename("weapon%045Test.txt "));
outputs: weapon-Test.txt
I've never seen that before, nice find .
__________________
Reply With Quote
  #8  
Old 12-03-2009, 12:41 AM
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 cbk1994 View Post
Nope, you can loadFolder() even without read rights.
Interesting. Thought all functions having to do with the filebrowser required rights, but I guess there are exceptions.
__________________
Reply With Quote
  #9  
Old 12-03-2009, 06:28 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Well, I guess it kinda makes sense since loadFolder() really isn't doing much but getting a list of file names.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #10  
Old 12-03-2009, 02:21 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 Riot View Post
As a note, you can use the "removeescapesfromfilename" function to removing the escaping used in filenames (rather than the charMap you have).

removeescapesfromfilename(str) - returns string

echo(removeescapesfromfilename("weapon%045Test.txt "));
outputs: weapon-Test.txt
Thanks

Updated the latest post.
Reply With Quote
  #11  
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
  #12  
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
  #13  
Old 12-05-2009, 09:14 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Why are you doing this?

PHP Code:
globalTriggerName this.name
It's probably better to just do this:

PHP Code:
globalTrigger this
then you can just do

PHP Code:
globalTrigger.function(); 
__________________
Reply With Quote
  #14  
Old 12-05-2009, 09:56 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 cbk1994 View Post
Why are you doing this?

PHP Code:
globalTriggerName this.name
It's probably better to just do this:

PHP Code:
globalTrigger this
then you can just do

PHP Code:
globalTrigger.function(); 
Ah yeah, should have done that. thanks.
Reply With Quote
  #15  
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
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 06:34 AM.


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