Thread: Fishing Rod
View Single Post
  #1  
Old 12-20-2012, 07:16 AM
Vatec Vatec is offline
Lurking
Join Date: Oct 2012
Posts: 27
Vatec is on a distinguished road
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.+ (vecx(player.dir) * 3), player.+ (vecy(player.dir) * 3), 22)) {
      
this.fishing true;
      
disabledefmovement();
      
setani("grab"NULL);
      
triggerserver("gui"this.name"startFishing"player.communityname);
    }
  }
}

function 
GraalControl.onKeyDown(codekey) {
  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(0this.possibleKeys.size() - 1))];
    
player.chat "Press " this.currentkey;
    
settimer(1.5);
  } else {
    
settimer(0);
    
caughtFish();
  }
}

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

__________________


Quote:
Originally Posted by GULTHEX View Post
so i think the problem is that onactionclientside isint a real function
Reply With Quote