Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-05-2011, 07:12 PM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Zie's Scripting Project

Hello all, I would like to begin by saying I'm learning to script very slowly. I'm currently going through PA school and scripting gives me a break from my current studies. (sounds odd but learning something different lets my mind rest a little) I have a couple of projects that I like to work on whenever I can. I would like input on my scripts so that they are made better and secure, so one day I can put these to use or someone else could learn from or use them.
Thanks,
Zie

With that said this first script is fairly simple and straight foward, but I think there might be other ways to attempt this script. It is a hat viewer/collector. I made this awhile ago, but now I would like some feedback.
PHP Code:
function onCreated() {
  
setimg("haticon.png");
  }

function 
onPlayertouchsme() {
    
addweapon("Personal/kingcj/haticon");
    
clientr.hat_array = {0,1,2,3,4,5};
 } 
 else if (
clientr.hat_array = {0,1,2,3,4,5}) {     //My goal here was if the player had the weapon it wouldn't reset the hat array... Doesn't work very well.
          
addweapon("Personal/kingcj/haticon");
  }
}

function 
onActionServerSide(tokens) {          //Lay the hat down portion, I tried vecx/vecy but it would place it somewhere awkward or too close and I would pick it back up
 
if (playerdir == 0){
  
temp.playerx 0.15
  
temp.playery 2.25;
}
if (
playerdir == 1){
  
temp.playerx 2.3;
  
temp.playery 1;
}
if (
playerdir == 2){
  
temp.playerx 0.15;
  
temp.playery 3;
}
if (
playerdir == 3){
  
temp.playerx 3.0;
  
temp.playery 1;

  
temp.npc putnpc2(temp.xtemp.ynull); //laid hat info
  
npc.hatimage tokens
  
npc.join("personal_kingcj_hatlaid"); 
  
clientr.hat_array.remove(tokens);
  }
  

//#CLIENTSIDE
function onHatShow() {    //Viewing current hats portion
  
showimg(199"hat" clientr.hat_array[this.current_hat] @ ".png"player.07,player.3);
  
changeimgpart(199,98,0,45,47);
  
showimg(201"hat" clientr.hat_array[this.current_hat 1] @ ".png"player.3,player.3);
  
changeimgpart(201,98,0,45,47);
  
showimg(202"hat" clientr.hat_array[this.current_hat 1] @ ".png"player.3,player.3);
  
changeimgpart(202,98,0,45,47);
  } 
  
function 
onHidenGo() {  //call this when a hat is choosen or ended viewing
  
hideimg(199);
  
hideimg(201);
  
hideimg(202);
  
enabledefmovement();
  
this.hatsel false;
  }
  
function 
onCreated(){   //Show basic set variables
  
this.hatsel false;
  
this.current_hat 0;
  
this.change false;
}
  
function 
onWeaponFired() {  //Fired weapon and viewing 
  
this.hatsel true;
  
disabledefmovement();
  
onHatShow();
     for (
temp.0temp.clientr.hat_array.size(); temp.i++) {
       
clientr.hat_array[temp.i].sorting clientr.hat_array[temp.i];
     }
  
clientr.hat_array.sortbyvalue("sorting""float"true);
  
setani("idle",null);
 }
  
 function 
onKeypressed(code) {  // Cycling through hats 
  
if (this.hatsel) {
    if (
keydown(3)) {
      
this.current_hat = (this.current_hat == clientr.hat_array.size() - 0:this.current_hat 1);
      
onHatShow();
  }
    else if (
keydown(1)) {   // cycling through hats the other way
      
this.current_hat = (this.current_hat == clientr.hat_array.size() - 1:this.current_hat 1);
      
onHatShow();
  }
    else if (
keydown(4) && this.haton != this.current_hat && this.change == false) {     //putting the hat on
         
player.attr[1] = "hat"clientr.hat_array[this.current_hat] @".png";
         
freezeplayer(.7);
         
setani("haton",null);
         
sleep(.7);
         
setani("idle",null);
         
this.haton this.current_hat;
         
this.change true;
         
onHidenGo();
  }       
    else if (
keydown(4) && this.current_hat == this.haton) {  //check to see if hat choosen is already on or not
        
player.chat "Hat Already On";
  }      
    else if (
keydown(4) && this.change == true) {  //switch hats
         
freezeplayer(1.35);
         
setani("hatoff",null);
         
sleep(.55);
         
setani("haton",null);
         
player.attr[1] = "hat" clientr.hat_array[this.current_hat] @".png";
         
sleep(.7);
         
setani("idle",null);
         
this.haton this.current_hat;
         
onHidenGo();
  }      
    else if (
keydown(5) && this.change == true) {  //Take off hats
        
freezeplayer(.55);
        
setani("hatoff",null);
        
sleep(.55);
        
setani("idle",null);
        
player.attr[1] = "";
        
this.change false;
        
this.haton =  -1;
        
onHidenGo();
  }
    else if (
keydown(5) && this.change == false) {  //Get out of hat viewing
        
player.attr[1] = "";
        
this.change false;
        
this.haton = -1;
        
onHidenGo();
  }      
    else if (
keydown(6) && this.current_hat && this.current_hat == this.haton) {  //Lay a hat down that player is wearing
        
freezeplayer(0.3);
        
setani("lay",null);
        
player.attr[1] = "";
        
temp.tokens clientr.hat_array[this.current_hat];
        
triggerServer("weapon",this.name,tokens);
        
this.current_hat 0;
        
this.change false;
        
this.haton = -1;
        
onHidenGo();
  }      
    else if (
keydown(6) && this.current_hat 5) {  //Lay down hat in inventory
        
freezeplayer(0.3);
        
setani("lay",null);
        
temp.tokens clientr.hat_array[this.current_hat];
        
triggerServer("weapon",this.name,tokens);
        
this.current_hat 0;
        
this.change false;
        
onHidenGo();
  }
    else if (
keydown(6) && this.current_hat <= 5) {   //Can't get rid of base set of hats
        
player.chat "You can't get rid of free hats!";}
  }

And the hat laid class is
PHP Code:
function onCreated() {
  
setimgpart("hat" this.hatimage ".png",98,0,45,47);
  }

function 
onPlayerTouchsme() {
  
clientr.hat_array.add(this.hatimage);
  
this.destroy();
  } 
Thanks for any feedback!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
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 09:14 AM.


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