Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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:08 PM.


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