Guided Nuke

Name: Guided Nuke
Type: Weapon
Author: John Doe
Description: Player shoots a standard nuke that they can guide with the arrow keys.
Notes: Required images are attached.

[code]if (this.init != 1) {
this.arrowpower = 2; // Power if the arrow
this.arrowspeed = 1; // Speed of the projectile
this.explostype = 1; // Explosion type (1 = normal, 3 = jolt)
this.explospower = 2; // Explosion power
this.shootwait = .3; // Time it takes for the player to shoot
this.fired = 0; // Leave this alone (left for when I make it with arrays)
this.init = 1;
}
if (playerenters) {
this.fired = 0;
show;
}
if (playertouchsme) {
toweapons Guided Nuke;
timeout=.05;
hide;
}

if (this.fired = 0) {
// Edit if you want it to cost more than one heart, or take away another item
// If player doesn't have enough ammo
if (weaponfired && playerdarts<=0) {
freezeplayer this.shootwait/3;
playersprite = 33; // Player's sprite when shooting
setbow wbow4.gif; // Player's bow image
play item2.wav;
}

// Edit if you want it to cost more than one heart, or take away another item
// If player has enough ammo
if (weaponfired && playerdarts>0) {
freezeplayer this.shootwait;
playersprite = 33; // Player's sprite when shooting
setbow wbow4.gif; // Player's bow image
play item2.wav;
sleep this.shootwait;
play arrow.wav;
playerdarts --;
this.fired = 1;
dartalignment();
freezeplayer 0.1;
}
}

function dartalignment() {
if (playerdir = 0) { // Player is facing up
this.arrowx = playerx+1.25;
this.arrowy = playery-1;
}
if(playerdir==1){ // Player is facing left
this.arrowx = playerx-1;
this.arrowy = playery+1.5;
}
if(playerdir==2){ // Player is facing down
this.arrowx = playerx+1.25;
this.arrowy = playery+2;
}
if(playerdir==3){ // Player is facing right
this.arrowx = playerx+2;
this.arrowy = playery+1.5;
}
showimg 0,nuke#v(playerdir).gif,this.arrowx,this.arrowy;
return;
}

if (timeout) {
if (this.fired = 1) {
if (playerdir = 0) {
this.arrowy -= this.arrowspeed;
}
if (playerdir = 1) {
this.arrowx -= this.arrowspeed;
}
if (playerdir = 2) {
this.arrowy += this.arrowspeed;
}
if (playerdir = 3) {
this.arrowx += this.arrowspeed;
}
showimg 0,nuke#v(playerdir).gif,this.arrowx,this.arrowy;
}
testhit();
timeout = 0.05;
}

if (this.fired = 1 && weaponfired) {
putexplosion2 this.explostype,this.explospower,this.arrowx,this.arrowy;
hideimg 0;
this.fired = 0;
timeout = 0.05;
}

function testhit() {
if (this.fired = 1) {
if (onwall(this.arrowx,this.arrowy)) {
putexplosion2 this.explostype,this.explospower,this.arrowx,this.arrowy;
hideimg 0;
this.fired = 0;
timeout = 0.05;
}

if (onwater(this.arrowx,this.arrowy)) {
putleaps 5,this.arrowx-.75,this.arrowy;
timeout = 0.05;
}

for (c=0; c<compuscount; c++) {
if (abs(this.arrowx-compus[c].x)<=2 && abs(this.arrowy-(compus[c].y-0.5))<=2 && compus[c].mode != 3 && compus[c].mode != 5){
hitcompu c,this.arrowpower,this.arrowx+0.5,this.arrowy+0.5;
putexplosion2 this.explostype,this.explospower,this.arrowx,this.arrowy;
hideimg 0;
this.fired = 0;
timeout = 0.05;
}
}

for (i=1; i<playerscount; i++) {
if (abs((this.arrowx+0.7)-(players[i].x+2))<=1 && abs((this.arrowy+0.5)-(players[i].y+2))<=1.5 && playersprite != 39 && playersprite != 40){
hitplayer i,this.arrowpower,this.arrowx,this.arrowy;
putexplosion2 this.explostype,this.explospower,this.arrowx,this.arrowy;
hideimg 0;
this.fired = 0;
timeout = 0.05;
}
}
}
}[/code]

[attachment deleted by admin]

Re: Guided Nuke

Here's a tweak I made to the Guided Nuke. I haven't tested it online yet, but here's what I have changed:

Features:

  • Player is frozen in place until the guided nuke detonates.

Coding:

  • Changed timeouts a bit, so timeouts ONLY run when the nuke is active. This should save on CPU load.
  • Removed redundant calls for timeouts

[attachment deleted by admin]

Re: Guided Nuke

Thanks, man. This is a bit advanced for me, so I wasn't able to fix those problem, myself. The forum needs a reputation mod so I can +rep this guy. XD

Re: Guided Nuke

Question Lord Koryo, does this require an npc server?:
for (i=1; i<playerscount; i++) {

I mean that type of function…

Re: Guided Nuke

playerscount is a local variable that equals the ammount of players in your current level (NPCs can be included in this sometimes)

You're thinking of 'allplayers', which is a variable of everyone on the playerlist, which is an NPC Server variable.