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 04-04-2007, 08:03 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Point and Copy: Cloning Device

PHP Code:
//Point and Copy: Cloning Device
//By: Gambet

//#CLIENTSIDE
function onKeyPressed(keycode)
{
 if (
keycode == 305//Press and hold shift then press 1
  
{
    
this.cloner_on = !this.cloner_on;
    
player.chat "Outfit Cloner: " @ (this.cloner_on "On" "Off");  
  }
}

function 
onMouseDown(button)
{
 if (
button == "double")
  {
   if (
this.cloner_on)
    {
     if (
timevar2 >= this.cooldown)
      {
       for (
pplayers)
        {
         if (
mousex in |p.x,p.x+1.5| && mousey in |p.y,p.y+2|)
          {
           for (
t=0t<5t++)
            {
             
player.colors[t] = p.colors[t];
            }
            
player.headimg p.headimg;
            
player.shieldimg p.shieldimg;
            
player.bodyimg p.bodyimg;
            
player.chat "Cloning Successful!";
            
this.cooldown int(timevar2 10);
          }
        }
       for (
nnpcs)
        {
         if (
mousex in |n.x,n.x+1.5| && mousey in |n.y,n.y+2|)
          {
           for (
u=0u<5u++)
            {
             
player.colors[u] = n.colors[u];
            }
            
player.headimg n.headimg;
            
player.shieldimg n.shieldimg;
            
player.bodyimg n.bodyimg;
            
player.chat "Cloning Successful!";
            
this.cooldown int(timevar2 10);
          }
        }
      }
     else
      {
       
player.chat "You must wait " abs(int(timevar2 this.cooldown)) @ " more seconds!";
      }  
    }
  }



I havn't tested it, but it should work.


Now, from the looks of it, it's a simple NPC, yes, but it's good enough for the new scripters to learn some of the basics.


Let me break it down:


This NPC shows a good way of using the keypressed function as a source for finding keycodes by designating such in the functions parameters. I used a weird combination to show that it's possible to use key combinations to perform different tasks.

This NPC also shows a good way of setting up a variable to be defined as the mouse button that the player presses in the mousedown function. You can basically put anything inside the parameters and use it to read if the player has pressed the "left" mouse button, "right" mouse button, "double" mouse button (I.E double click), and "middle" mouse button (I.E pressed on the scroll ball). Once you define this, reading what mouse button the player clicked is easy, as displayed above.

This NPC also shows a good way of using timevar2 as a cooldown device, without the need of using a timeout. You can use timevar2 for most cooldown systems as an alternative to timeouts, which will decrease the amount of CPU time that your system takes. As you see here, I created a cooldown system without the need of a timeout, which is more efficient when it comes to lag.

This NPC also shows a way of looping through all of the players and NPCs in order to perform certain tasks that you'd wish to designate.

This NPC also shows how you can manipulate certain events that will in turn cause an NPC and/or player to act as you'd like. In this case, I check to see if when the player double clicks their mouse, if their mouse position is within a certain range of a player or NPC, then the person will end up copying the outfit of the player or NPC. You can use this method to perform plenty of tasks, not just copying attire.

And finally, this NPC also shows a good way of using a loop to loop through a player/npcs clothes colors without the need of separate this.colors[0], this.colors[1], etc. lines. You can use loops to do a lot of things much faster and more efficiently, such as when reading what keys the player pressed and so forth.


Though it is simple to those experienced, it can actually teach the newer scripters quite a few things on how to work with several functions and so forth to make scripting a bit easier and more efficient. I scripted this NPC simply for educational purposes, though it can also be used for what it is, which is a cloning device.


NOTE: If the designated NPC is not a character, then your outfit will be set to the default noob outfit.



Hope this helps,


Enjoy

Last edited by Gambet; 04-04-2007 at 09:12 PM..
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 08:40 AM.


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