Graal Forums

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

sssssssssss 06-04-2010 10:41 PM

onwater()
 
So i have this script, and without onwater it works fine (I use it for birds), but when i put onwater in, the damn fish doesnt move period. :/

PHP Code:

function onCreated() {
  
setCharani("armageddon-fish_bass",NULL);
}
//#CLIENTSIDE
function onCreated() {
  
setTimer(0.05);
  
drawoverplayer();
  
dontblocklocal();
  
this.= -1;
}
function 
move() {
  
this.return = int(random(0,50));
  if(
this.return > 45) {
   if (
onwater(this.x+1.5,this.y+2)) {
     
this.dir this.dir int(random(-1,1));
     if (
this.dir 3) {
       
this.dir 0;
     }
     if (
this.dir 0) {
       
this.dir 3;
     }
     
this.this.dir;
  }
  
this.dir this.i;
  
this.+= vecx(this.i) / this.speed;
  
this.+= vecy(this.i) / this.speed;
 }

function 
onTimeout() {
  
checks();
  
move();
  
setTimer(0.05);



Tigairius 06-04-2010 10:53 PM

Which tileset type are you using?

sssssssssss 06-04-2010 11:11 PM

based off pics0 so i guess type 0.

Its kind of on topic, in a way now, so I'll go ahead an ask another question. Trying to find out the tile location, like 0x3AB or whatever, so I can do a movement system of sorts, but this isnt working either, tried it clientside and serverside.

PHP Code:

function OnMouseDown() {
    
player.chat tiles[mousex,mousey];



DustyPorViva 06-04-2010 11:13 PM

Move is a preexisting function :P Try renaming it.

Also, you can just do something like this:
PHP Code:

function MoveFish() {
  if (!
onwater(this.x+1.5,this.y+2)) return;
  
this.return = int(random(0,50));
  if(
this.return > 45) {
    
// stuff
  
}


'return' will stop the function immediately.

Also, it may be a problem with some sort of level thing... I doubt it, but try something like:
this.level.onwater(x,y);

sssssssssss 06-04-2010 11:21 PM

Quote:

Originally Posted by DustyPorViva (Post 1580348)
Move is a preexisting function :P Try renaming it.

Also, you can just do something like this:
PHP Code:

function MoveFish() {
  if (!
onwater(this.x+1.5,this.y+2)) return;
  
this.return = int(random(0,50));
  if(
this.return > 45) {
    
// stuff
  
}


'return' will stop the function immediately.

Also, it may be a problem with some sort of level thing... I doubt it, but try something like:
this.level.onwater(x,y);

Neither works.

fowlplay4 06-04-2010 11:44 PM

Have you considered using the built-in move? I know this probably doesn't fix your current problem but just something that could benefit you down the line.

Here's a little example of what's possible:

PHP Code:

//#CLIENTSIDE

function onCreated() {
  
showcharacter();
  
setTimer(0.05);
}

function 
onTimeout() {
  
// Move to a random location in 2 seconds.
  
moveTo(random(064), random(064), 2);
  
// Wait till movement complete
  
waitfor(this"MovementFinished");
  
// Continue looping
  
setTimer(0.05);
}

function 
moveTo(txtytime) {
  
// Determine Movement Deltas (Final take away Initial)
  
temp.dx tx this.x;
  
temp.dy ty this.y;
  
// Set New Direction
  
this.dir getdir((this.dx) - this.x,(this.dy) - this.y);
  
// Set Movement Animation
  
setcharani("walk""");
  
// Move (The 8 at the end is so the MovementFinished event is called)
  
move(temp.dxtemp.dytime8);
}

function 
onMovementFinished() {
  
setcharani("idle""");



sssssssssss 06-04-2010 11:59 PM

I was thinking of it, but was just trying to get onwater to work first. Have crabs that use that. :)

DustyPorViva 06-05-2010 01:18 AM

Try: onwater(this.x%64+1.5,this.y%64+2)

sssssssssss 06-05-2010 01:29 AM

Still the same. :/

sssssssssss 06-05-2010 05:11 AM

Quote:

Originally Posted by sssssssssss (Post 1580347)

Its kind of on topic, in a way now, so I'll go ahead an ask another question. Trying to find out the tile location, like 0x3AB or whatever, so I can do a movement system of sorts, but this isnt working either, tried it clientside and serverside.

PHP Code:

function OnMouseDown() {
    
player.chat tiles[mousex,mousey];



Any ideas onthis?

cbk1994 06-05-2010 05:32 AM

Quote:

Originally Posted by sssssssssss (Post 1580426)
Any ideas onthis?

What does it do? It should give you a number (not in hexadecimal though).

sssssssssss 06-05-2010 07:07 AM

It does nothing. No player chat or anything.

fowlplay4 06-05-2010 07:18 AM

Quote:

Originally Posted by sssssssssss (Post 1580433)
It does nothing. No player chat or anything.

It's may be case-sensitive, try:

PHP Code:

//#CLIENTSIDE
function onMouseDown() {
  
player.chat tiles[int(mousex), int(mousey)];


or even

PHP Code:

//#CLIENTSIDE
function GraalControl.onMouseDown() {
  
player.chat tiles[int(mousex), int(mousey)];



DustyPorViva 06-05-2010 07:20 AM

Floating points definitely don't matter for tiles[x,y] by the way.

sssssssssss 06-05-2010 08:52 PM

Ok, so i didnt even realize the on was cap, works fine.

Im trying to get the tile location though, and it doesnt seem thats right. How would I put player.chat to the tile location?

Tigairius 06-05-2010 08:55 PM

Quote:

Originally Posted by sssssssssss (Post 1580496)
Im trying to get the tile location though, and it doesnt seem thats right. How would I put player.chat to the tile location?

What do you mean by the tile location? Do you mean which tile is being displayed at a given (x,y)?

sssssssssss 06-05-2010 08:56 PM

I mean like the 0CxC39 stuff. or is the x,y good enough to do a movement sys with?

DustyPorViva 06-05-2010 09:01 PM

Quote:

Originally Posted by sssssssssss (Post 1580496)
Ok, so i didnt even realize the on was cap, works fine.

I suspected that, but I never brought it up :(

To get the hex codes for tiles you need to use the external editor. Open it up and lay the tiles you want, highlight them and then click the button on the top that looks like a circle with a cross in it. Graal will convert these to integers(numbers) in gscript though, hence why tiles[x,y] return numbers instead. They're all the same, though.

sssssssssss 06-05-2010 09:35 PM

so i could use tiles[x,y] the same way, if i wanted to?

DustyPorViva 06-05-2010 09:42 PM

Quote:

Originally Posted by sssssssssss (Post 1580507)
so i could use tiles[x,y] the same way, if i wanted to?

Yup./

sssssssssss 06-05-2010 09:48 PM

coo, lol. thanks.


As for the onwater part of my question, is it just that it should work and its just not?

salesman 06-05-2010 10:13 PM

try onwater2() and see if makes any difference? (sorry if someone already suggested this, I didn't read the whole thread)

sssssssssss 06-05-2010 10:16 PM

I tried with 1,1 onwater2, did the same thing. :/

salesman 06-05-2010 10:38 PM

I tried your code on my server (using new tileset type, though) and it worked fine.

Just curious, are you defining this.speed anywhere? You said it works fine without the onWater() check, but I don't see this.speed set anywhere in your post. (dividing by zero is bad and would cause this not to work!)

sssssssssss 06-05-2010 11:44 PM

Quote:

Originally Posted by salesman (Post 1580516)
I tried your code on my server (using new tileset type, though) and it worked fine.

Just curious, are you defining this.speed anywhere? You said it works fine without the onWater() check, but I don't see this.speed set anywhere in your post. (dividing by zero is bad and would cause this not to work!)

Most likely, but like I said: Works on the birds just fine. Maybe this.speed is the reason, I will try w/o it.

salesman 06-05-2010 11:55 PM

Quote:

Originally Posted by sssssssssss (Post 1580520)
Most likely, but like I said: Works on the birds just fine. Maybe this.speed is the reason, I will try w/o it.

or just make sure you're giving it a value, because you're not in your example.

sssssssssss 06-06-2010 12:25 AM

in my ex. i thought the onwater was in working, if its not, plz point out the problem.

sssssssssss 06-07-2010 03:11 AM

Quote:

Originally Posted by salesman (Post 1580523)
or just make sure you're giving it a value, because you're not in your example.

My example is the entire code. So im def not, but like i said, works with the birds.

salesman 06-07-2010 04:25 AM

Quote:

Originally Posted by sssssssssss (Post 1580696)
My example is the entire code. So im def not, but like i said, works with the birds.

You cannot divide by zero. Your code will not work until you give this.speed a value. Well, you can, your fish just wont move anywhere =p

sssssssssss 06-07-2010 05:22 AM

Quote:

Originally Posted by salesman (Post 1580715)
You cannot divide by zero. Your code will not work until you give this.speed a value. Well, you can, your fish just wont move anywhere =p

Thats just rude. If you want to put your foot in your mouth I'll give u rc on armageddon for a second, u look at the class, then Ill show you a bird flying around with it.

salesman 06-07-2010 05:36 AM

Quote:

Originally Posted by sssssssssss (Post 1580726)
Thats just rude. If you want to put your foot in your mouth I'll give u rc on armageddon for a second, u look at the class, then Ill show you a bird flying around with it.

I'm just trying to help. I copied and pasted your code on my server, set this.speed to 1, and it worked fine.

I don't see why you're being so stubborn, saying that "well, it works for birds" instead of just fixing the problem I showed you? If you did set this.speed to 1, and it's still not working, then your problem might not be in the code and there is something else conflicting. With the way you've responded though, I'm getting the feeling that you haven't even tried it yet.

cbk1994 06-07-2010 05:46 AM

Sales is correct.

http://images.encyclopediadramatica....videbyzero.jpg

PHP Code:

this.+= vecx(this.i) / this.speed
this.+= vecy(this.i) / this.speed

First, you should multiply by the speed

PHP Code:

this.+= vecx(this.i) * this.speed
this.+= vecy(this.i) * this.speed

And then just set "this.speed" in the onCreated event.

sssssssssss 06-07-2010 05:51 AM

Quote:

Originally Posted by sssssssssss (Post 1580520)
Most likely, but like I said: Works on the birds just fine. Maybe this.speed is the reason, I will try w/o it.

Quote:

Originally Posted by sssssssssss (Post 1580520)
I will try w/o it.

I took it out, it did absolutely nothing being there.
Also, I knew you couldnt divide by zero, i was simply saying it didn't apparently matter much, because the bird works fine. Dont know how, but it does.

dunno how yours works sales, b/c mine just moves anywhere it pleases, water or not.

cbk1994 06-07-2010 05:53 AM

Quote:

Originally Posted by sssssssssss (Post 1580742)
I took it out, it did absolutely nothing being there.
Also, I knew you couldnt divide by zero, i was simply saying it didn't apparently matter much, because the bird works fine. Dont know how, but it does.

Add me RC on your server and I guarantee I can find 'this.speed' being defined in the birds.

salesman 06-07-2010 05:54 AM

Quote:

Originally Posted by sssssssssss (Post 1580532)
in my ex. i thought the onwater was in working, if its not, plz point out the problem.

Quote:

Originally Posted by sssssssssss (Post 1580532)
if its not, plz point out the problem.

Next time I won't bother trying to help you

sssssssssss 06-07-2010 05:58 AM

Lol sales, I told u I'd try taking it out. -_- Sorry i got like that, guess i read what you were saying wrong unless you were just intending to be rude, but I did clearly say i'd take it out, and I tried that.

onwater still doesnt work.

salesman 06-07-2010 06:04 AM

Quote:

Originally Posted by sssssssssss (Post 1580746)
Lol sales, I told u I'd try taking it out. -_- Sorry i got like that, guess i read what you were saying wrong unless you were just intending to be rude, but I did clearly say i'd take it out, and I tried that.

onwater still doesnt work.

I wasn't intending to be rude, and I'm sorry if it came out that way...if onwater() still doesn't work, I have no clue what else to tell you.

I had a problem with projectile collision because I forgot to set newtilesets=true in the server options (it could be something stupid like that).

sssssssssss 06-07-2010 06:08 AM

:/ tried. probably a good thing to have true though.


All times are GMT +2. The time now is 08:27 AM.

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