Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   almost got this npc.. it uses same variables for all arrows! (https://forums.graalonline.com/forums/showthread.php?t=63198)

checkmyparanoia 01-04-2006 07:45 AM

almost got this npc.. it uses same variables for all arrows!
 
NPC Code:

// NPC made by Sephroth{ravenfist dynasty} ; edited by xeno
if(playerenters){
show;
if (this.init!=1) { //redundant but whatever
if (this.init!=1) {

this.rateoffire = 100;
this.maxrateoffire = 500;

//this.maxcount is the maximum amount of arrows
//allowed on screen at one time (higher #=more lag)
this.maxcount=30;

//this.life is the amount of time (in seconds)
//an arrow can be on screen (higher #=more lag)
this.life=6;

//this.arrowspeed is the rate at which an arrow
//moves (1=normal arrow's speed)
this.arrowspeed=.1;

//this.arrowdamage is the amount of half hearts
//taken off which each successful hit
this.arrowdamage=3;

//don't edit the following (initalizes the arrays)
setarray this.arrowx,this.maxcount+1;
setarray this.arrowy,this.maxcount+1;
setarray this.arrowdir,this.maxcount+1;
setarray this.arrowtime,this.maxcount+1;
setarray this.arrowact,this.maxcount+1;
this.init=1;
}
}
}

//puts weapon in inventory
if (playertouchsme) {


toweapons pistol;

timeout=.05;
}

if (mouseup) callweapon selectedweapon,weaponfired,nothing;

if(weaponfired&&playerdarts>0&&this.rateoffire<thi s.maxrateoffire){
//freezeplayer .01;
this.rateoffire=this.rateoffire+100;
playersprite=33;
playerdarts--;
//change the gif name below to change
//the gif of the bow the player uses when the weapon
//is fired
setbow medbow.gif;

//dont edit until you see another "//"
sleep .1;
play arrow.wav;

if (mousex>playerx){
sidemod = 1;
sidedis = mousex - playerx;
}
if (mousex<playerx){
sidedis = playerx - mousex;
sidemod = -1;
}
if (mousey>playery){
talldis = mousey - playery;
tallmod = 1;
}
if (mousey<playery){
tallmod = -1;
talldis = playery - mousey;
}
sidedis = sidedis * sidemod;
talldis = talldis * tallmod;
sidedis = sidedis / 8;
talldis = talldis / 8;

if(playerdir==3)
{
this.arrowx[this.out]=playerx;
this.arrowy[this.out]=playery;
this.arrowmodx[this.out] = sidedis;
this.arrowmody[this.out] = talldis;
}
if(playerdir==0){
this.arrowx[this.out]=playerx;
this.arrowy[this.out]=playery;
this.arrowmodx[this.out] = sidedis;
this.arrowmody[this.out] = talldis;
}
if(playerdir==1){
this.arrowx[this.out]=playerx;
this.arrowy[this.out]=playery;
this.arrowmodx[this.out] = sidedis;
this.arrowmody[this.out] = talldis;
}
if(playerdir==2){

this.arrowx[this.out]=playerx;
this.arrowy[this.out]=playery;
// this.arrowmody[this.out] = 0;
// this.arrowmodx[this.out] = -5; //////down
this.arrowmodx[this.out] = sidedis;
this.arrowmody[this.out] = talldis;
}
this.arrowdir[this.out]=playerdir;
this.arrowact[this.out]=0;
this.out++;
timeout=.05;
}
if(timeout){
if(this.rateoffire>0){this.rateoffire=this.rateoff ire-6;}
timeout=.05;
for(e=0;e<this.out;e++){
if(this.arrowact[e]==0){
if(this.arrowdir[e]==3){
this.arrowx[e]+=this.arrowspeed;

//change the gifname below to change the gif
//shown when the arrow travels right
showimg e,magbulletr.gif,this.arrowx[e],this.arrowy[e];
}

if(this.arrowdir[e]==0){
this.arrowy[e]-=this.arrowspeed;

//change the gifname below to change the gif
//shown when the arrow travels up
showimg e,magbulletu.gif,this.arrowx[e],this.arrowy[e];
}

if(this.arrowdir[e]==1){
this.arrowx[e]-=this.arrowspeed;

//change the gifname below to change the gif
//shown when the arrow travels left
showimg e,magbulletl.gif,this.arrowx[e],this.arrowy[e];
}

if(this.arrowdir[e]==2){
this.arrowy[e]+=this.arrowspeed;

//change the gifname below to change the gif
//shown when the arrow travels down
showimg e,magbulletd.gif,this.arrowx[e],this.arrowy[e];

}
this.arrowx[e] = this.arrowx[e] + this.arrowmodx;
this.arrowy[e] = this.arrowy[e] + this.arrowmody;


this.arrowtime[e]++;
}else{
this.arrowtime[e]=this.life*20;
}
for (c=0; c<compuscount; c++) {
if (abs(this.arrowx[e]-compus[c].x)<=2 &&
abs(this.arrowy[e]-(compus[c].y-0.5))<=2 &&
compus[c].mode!=3&&
compus[c].mode!=5){

//EDIT THIS TO HEAL BADDIES
hitcompu c,-1*this.arrowdamage,this.arrowx[e]+0.5,this.arrowy[e]+0.5;
//just delete "-1*" and it'll heal a baddy when they get hit.

this.arrowact[e]=1;
}
}
for (d=1; d<playerscount; d++) {
if (abs((this.arrowx[e]+0.7)-(players[d].x+2))<=1 &&
abs((this.arrowy[e]+0.5)-(players[d].y+2))<=1.5){
hitplayer d,this.arrowdamage,this.arrowx[e],this.arrowy[e];
//SCORE damage here
this.arrowact[e]=1;
}
}
if (this.arrowtime[e] >= (this.life*20)) {
hideimg e;
for (b=e; b<=this.out && b<20; b++) {
this.arrowx[b] = this.arrowx[b+1];
this.arrowy[b] = this.arrowy[b+1];
this.arrowdir[b] = this.arrowdir[b+1];
this.arrowact[b] = this.arrowact[b+1];
this.arrowtime[b] = this.arrowtime[b+1] - 1;
}
this.arrowx[this.out] = -1;
this.arrowy[this.out] = -1;
this.arrowdir[this.out] = -1;
this.arrowtime[this.out] = -1;
this.arrowact[this.out] = -1;
this.out--;
a--;
hideimg this.out;
}
}
timeout=.05;
this.mmx = mousescreenx;
this.mmy = mousescreeny;
players.bombs = mousescreenx;
}

if (playerchats&&isweapon) {
if (strequals(#c,ordinance)) {
//set bootson;
setlevel2 every.nw, 19, 19;
timeout=.05;
}
}



heh.. ok i changed it, it still does it :/

Lance 01-04-2006 08:06 AM

First, you should take care of that whole "you have code outside of event blocks" problem.

Then, you should be able to see part of why it isn't working properly.

I suggest you read this.

checkmyparanoia 01-04-2006 08:33 AM

still dont see it.... will you point out what is outside of the blocks?

Lance 01-04-2006 08:52 AM

Quote:

Originally Posted by checkmyparanoia
still dont see it.... will you point out what is outside of the blocks?

Hint: Look at the very first line of actual code.

checkmyparanoia 01-11-2006 07:07 AM

i edited that.. thanks.. ah i think the problem might be arrays.

ApothiX 01-11-2006 06:55 PM

You should also take a look at the rules about posting whole scripts.

Yen 01-11-2006 10:21 PM

...
This script gave me a headache, so I stopped half way down.
It looks like you're basically trying to rescript the shoot command. If this is the case, why don't you just use the shoot command?

Moondeath_2 01-19-2006 10:49 PM

It also confuses me why he used toweapons. -_-;

Yen 01-19-2006 10:50 PM

That was a script from ShadowDragons.


All times are GMT +2. The time now is 01:56 PM.

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