Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   How to shoot? (Formerly "Learning.") (https://forums.graalonline.com/forums/showthread.php?t=134258318)

Black_knights55 03-09-2010 08:46 PM

How to shoot? (Formerly "Learning.")
 
Hey,
I kind of know the really basic stuff but still, I'm new to scripting and I want to learn. I'm trying to script a simple weapon that throw anything. I first try to just throw an arrow, but the only thing I have is a shadow flying forward. If anyone can help me, I'd really like to know how exactly the functions work and where to put what in the parameters. Let's say I want my character to throw shuriken.png?

I have few mores questions after this one is solve, I'll just post them after that one. Thanks by the way for the help!

DrakilorP2P 03-09-2010 10:18 PM

Not sure what you're asking for, but I think you're trying to use shoot(), which is described here: http://wiki.graal.us/shoot

You can change the projectile's image in the last parameter:
PHP Code:

//#CLIENTSIDE
function onWeaponFired()
{
  
temp.angle getangle(vecx(player.dir), vecy(player.dir));
  
shoot(player.xplayer.yplayer.ztemp.angle00"arrow""barrow0.png");


If arrow.gani is too complicated you can make your own single-frame gani.

Black_knights55 03-10-2010 07:30 PM

Thanks, that's working.
Now, I did a new projectile called val_shuriken.png and a new gani called temp_shuri.gani. I've replaced "arrow" and "barrow0.png" but I guess I'm doing something wrong because now there's nothing shooting at all.

NPC Code:
//#CLIENTSIDE
function onWeaponFired()
{
setani("shoot",0);
temp.angle = getangle(vecx(player.dir), vecy(player.dir));
shoot(player.x, player.y, player.z, temp.angle, 0, 0, "temp_shuri", "val_shuriken.png");
freezeplayer(0.3);
}


Deas_Voice 03-10-2010 08:27 PM

post the gani please :)

Black_knights55 03-10-2010 10:02 PM

2 Attachment(s)
I just made all those thing kind of fast just to test the script.

The Shuriken: Attachment 50548
The Gani : Attachment 50547

Tigairius 03-10-2010 10:09 PM

Quote:

Originally Posted by Black_knights55 (Post 1561626)
Thanks, that's working.
Now, I did a new projectile called val_shuriken.png and a new gani called temp_shuri.gani. I've replaced "arrow" and "barrow0.png" but I guess I'm doing something wrong because now there's nothing shooting at all.

NPC Code:
//#CLIENTSIDE
function onWeaponFired()
{
setani("shoot",0);
temp.angle = getangle(vecx(player.dir), vecy(player.dir));
shoot(player.x, player.y, player.z, temp.angle, 0, 0, "temp_shuri", "val_shuriken.png");
freezeplayer(0.3);
}


Make sure the image in your gani is set to PARAM1.
Let me try to explain shoot a little bit better:

level.shoot(start x, start y, start z, direction of shot, z-angle, strength, gani, gani params);


By editing strength, you can specify strength based on the gravity settings for your server/client, increasing strength increases speed of the shot.

By changing z-angle you can make your shot arch in the air using some trigonometric math.

If you want to change your gravity, you can simply do gavity=5 (for example), which is a global variable. If you change it on the clientside, it will only affect that person's gravity, but if you change it serverside, it will affect the whole server. If you change your gravity high enough, shots will fly over walls, etc.

Quote:

Originally Posted by Black_knights55 (Post 1561651)
I just made all those thing kind of fast just to test the script.

The Shuriken: Attachment 50548
The Gani : Attachment 50547

You need to change your shuriken sprite's image to PARAM1 (on the left side of the gani editor), right now it is equal to the name of the image, but if you look in the lower right side of the gani editor it says "def param1", that means wherever PARAM1 is placed, that image will be there. By using PARAM1, you also make the image accessible by script, which is exactly what you need to do for the shoot function. However, if you don't plan to change the image at all, you can simply leave the param1 part of the shoot command blank (like "") and simply specify a gani to use.

Black_knights55 03-10-2010 11:18 PM

Thanks, I really appreciate your explanations. But, when I use the weapon, nothing is shooting. The player freeze and play the ani "shoot" but there no projectile. I don't understand why it doesn't just shoot that shuriken lol.

cbk1994 03-10-2010 11:33 PM

Quote:

Originally Posted by Black_knights55 (Post 1561674)
Thanks, I really appreciate your explanations. But, when I use the weapon, nothing is shooting. The player freeze and play the ani "shoot" but there no projectile. I don't understand why it doesn't just shoot that shuriken lol.

I can't check the GANI now (on Mac), but try setting it to "sword", then listen for the slash sound. You will also see shadows shooting if it works. The code should be similar to

PHP Code:

temp.player.+ (vecx(player.dir) * 1.5);
temp.player.+ (vecy(player.dir) * 2);
temp.0;

temp.angle = (player.dir 1) * (pi 2);
temp.zangle 0;
temp.power 0;

temp.ani "sword";
temp.ani.param "";

player.level.shoot(xyzanglezanglepoweraniani.param); 


Black_knights55 03-11-2010 12:03 AM

Yes it's working. But when I put my custom gani and image, it doesn't. Probably something with the gani I did wrong.

DrakilorP2P 03-11-2010 01:10 PM

Quote:

Originally Posted by Black_knights55 (Post 1561695)
Yes it's working. But when I put my custom gani and image, it doesn't. Probably something with the gani I did wrong.

The gani is working fine for me, except for the PARAM1 thing that Tigairius mentioned. Maybe it's not uploaded properly?

Black_knights55 03-11-2010 03:10 PM

1 Attachment(s)
I updated the gani with the PARAM1 thing, but not sure I did it well. Here's the new one.

Attachment 50549

Maybe with the upload... I've put the .gani in levels/ganis/, is that ok? Or it has to be in another specific folder?

Soala 03-11-2010 07:27 PM

1 Attachment(s)
Quote:

Originally Posted by Black_knights55 (Post 1561841)
Maybe with the upload... I've put the .gani in levels/ganis/, is that ok? Or it has to be in another specific folder?

if you have levels/ganis it should be the right folder because it should be set to allow .gani files.
If you're unsure, you can still check the folder configuration
Attachment 50550
You should have things like this:

file *.gani

and

file ganis/*.gani

cbk1994 03-11-2010 11:04 PM

Quote:

Originally Posted by alexandralove (Post 1561866)
if you have levels/ganis it should be the right folder because it should be set to allow .gani files.
If you're unsure, you can still check the folder configuration
Attachment 50550
You should have things like this:

file *.gani

and

file ganis/*.gani

An easier way to check is doing "/find filename". It should show up as downloadable. If not, the folder config is wrong.

Black_knights55 03-13-2010 03:23 PM

Thanks for your help! I made an error when writing the rights, so it wasn't able to detect the gani. So now, it throw the "shuriken" but after like half a second, the shuriken disappears and there's only the shadow left. When I tried with the "arrow.gani" the arrow was there all the time, and my gani is exactly the same, except it's single direction. Is there something I have to do with the gani to keep it visible when throwing it?

EDIT: Sorry, found my mistake. ;) It just worked all fine. Thanks a lot for all your help. It really helped me understand all that stuff lol. :)


All times are GMT +2. The time now is 01:36 AM.

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