Graal Forums

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

Schetti 02-11-2009 04:22 PM

Shoots
 
2 questions.
A: Can someone explain me a simple shoot script(for bullets like on era)

B:Why is shootarrow etc. clientside only?

Chompy 02-11-2009 04:25 PM

PHP Code:

// Will shoot a projectile in the direction of the player
//#CLIENTSIDE
function onCreated() {
  
temp.startx player.x+vecx(player.dir);
  
temp.starty player.y+vecy(player.dir);
  
temp.startz player.z;
  
temp.angle getangle(vecx(player.dir), vecy(player.dir));
  
temp.zangle 0;
  
temp.power  0;
  
temp.ani "arrow"// projectile ani
  
temp.aniparam0 0;
  
temp.aniparam1 0;
  
// etc
  
shoot(temp.startxtemp.startytemp.startztemp.angletemp.zangletemp.powertemp.anitemp.aniparam0temp.aniparam1); // etc with the aniparams



Crow 02-11-2009 05:00 PM

Quote:

Originally Posted by Chompy (Post 1465308)
PHP Code:

// Will shoot a projectile in the direction of the player
//#CLIENTSIDE
function onCreated() {
  
temp.startx player.x+vecx(player.dir);
  
temp.starty player.y+vecy(player.dir);
  
temp.startz player.z;
  
temp.angle getangle(vecx(player.dir), vecy(player.dir));
  
temp.zangle 0;
  
temp.power  0;
  
temp.ani "arrow"// projectile ani
  
temp.aniparam0 0;
  
temp.aniparam1 0;
  
// etc
  
shoot(temp.startxtemp.startytemp.startztemp.angletemp.zangletemp.powertemp.anitemp.aniparam0temp.aniparam1); // etc with the aniparams



May I suggest the following changes for the starting position:
PHP Code:

  temp.startx player.1.5 vecx(player.dir);
  
temp.starty player.vecy(player.dir); 


Deas_Voice 02-11-2009 09:04 PM

Quote:

Originally Posted by Crow (Post 1465312)
May I suggest the following changes for the starting position:

becaause?

Crow 02-11-2009 09:12 PM

Quote:

Originally Posted by Deas_Voice (Post 1465358)
becaause?

Because the coordinates I suggested are approximately the center of the player. If I recall correctly, that should work better with projectiles. Don't hurt me if it does not :D

Chompy 02-11-2009 10:49 PM

Quote:

Originally Posted by Crow (Post 1465312)
May I suggest the following changes for the starting position:
PHP Code:

  temp.startx player.1.5 vecx(player.dir);
  
temp.starty player.vecy(player.dir); 


A little bird told me that since projectiles use gani's they can be projected from the player's position(player.x,player.y) and not hit the player

Crow 02-11-2009 11:06 PM

Quote:

Originally Posted by Chompy (Post 1465427)
A little bird told me that since projectiles use gani's they can be projected from the player's position(player.x,player.y) and not hit the player

Good to know ;P

DustyPorViva 02-12-2009 03:22 AM

Quote:

Originally Posted by Crow (Post 1465434)
Good to know ;P

More specifically, since shoot() uses a gani, and the gani's follow the same proportions as the player(size-wise), all you have to do is put the projectile in the gani in the center(like it should be anyways). Shoot() the projectile from player.x,player.y, and the projectile will visually originate from the center of the player.

Angel_Light 02-12-2009 05:59 AM

Looking at this just brought something to my attention, is there vecz(), i know it seems pointless and most likely is, but just curious. o.O

DustyPorViva 02-12-2009 06:09 AM

Quote:

Originally Posted by Angel_Light (Post 1465563)
Looking at this just brought something to my attention, is there vecz(), i know it seems pointless and most likely is, but just curious. o.O

No, because it would always return 0, seeing as in relation to player direction, you can only move in two planes.

Schetti 02-12-2009 08:22 AM

shoot(temp.startx, temp.starty, temp.startz, temp.angle, temp.zangle, temp.power, temp.ani, temp.aniparam0, temp.aniparam1);


with the numbers or just like written above?

thatdwarf 02-12-2009 08:01 PM

just like written above as long as those variables are defined
You can see in Chompy's script where those variables (temp.startx, temp.angle, etc) are given values.

You can very well just put all the numbers/math in the appropriate location in the shoot() function, but it's very messy, and considered bad practice to use "magic numbers", meaning numbers without clear meaning.

Defining the variables beforehand gives the code more readability ^_^


All times are GMT +2. The time now is 12:49 PM.

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