Graal Forums

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

coreys 05-14-2005 08:35 PM

Gravity
 
Well, can anyone tell me how to go about making a gravity script, cause I havent the slightest idea of how to make one.

Just for the record, I'm not asking for a full script so don't give me one, just explain how I should go about doing it, if you know.

xAndrewx 05-14-2005 09:13 PM

Think about the player’s position in the level.
[playerx,playery]

coreys 05-14-2005 09:14 PM

I know that but...

xAndrewx 05-14-2005 09:32 PM

But what? that's all you mainly need to know.
Are you using pics1.png?

coreys 05-14-2005 09:39 PM

well, we are going to use an edit of it.

ahhhh, now i understand the basic concept of it. =]

now to try...but, I need to knwo how to do the onwall checking for moving the player like there's gravity, so the player doenst just go through a wall.

xAndrewx 05-14-2005 10:05 PM

If you're editing the pics1.png I don't think you need a onwall part :o.
(Not to sure on this though, sorry)

coreys 05-14-2005 10:09 PM

Well, can anyone tell me of any errors in this, or if this will work. (Im sure theres at least one error cause rc keeps saying there is, but I can't isolate it)
PHP Code:

// NPC made by Vash-Aniki(*coreys)
// [Copyright © 2005]
//#CLIENTSIDE
if (created) {
  
disabledefmovement;
}
if (
client.grav) {
  if (
keydown(1)) {
    if (
timeout == 0) {
      
timeout 0.35;
      
playery -= .5;
      
sleep .05;
      if (!
onwall(playerx,playery)) {
        
playery -= .5;
   }
      
sleep .05;
      if (!
onwall(playerx,playery)) {
        
playery -= .5;
   }
      
sleep .05;
      if (!
onwall(playerx,playery)) {
        
playery -= .5;
   }
      
sleep .05;
      if (!
onwall(playerx,playery)) {
        
playery += .5;
   }
      
sleep .05;
      if (!
onwall(playerx,playery)) {
        
playery += .5;
   }
      
sleep .05;
      if (!
onwall(playerx,playery)) {
        
playery += .5;
   }
      
sleep .05;
       if (!
onwall(playerx,playery)) {
       
playery += .5;
   }
  }
 }
else if (
keydown(2)) {
  
playerx -= .5;
 }
else if (
keydown(3)) {
  
playery += .5;
 }
else if (
keydown(4)) {
  
playerx += .5;
 }
if (!
onwall) {
  if (
timeout == 0) {
    
playery += .5;
  }
 }
else {
  
enabledefmovement;



Kaimetsu 05-14-2005 10:13 PM

Don't mix sleeps and timeouts.

Also: KSI-GS.

Velox Cruentus 05-14-2005 10:16 PM

Horrible.

PHP Code:

//#CLIENTSIDE
if (created) {
  
disabledefmovement;
}
if (
timeout)
{
  
this.mx = (keydown(0) - keydown(2))/2;
  
this.my = (keydown(3) - keydown(1))/2;
  if (!
onwall(playerx this.mx,playery))
    
playerx += this.mx;
  if (!
onwall(playerx,playery this.my))
    
playery += this.my;

  
playery += 0.1;
  
timeout 0.05;


This is a lot better, but may not be what you want (I just rescripted what you did)

Try to keep it short and simple, and make sure that you don't get conditions where events should go... Use KSI-GS... Think about what you really want.


--- EDIT:

Something you might want to take in consideration is that the gravitational pull accellerates with time. Thereby, a constant for the decrease wouldn't be what you're aiming for.

coreys 05-14-2005 10:22 PM

Umm, I'm not that great of a scripter so if you could explain that whole thing out for me that would be great. So i can understand what all that means xD

Velox Cruentus 05-15-2005 02:11 AM

PHP Code:

//#CLIENTSIDE
if (created) {
  
disabledefmovement;
}
if (
timeout)
{
  
this.my = (keydown(2) - keydown(0))/2;
  
this.mx = (keydown(3) - keydown(1))/2;
  if (!
onwall(playerx this.mx,playery))
    
playerx += this.mx;
  if (!
onwall(playerx,playery this.my))
    
playery += this.my;

  
playery += 0.1;
  
timeout 0.05;
}
// Script Corrected. 

First off: Start every group with events... Basically, events are what happens for something to execute:

PHP Code:

if (timeout// == Whenever the timeout var reaches 0, it calls a timeout event. 

... and...
PHP Code:

 this.my keydown(2) - keydown(0); 

Okay: Here, the principal is... Whenever up key is pressed, it returns a 1... Whenever down key is pressed, it returns a 1.

this.my = 1 - 0 = 1; That would make it go towards the right.
If no keys are pressed, this.my = 0;... If only the up key is pressed...

this.my = 0 - 1 = -1; So, it would go up.

Onwall tests the actual movement.

PHP Code:

  playery += 0.1// Here should be something that increases all the time: 

Make it:
PHP Code:

  if (!onwall(playerx,playery this.grav))
    
this.grav this.grav 0.1;
  else 
this.grav 0;
  
playery += this.grav

This is a very rough show on how it works... But well, basically, the force of gravity increases steadily everytime that the player can 'fall'.
The rest of the script works with the actual moving of the character.

coreys 05-15-2005 03:44 AM

This better?
PHP Code:

//Made by Corey "Vash-Aniki(*coreys)" Schram
//[Copyright Corey Schram © 2005]
if (created) {
  
timeout 0.05;
  
this.speed 0.1;
}
if (
timeout) {
  if (
clientr.grav==1) {
    if (
onwall2(playerx,playery-1,3,1) || onwall2(playerx-1,playery,1,3) || onwall2(playerx,playery+3,3,1) || onwall2(playerx+3,playery,3,1)) {
      
this.speed 0;
  }
else {
  
playery+=this.speed*2;
  if (
keydown(1)) playerx -= 1;
  if (
keydown(2)) playery -= 1;
  if (
keydown(3)) playerx += 1;
  if (
keydown(4)) playery += 1;
  }
 }



falco10291029 05-15-2005 05:27 AM

For a true gravity affect this.speed should increase over time.

Velox Cruentus 05-15-2005 06:06 AM

Yes. And you can simplify the equation of the movement to what I told you earlier:

PHP Code:

 this.my keydown(2) - keydown(0);
 
this.mx keydown(3) - keydown(1); 

Other then that... this.speed needs to increase over time...

I don't even know why you check for clientr.grav.

Maxalou2k 06-06-2005 11:12 PM

Try this...
PHP Code:

// NPC made by someone... I hope
if (playerenters) {
hide;
toweapons *Gravity;
playerx=int(playerx);
playery=int(playery);
playerdir=3;
timeout=0.05;
}
if (
timeout&&isweapon) {
if (!
antigravity) {
if (
keydown(0)&&playersprite>=1&&playersprite<=8playery+=0.5;
if (
playerdir==0||playerdir==2playerdir=gravdir;
if (
onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)) {
velocity=0;
playery=int(playery);
if (
keydown(6)) velocity=-2;

}
else if (
keydown(2)&&playersprite>=1&&playersprite<=8playery-=0.5;
if (
onwall(playerx+0.5,playery-0.1)||onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)||onwall(playerx+1.5,playery-0.1)) velocity=0.1;
else {
if (
velocity>-0.1&&velocity<=0velocity=0.1;
if (
velocity>3velocity=3;
}
if (
abs(velocity)>0) {
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
}
velocity+=abs(velocity/4);
if (
this.shot==9) {
hideimg 345;
this.shot=0;
}
if (
this.shot>0) {
if (
this.sd==1this.sx-=0.75;
if (
this.sd==3this.sx+=0.75;
showimg 345,busterl2d#v(this.sd).gif,this.sx,this.sy;
if (this.sd==1) {
if (
testplayer(this.sx,this.sy)>-2hitplayer testplayer(this.sx,this.sy),2,playerx,playery;
if (
testnpc(this.sx,this.sy)>-2hitnpc testnpc(this.sx,this.sy),2,playerx,playery;
if (
testcompu(this.sx,this.sy)>-2hitcompu testcompu(this.sx,this.sy),2,playerx,playery;
}
if (
this.sd==3) {
if (
testplayer(this.sx+1,this.sy)>-2hitplayer testplayer(this.sx+1,this.sy),2,playerx,playery;
if (
testnpc(this.sx+1,this.sy)>-2hitnpc testnpc(this.sx+1,this.sy),2,playerx,playery;
if (
testcompu(this.sx+1,this.sy)>-2hitcompu testcompu(this.sx+1,this.sy),2,playerx,playery;
}
this.shot++;
}
if (
playersprite==11&&playerhearts==playerfullhearts) {
this.shot=1;
this.sd=playerdir;
if (
this.sd==1) {
this.sx=playerx-2;
this.sy=playery+1;
}
if (
this.sd==3) {
this.sx=playerx+2;
this.sy=playery+1;
}
showimg 345,busterl2d#v(this.sd).gif,this.sx,this.sy;
}
if ((
keydown(0)||keydown(2))&&!(keydown(1)||keydown(3))) playersprite=0;
if (
keydown(1)&&!keydown(3)) playerdir=1;
if (
keydown(3)&&!keydown(1)) playerdir=3;
gravdir=playerdir;
}
timeout=0.05;
}
if (
created) {
if (
keydown(6)) {setani jumpnrun,;}



Amagius 06-06-2005 11:58 PM

Quote:

Originally Posted by Maxalou2k
Try this...
PHP Code:

// NPC made by someone... I hope
if (playerenters) {
hide;
toweapons *Gravity;
playerx=int(playerx);
playery=int(playery);
playerdir=3;
timeout=0.05;
}
if (
timeout&&isweapon) {
if (!
antigravity) {
if (
keydown(0)&&playersprite>=1&&playersprite<=8playery+=0.5;
if (
playerdir==0||playerdir==2playerdir=gravdir;
if (
onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)) {
velocity=0;
playery=int(playery);
if (
keydown(6)) velocity=-2;

}
else if (
keydown(2)&&playersprite>=1&&playersprite<=8playery-=0.5;
if (
onwall(playerx+0.5,playery-0.1)||onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)||onwall(playerx+1.5,playery-0.1)) velocity=0.1;
else {
if (
velocity>-0.1&&velocity<=0velocity=0.1;
if (
velocity>3velocity=3;
}
if (
abs(velocity)>0) {
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
if ((
velocity>0&&(onwall(playerx+0.5,playery+3)||onwall(playerx+1.5,playery+3)))||(velocity<0&&(onwall(playerx+0.5,playery)||onwall(playerx+1.5,playery)))) playery=int(playery);
else 
playery+=velocity/6;
}
velocity+=abs(velocity/4);
if (
this.shot==9) {
hideimg 345;
this.shot=0;
}
if (
this.shot>0) {
if (
this.sd==1this.sx-=0.75;
if (
this.sd==3this.sx+=0.75;
showimg 345,busterl2d#v(this.sd).gif,this.sx,this.sy;
if (this.sd==1) {
if (
testplayer(this.sx,this.sy)>-2hitplayer testplayer(this.sx,this.sy),2,playerx,playery;
if (
testnpc(this.sx,this.sy)>-2hitnpc testnpc(this.sx,this.sy),2,playerx,playery;
if (
testcompu(this.sx,this.sy)>-2hitcompu testcompu(this.sx,this.sy),2,playerx,playery;
}
if (
this.sd==3) {
if (
testplayer(this.sx+1,this.sy)>-2hitplayer testplayer(this.sx+1,this.sy),2,playerx,playery;
if (
testnpc(this.sx+1,this.sy)>-2hitnpc testnpc(this.sx+1,this.sy),2,playerx,playery;
if (
testcompu(this.sx+1,this.sy)>-2hitcompu testcompu(this.sx+1,this.sy),2,playerx,playery;
}
this.shot++;
}
if (
playersprite==11&&playerhearts==playerfullhearts) {
this.shot=1;
this.sd=playerdir;
if (
this.sd==1) {
this.sx=playerx-2;
this.sy=playery+1;
}
if (
this.sd==3) {
this.sx=playerx+2;
this.sy=playery+1;
}
showimg 345,busterl2d#v(this.sd).gif,this.sx,this.sy;
}
if ((
keydown(0)||keydown(2))&&!(keydown(1)||keydown(3))) playersprite=0;
if (
keydown(1)&&!keydown(3)) playerdir=1;
if (
keydown(3)&&!keydown(1)) playerdir=3;
gravdir=playerdir;
}
timeout=0.05;
}
if (
created) {
if (
keydown(6)) {setani jumpnrun,;}



MY EYES? Long and unformatted codeseses...

Maxalou2k 06-07-2005 03:34 AM

Quote:

Originally Posted by Amagius
MY EYES? Long and unformatted codeseses...

Well, i tried it and it worked...

Kaimetsu 06-07-2005 03:52 AM

Quote:

Originally Posted by Maxalou2k
Well, i tried it and it worked...

That doesn't make it a good script.

Maxalou2k 06-07-2005 10:57 AM

I know but i made my possible. I'm trying to check for bugs...

Robin 07-08-2005 03:45 AM

ewwwwww......


kaimetsu.. did you lose your modship or something? O.o

back in the old day's you'd be ripping these threads up.





did someone.....BREAK you??

Damix2 07-08-2005 03:51 AM

Hes not as hardcore anymore. Duh!

Robin 07-08-2005 03:54 AM

I think i'm going to cry!

:(

Kaimetsu isn't a hardass anymore?

BUT WHO WILL SPANK ME!?

Python523 07-08-2005 08:02 AM

Quote:

Originally Posted by Robin
I think i'm going to cry!

:(

Kaimetsu isn't a hardass anymore?

BUT WHO WILL SPANK ME!?

Me.

WanDaMan 07-08-2005 12:45 PM

Enough with the homosexual jokes :\

Haha, Jagen you dirrty boy :)

smurfmidgetninja 07-08-2005 07:31 PM

Quote:

Originally Posted by Amagius
MY EYES? Long and unformatted codeseses...

Yeah that is really long but I don't get why people like all the damn spaces and "formatting" ... I think it looks better and is easier to read when its like in block type thing like that....

Skyld 07-08-2005 08:22 PM

Quote:

Originally Posted by smurfmidgetninja
Yeah that is really long but I don't get why people like all the damn spaces and "formatting" ... I think it looks better and is easier to read when its like in block type thing like that....

Good formatting makes it easier to identify problems with code.

Robin 07-10-2005 12:19 PM

Quote:

Originally Posted by Python523
Me.

ITS JON! ILU!

seriously though, where did the dictatorship go? it's like the drama dried up! :(

PastAustin 07-29-2005 12:11 AM

Quote:

Originally Posted by Kaimetsu
That doesn't make it a good script.

Oh Kai. I miss you. You should really rip this thread up.

Just giving out code willy-nilly is not learning how to script!


Quote:

Originally Posted by Python523
Me.


Fine just spank him. Leave nothing for me. Fine.


edit: I'm back. =-)


All times are GMT +2. The time now is 07:48 AM.

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