Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Fishing Rod (https://forums.graalonline.com/forums/showthread.php?t=134267605)

Vatec 12-20-2012 07:16 AM

Fishing Rod
 
Well I decided to make a fishing rod, basically the player gets told which key to press and then if they press the keys correctly in time they catch the fish. Right now I have all of it clientside which is very insecure, but I just want to get input on the neatness of my coding, and overall coding efficiency.

PHP Code:

//#CLIENTSIDE

// Stages: 0 Idle, 1 Fishing, 2 Reeling

function onCreated() {
  
this.possibleKeys = {
    
"a", "b", "c", "f", "g", "h", "i", "j"
  
};
  
this.possibleFish = {
    
"Pike", "Bass", "Salmon", "Tuna"
  
};
  
this.keysPressed = 0;
}


function 
onWeaponFired() {
  if (
this.fishingStage == 0) {
    if (
onwater2(player.x + (vecx(player.dir) * 3), player.y + (vecy(player.dir) * 3), 2, 2)) {
      
this.fishing = true;
      
disabledefmovement();
      
setani("grab", NULL);
      
triggerserver("gui", this.name, "startFishing", player.communityname);
    }
  }
}

function 
GraalControl.onKeyDown(code, key) {
  if (
key == this.currentkey && this.fishingStage == 2) {
    
temp.pl.chat = "Pressed "@key;
    
this.keysPressed++;
    
nextKey();
  } else if (
key != this.currentkey && this.fishingStage == 2) {
    
gotAway();
  }
}

function 
onTimeout() {
  if (
this.fishingStage == 1) {
    
this.fishingStage = 2;
    
setani("pull", null);
    
nextKey();
  } else {
    
gotAway();
  }
}

function 
gotAway() {
  
settimer(0);
  
this.fishingStage = 0;
  
this.keysPressed = 0;
  
enabledefmovement();
  
setani("idle", NULL);
  
player.chat = "It got away!";
}

function 
caughtFish() {
  
this.fishingStage = 0;
  
keysPressed = 0;
  
enabledefmovement();
  
setani("carry", NULL);
  
temp.fish = getRandomFish();
  
player.chat = "You caught a " @ temp.fish @ "!";
  
//Add fish to players inventory
}

function 
nextKey() {
  if (
this.keysPressed < 7) {
    
this.currentkey = this.possibleKeys[int(random(0, this.possibleKeys.size() - 1))];
    
player.chat = "Press " @ this.currentkey;
    
settimer(1.5);
  } else {
    
settimer(0);
    
caughtFish();
  }
}

function 
getRandomFish() {
  return 
this.possibleFish[int(random(0, this.possibleFish.size() - 1))];
} 



All times are GMT +2. The time now is 01:17 AM.

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