Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Old Scripting Engine (GS1) (https://forums.graalonline.com/forums/forumdisplay.php?f=154)
-   -   Custom Projectile (Bow) (https://forums.graalonline.com/forums/showthread.php?t=134266672)

E_Man 06-18-2012 11:30 PM

Custom Projectile (Bow)
 
I'm trying to make a custom bow with new images for my world, I found a script online that uses the command I need: "shoot" but I could not find it in the commands list so I don't know how to completely use it properly. Also I can't figure out how to make the arrows do damage, this is what I have so far.

// NPC made by E-Man
if (created) {
setimg woodenbow.png;
}
if (playertouchsme) {
toweapons Wooden Bow;
}
if (weaponfired && playerdir=0) {
freezeplayer 0.6;
setani shoot,woodenbow1.png;
sleep 0.2;
shoot playerx-0.8,playery+0.5,2,pi/2,0,0,eman_woodenarrow,;
}
if(weaponfired && playerdir=1){
freezeplayer 0.6;
setani shoot,woodenbow1.png;
sleep 0.2;
shoot playerx-1,playery+2,2,pi,1,0,eman_woodenarrow,;
}
if(weaponfired && playerdir=2){
freezeplayer 0.6;
setani shoot,woodenbow1.png;
sleep 0.2;
shoot playerx+0.2,playery+3,2,1.5*pi,.5,0,eman_woodenarr ow,;
}
if(weaponfired && playerdir=3){
freezeplayer 0.6;
setani shoot,woodenbow1.png;
sleep 0.2;
shoot playerx+1.3,playery+2,2,pi*2,1,0,eman_woodenarrow, ;
}



Also for some reason when I shoot left the arrow is transparent, I think that may be because of the shoot command though.

DustyPorViva 06-18-2012 11:46 PM

Shoot inherits basic gani properties. In this case you can just set the graphics in the gani for each direction and they will be set automatically when fired. You can also simplify the script like so:

PHP Code:

if (weaponfired) {
  
freezeplayer 0.6;
  
setani shoot,woodenbow1.png;
  
sleep 0.2;
  
shoot playerx-0.8,playery+0.5,2,pi/2*playerdir,0,0,eman_woodenarrow,;



E_Man 06-18-2012 11:59 PM

Quote:

Shoot inherits basic gani properties. In this case you can just set the graphics in the gani for each direction and they will be set automatically when fired. You can also simplify the script like so:

PHP Code:
if (weaponfired) {
freezeplayer 0.6;
setani shoot,woodenbow1.png;
sleep 0.2;
shoot playerx-0.8,playery+0.5,2,pi/2*playerdir,0,0,eman_woodenarrow,;
}
Making the script shorter is cool, but that is not the problem I have, I need to know what the variables in the command "shoot" are, and I need to figure out why is it when I shoot only left, it is transparent, and I need to figure out how to injure npc baddies. Also that script that you said shoots weird, if you shoot left, the arrow up, if you shoot up, the arrow goes right, it goes one direction more clockwise than it should.

(Btw, how do you put a script in a PHP Code box?)

DustyPorViva 06-19-2012 12:06 AM

PHP Code:

  - new script command 'shoot' for shooting projectiles:
    
shoot x,y,z,angle,zangle,power,gani,ganiparams;
      
x,and specify the starting position
      angle 
shoot angle (when looking from the top): east is 0,
        
north 3.14/2west is 3.14south 3.14*3/2)
      
zangle the angle in vertical direction0 means the
        projectile is shoot horizontal
3.14/2 means straight to the
        sun
      power 
the shoot power which is used to shoot the projectile;
        if 
it's 0 then the projectile is shoot like an old arrow
        (doesn'
t fall downmoves 20 tiles each second)
      
gani the animation that is used for the projectilethe
        animation can be multidirectional
the engine automatically
        selects the best direction 
for the flying directionthe
        animation can have 1 step 
(not animated) or 7 stepsthen the
        engine is automatically choosing the good animation step 
for
        
the projectile flying angle when its raising then step 1 is
        taken
when flying horizontal it is step 4when it is short before
        the impact then the engine displays step 7
    When the projectile is landing 
or hitting an object then some actions
    are triggered
With the command 'setshootparams <params>;' you can set
    the parameters that the called scripts get
call 'setshootparams' before
    shooting the projectile
.
    
Client-side events:
      - 
actionprojectile:
        
is triggered when a projectile lands on the player/npc,
        
in #p(0), #p(1) etc. you have the parameters set with the
        
command setshootparams
    Server
-side events:
      - 
actionprojectile:
        
is triggered when a client has used the 'shoot' command to shoot a
        projectile 
and the projectile is landedin #p(0) and #p(1) you have
        
the x and y position of the impact in case you want to place an explosion
        
or similar things on the ground (the control-npc is automatically warped
        to the level where the impact happened
); #p(2),#p(3) etc. contain the
        
params set with 'setshootparams' (before shooting the projectile)
      - 
actionsprojectile:
        
is triggered when a server-side script has shot a projectile and the projectile
        is landed
in #p(0) and #p(1) you have the x and y position of the impact
        
(the control-npc is automatically warped to the level where the impact
        happened
); #p(2),#p(3) etc. contain the params set with 'setshootparams'
        
(before shooting the projectile)
    
Projectiles are easy to use and don't take a lot of bandwidth because only
    the shooting of the projectile needs to be sent, the movement is calculated on
    the different computers. The projectile is flying like a heavy object thrown
    through the air: the horizontal movement speed keeps the same (moves
    horzspeed=cos(zangle)*speed tiles all 0.05 seconds), the vertical speed is
    initialized as vertspeed=sin(zangle)*speed and is decreased by 0.1 all 0.05 seconds;
    then the new position (calculated all 0.05 seconds) is
    newx = x + cos(angle)*horzspeed, newy = y - sin(angle)*horzspeed,
    newz = z + vertspeed 


E_Man 06-19-2012 12:49 AM

Can you give me an example line that uses "shoot because that is kind of confusing. I mainly don't get the variables of : z, angle, zangle, and ganiparams. Also I still don't know how to use setshootparams or how to call it, and setshootparams is to do damage, right?

cbk1994 06-19-2012 01:27 AM

Quote:

Originally Posted by E_Man (Post 1697677)
Can you give me an example line that uses "shoot because that is kind of confusing. I mainly don't get the variables of : z, angle, zangle, and ganiparams. Also I still don't know how to use setshootparams or how to call it, and setshootparams is to do damage, right?

GS2 example of the shoot command:

Quote:

Originally Posted by cbk1994 (Post 1561680)
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.aniParam "";
shoot(xyzanglezanglepoweranianiParam); 


Remove the parentheses and a couple other GS2 bits and you're good to go.

E_Man 06-19-2012 03:02 AM

Quote:

Originally Posted by cbk1994 (Post 1697680)
GS2 example of the shoot command:

I can't use gs2 scripts since I'm trial, but I may be able to figure out how to use the general variables in this command with gs1 with your script. But what is pi, it's in both gs1 and gs2 scripts, is that 3.14 or does it mean something else?

Tricxta 06-19-2012 03:23 AM

Since graal functions work in radians, pi is an important variable seeing as pi *2 is equivalent to 360 degrees.

Apart from that it has no further significance.

cbk1994 06-19-2012 03:36 AM

Quote:

Originally Posted by E_Man (Post 1697693)
But what is pi, it's in both gs1 and gs2 scripts, is that 3.14 or does it mean something else?

Programming languages typically work in radians instead of degrees. There's 2pi radians in a circle.

http://uploads.graalcenter.org/uploa...987bd6e5ae.jpg

Notice how the radians on the circle (they have pi attached) compare to the degrees.

So to get the angle bullets should fly at, we can do..
PHP Code:

(player.dir 1) * (pi 2

Let's say I'm facing left, which means my dir is 1.

http://uploads.graalcenter.org/uploa...directions.png

So we can start filling in values for that expression

PHP Code:

(1) * (pi 2

simplifies to..

PHP Code:

* (pi 2

which simplifies using basic math to simply pi. If we look on that circle, we can see where the angle pi lies.

http://uploads.graalcenter.org/uploa...-annotated.jpg

This is where our bullets will fly. Try the same thing for any direction and you'll find the angle matches up to the direction the player is facing.

E_Man 06-19-2012 06:44 PM

Quote:

Originally Posted by cbk1994 (Post 1697703)
Programming languages typically work in radians instead of degrees. There's 2pi radians in a circle.

http://uploads.graalcenter.org/uploa...987bd6e5ae.jpg

Notice how the radians on the circle (they have pi attached) compare to the degrees.

So to get the angle bullets should fly at, we can do..
PHP Code:

(player.dir 1) * (pi 2

Let's say I'm facing left, which means my dir is 1.

http://uploads.graalcenter.org/uploa...directions.png

So we can start filling in values for that expression

PHP Code:

(1) * (pi 2

simplifies to..

PHP Code:

* (pi 2

which simplifies using basic math to simply pi. If we look on that circle, we can see where the angle pi lies.

http://uploads.graalcenter.org/uploa...-annotated.jpg

This is where our bullets will fly. Try the same thing for any direction and you'll find the angle matches up to the direction the player is facing.

Ok, I kind of get it, so if looking up, it's 1,pi/2? Also, I still need help with the damage too.

cbk1994 06-19-2012 07:11 PM

Quote:

Originally Posted by E_Man (Post 1697739)
Ok, I kind of get it, so if looking up, it's 1,pi/2? Also, I still need help with the damage too.

Up would be pi / 2, yes.

I wouldn't know the best way to handle damage in GS1; assuming you can't use GS2 because you're a trial and have no access to Testbed, have you tried using SuperRewards to get enough gelats for a month of gold? It might take some time, but you can usually squeeze 300 gelats out of it without too much trouble.

I really hate to see someone learning such an old and horrible language (GS1) just because they're a trial.

E_Man 06-19-2012 07:47 PM

Quote:

Originally Posted by cbk1994 (Post 1697742)
I wouldn't know the best way to handle damage in GS1; assuming you can't use GS2 because you're a trial and have no access to Testbed, have you tried using SuperRewards to get enough gelats for a month of gold? It might take some time, but you can usually squeeze 300 gelats out of it without too much trouble.

I really hate to see someone learning such an old and horrible language (GS1) just because they're a trial.

I already used most of the easy super rewards to get gold once, and I'm uncomfortable with the other things like surveys, but even if I did get gold and go on testbed, I could only do it for a month and then I would be trial again, I wish I could still be a classic account. :(

cbk1994 06-19-2012 08:22 PM

Quote:

Originally Posted by E_Man (Post 1697745)
I already used most of the easy super rewards to get gold once, and I'm uncomfortable with the other things like surveys, but even if I did get gold and go on testbed, I could only do it for a month and then I would be trial again, I wish I could still be a classic account. :(

It's pretty dumb—you have my sympathy.

E_Man 06-19-2012 08:57 PM

Now that everyone knows that I can't get gold, let's get back to the issue of figuring out how to do damage to npc baddies with a projectile on offline editor

(Why can't offline editor just used gs2 :()

E_Man 06-19-2012 11:42 PM

Quote:

Programming languages typically work in radians instead of degrees. There's 2pi radians in a circle.



Notice how the radians on the circle (they have pi attached) compare to the degrees.

So to get the angle bullets should fly at, we can do..
PHP Code:
(player.dir + 1) * (pi / 2)
Let's say I'm facing left, which means my dir is 1.



So we can start filling in values for that expression

PHP Code:
(1 + 1) * (pi / 2)
simplifies to..

PHP Code:
2 * (pi / 2)
which simplifies using basic math to simply pi. If we look on that circle, we can see where the angle pi lies.



This is where our bullets will fly. Try the same thing for any direction and you'll find the angle matches up to the direction the player is facing.

Ok, now I completely understand this. Thank you for sending this. I was even able to fix your shorted script that you said earlier

Quote:

Shoot inherits basic gani properties. In this case you can just set the graphics in the gani for each direction and they will be set automatically when fired. You can also simplify the script like so:

PHP Code:
if (weaponfired) {
freezeplayer 0.6;
setani shoot,woodenbow1.png;
sleep 0.2;
shoot playerx-0.8,playery+0.5,2,pi/2*playerdir,0,0,eman_woodenarrow,;
}
You just needed to do this
PHP Code:

if (weaponfired) {
  
freezeplayer 0.6;
  
setani shoot,woodenbow1.png;
  
sleep 0.2;
  
shoot playerx-0.8,playery+0.5,2,pi/2*(playerdir+1),0,0,eman_woodenarrow,;


As you can see, I jst slightly changed the pi/2*playerdir to pi/2*(playerdir+1) because it was shooting 90 degrees more than it should have. But I don't think this script could work shortened because when you try shooting in different directions, the bow gani changes where the bow is coming from so you can't do playery+# and playerx+# because it changes. But just so no one forgets, I will just mention that I still need to figure out how to damage baddy npcs.


All times are GMT +2. The time now is 06:51 AM.

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