Graal Forums

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

oscarjf1 08-28-2001 08:29 PM

Arrays....
 
Hello, Im working on a script that uses arrays. This script puts images randomly across the board. That part is fine, but....its the script that goes with it. Ive tried everything....from in to arraylen(which i found out really wasnt worth trying lol). I need to know how to detect if there is an image in front of the player. It wont detect anything, because its an array, and it's value is always 10 because of setarray blach,10; I did however, use level. vars...so the other NPC CAN detect the images, but all of the commands ive tried wont work. Can anyone help me? If you need the coding...i guess i could post it, though I thought this was sufficient.

oscarjf1 08-28-2001 08:51 PM

umm
 
I have 10 values of arrays in x,y form. level.fishx and level.fishy. What i want to do, is when the player is near a level.fishx,level.fishy i want it to trigger another command, but this is difficult w/arrays. Can it be done?
Ill post the code.
NPC Code:

// NPC made by War Lord Mpg2
if (playerenters) {toweapons Spear Fisher; this.on=0;
}
if (playertouchsme) {
}
if (weaponfired) {sleep .3;
this.on=1; timeout = .05; disabledefmovement; playersprite = 35; this.move=1; client.spearing=0;
}
if (timeout) {
if (this.on=1) {
showspear(); controltest(); testfish(); showspear(); timeout = .05;
}
if (this.on=0) {hideimg 9999; enabledefmovement;
}
}

// FUNCTIONS


function showspear() {
if (playerdir=0) {showimg 9999,la-spear_u.gif,playerx,playery-2;
}
if (playerdir=1) {showimg 9999,la-spear_l.gif,playerx-2,playery+.5;
}
if (playerdir=2) {showimg 9999,la-spear_d.gif,playerx+2,playery;
}
if (playerdir=3) {showimg 9999,la-spear_r.gif,playerx+1,playery+.5;
}playersprite = 35;
return;
}


function testfish() {
if (client.spearing=1) {
if (playerdir=0) {showimg 9999,la-spear_u.gif,playerx,playery-8;
if (level.fishx in |playerx-10,playerx+10| && level.fishy in |0,64|) {client.hasfish=1;
}
}
if (playerdir=1) {
}
if (playerdir=2) {
}
if (playerdir=3) {
}
sleep .5; client.spearing=0;
}
}


function controltest() {
if (keydown(4)) {this.on=0; enabledefmovement; hideimg 9999; sleep .3;
}
if (keydown(0)) {playerdir=0;
}
if (keydown(1)) {playerdir=1;
}
if (keydown(2)) {playerdir=2;
}
if (keydown(3)) {playerdir=3;
}
if (keydown(5)) {
if (playerdir=0 && !onwall(playerx,playery-this.move)) {playery-=this.move;
}
if (playerdir=2 && !onwall(playerx,playery+this.move)) {playery+=this.move;
}
if (playerdir=3 && !onwall(playerx+2+this.move,playery)) {playerx+=this.move;
}
if (playerdir=1 && !onwall(playerx-this.move,playery)) {playerx-=this.move;
}
}
if (keydown(6)) {client.spearing=1;
}
}


That is the weapon part, that detects.
This (below) is the array part, that does the images.
NPC Code:

/ NPC made by War Lord Mpg2
if (playerenters) {enabledefmovement; this.on=1; timeout = .1; this.go=1;
}
if (this.on=1) {
setarray level.maxfish,10; setarray level.fishx,10;
setarray level.fishy,10;
for (q=0; q<10; q++;) {
level.fishx[q]=int(random(3,61));
level.fishy[q]=int(random(3,61));
}
this.on=0;
}
if (timeout) {
for (b=0; b<10; b++;) {
if (level.fishx[q]>-1) {
if (this.go=1) {
level.fishx[b]=int(random(3,61));
level.fishy[b]=int(random(3,61));
level.maxfish[b]+=1;
this.go=0;
}
}
level.randmovex=int(random(-1,2)); level.randmovey=int(random(-1,2));
if (level.randmovex<0) {setstring level.fish,spearfish2.gif;}
if (level.randmovex>0) {setstring level.fish,spearfish1.gif;}
level.fishx[b]+=level.randmovex; level.fishy[b]+=level.randmovey;
showimg b,#s(level.fish),level.fishx[b],level.fishy[b];
}
timeout = 1;
}



Lot of code, lol. Anyways, im trying to get it to where it sets client.hasfish=1 when client.spearing=1 if the player is close to a fish.

Can you help me?
(Ive got it to set client.spearing=1, lol.)

Merlin 08-28-2001 09:02 PM

couldnt you use strings?
like
if (Action) {setstring image,random(1,6);
set random;
}
while (random) {
showimg #s(image),30,30;
}

or something if you're just showing random images?

oscarjf1 08-28-2001 09:14 PM

i guess...
 
i guess i could. But that takes all the fun outta it ;). I wouldnt have to use strings...i could do what im doing, except not use arrays. level. controls vars for the whole level, which is great for this script. I guess there is no way to do it with arrays :(. I like using arrays, because they are new to me. I just learned them a few weeks ago. They are great for weather scripts and stuff. I guess i have a small enough amount of images to do each one individually, but....it would also make my weapon script longer. Id have to detect each Image differently because they would all have different values instead of the arrays where they are all level.fishx,level.fishy. there would be level.fishx1,level.fishx2,level.fishx3 ect. Ill work something out since noone has a clue either. This is gonna be a great script once its finished :-).

oscarjf1 08-28-2001 11:23 PM

yes
 
yes, thats what i want.....
How do i do it?

oscarjf1 08-29-2001 12:05 AM

umm
 
yeah, i know how to do it without using arrays. But i want lots of fish. So, what do you suggest?

oscarjf1 08-29-2001 01:00 AM

okay, so that would tell me the distance.... from the player to the fish.

so i would put
if (distance<=5) {client.hasfish=1;
}

??

And that script would make it so it would have the distance of every fish that appears?

oscarjf1 08-29-2001 09:45 PM

n/m
 
Ahh forget it. I decided to use an NPC for each fish, and have the NPC detect the player, instead of having the player detect the NPC....much easier. I finished my script in like 10 minutes this way....

Thanks for your help though!


All times are GMT +2. The time now is 07:18 PM.

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