Page 1 of 1

Limited ammo in a rifle or how do you count the shots?

PostPosted: Thu Oct 19, 2006 7:07 pm
by Diana Kennedy
Okay, some of you may solve this one trough a health bar. I hate health bars, so I would as this one:

The player is a sniper. He has an old rifle (WW1) and has to refill it after 7 shots. How can I count the shots made and make it that it is not possible to shoot after the seventh shot? (it will only play a "empty clic" sound) Player will have to click on a "reload weapon" actor to be able to do again 7 shots. How would you approach this problem?

PostPosted: Thu Oct 19, 2006 7:39 pm
by Novice
Don't want to sound rude but this isn't an advanced topic. It's quite simple it uses a single variable and an if statement:

1.Create an integer variable called ammo and set it at 7.
2.Use something like this on your mouse button event or whatever makes your sniper shoot:
Code: Select all
//WARNING!!! PSEUDO CODE 
if (ammo>0)
{
     "your shoot action here"
     ammo--;
}
else PlaySound("Empty Click");

3.On your reload button "ammo=7"
4.Enjoy! :wink:

PostPosted: Thu Oct 19, 2006 9:16 pm
by Diana Kennedy
Novice wrote:Don't want to sound rude but this isn't an advanced topic.


No offense taken! :D

It's quite simple it uses a single variable and an if statement:

1.Create an integer variable called ammo and set it at 7.
2.Use something like this on your mouse button event or whatever makes your sniper shoot:
Code: Select all
//WARNING!!! PSEUDO CODE 
if (ammo>0)
{
     "your shoot action here"
     ammo--;
}
else PlaySound("Empty Click");

3.On your reload button "ammo=7"
4.Enjoy! :wink:


Cool! Will try this out immediatly!

PostPosted: Thu Oct 19, 2006 10:18 pm
by Diana Kennedy
Well, on the target on mouse button actor I did this script:

Code: Select all

if (ammo>0)
{
     ChangeAnimation("horse1", "blackshot01", FORWARD);
     ammo--;
}
else PlaySound2("C:\\Downloads\\Sounds fuer Flash Film und Themen\\Krieg-Waffen\\entsichern-klicj.wav", 1.000000, 1, 0.000000);


For mow, it play just only the empty-click sound. So I messed up with the variable. I create a globar integer named ammo, but I don't know how to set it at 7? I tried to double click on it on the list and wrote

ammo=7; But this don't work.

I'm a noob, I know.

Other ting: When ammo is available, it should do more than one action, can I pack it in the same code,

somerthinng like this:

Code: Select all
if (ammo>0)
{
     ChangeAnimation("horse1", "blackshot01", FORWARD);
     score.textNumber = score.textNumber + 20;
     PlaySound2("C:\\Downloads\\Sounds fuer Flash Film und Themen\\Krieg-Waffen\\schuss.wav", 1.000000, 1, 0.000000);
     StopSound=(gallop1)
     ammo--;
     
}
else PlaySound2("C:\\Downloads\\Sounds fuer Flash Film und Themen\\Krieg-Waffen\\entsichern-klicj.wav", 1.000000, 1, 0.000000);


Would this be the right syntax? Or do I have to make braces after each command?

PostPosted: Thu Oct 19, 2006 10:47 pm
by Diana Kennedy
Ok! I found it out! It works! Thanks!

PostPosted: Thu Oct 19, 2006 10:49 pm
by DilloDude
You need an event to set ammo to 7. Like create actor:
Code: Select all
ammo = 7;

Code: Select all
if (ammo>0)
{
     ChangeAnimation("horse1", "blackshot01", FORWARD);
     score.textNumber = score.textNumber + 20;
     PlaySound2("C:\\Downloads\\Sounds fuer Flash Film und Themen\\Krieg-Waffen\\schuss.wav", 1.000000, 1, 0.000000);
     StopSound=(gallop1)
     ammo--;
     
}
else PlaySound2("C:\\Downloads\\Sounds fuer Flash Film und Themen\\Krieg-Waffen\\entsichern-klicj.wav", 1.000000, 1, 0.000000);

Yes, that should do the trick.

PostPosted: Fri Oct 20, 2006 8:35 am
by Diana Kennedy
Yes, well it works just nice now! :D

PostPosted: Sat Oct 21, 2006 11:13 am
by Diana Kennedy
I will offer a test version for everyone to test it, as soon as I am finshed with at least an early beta-version. But I am very confident because right now it works damn good and gives me a real shudder when I play it, since its somehow very realistic.
(At least me I do shudder, I am not this used to shooting games. Others may just yawn ;) )
The work that I am involved to do now is to draw a lot of animations of falling and fighting soldiers. This will take some time.


Yes, this forum is best when it comes to great advices and help. I never was disapointed. This is a great community.

PostPosted: Sun Oct 22, 2006 12:32 am
by Diana Kennedy
Well, now I am a bit stuck.
In fact what I want t do is, that the reloading actor (where you'll have to right-click to reload the rifle) changes its animation to a "reload" animation as soon as the 7 shots are done (rifle is empty.)

For this I expanded the script to:

Code: Select all
if (ammo>0)
{
     ChangeAnimation("horse1", "blackshot01", FORWARD);
     score.textNumber = score.textNumber + 5;
     PlaySound2("data/schuss1.wav", 1.0001, 1, 0.000000);
     ChangePath("Event Actor", "no path", BOTH_AXIS);
     stopSound(galopp1);
     ammo--;
}
else PlaySound2("data/entsichern-klicj.wav", 1.000000, 1, 0.000000);
     ChangeAnimation("reload", "reload01", FORWARD);



See last command line.

But in fact, it changes to the "reload animation from the very first shot on, i.e also when 6 shots are left.

PostPosted: Sun Oct 22, 2006 12:49 am
by Game A Gogo
you need to do this
Code: Select all
else
{
       //code here
}

or you can also make this
Code: Select all
else if(ammo<1)
{
      //your code here
}

PostPosted: Sun Oct 22, 2006 9:15 pm
by Diana Kennedy
Thanks!! 8)

PostPosted: Mon Jan 15, 2007 1:35 am
by DarkParadox
it dosn't work for me :!:

PostPosted: Sat Jan 20, 2007 1:08 pm
by DarkParadox
is there a easier way :?: