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))];
}