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

Non-platform specific questions.

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

Postby Diana Kennedy » Thu Oct 19, 2006 7:07 pm

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?
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Novice » Thu Oct 19, 2006 7:39 pm

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:
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby Diana Kennedy » Thu Oct 19, 2006 9:16 pm

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!
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Diana Kennedy » Thu Oct 19, 2006 10:18 pm

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?
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Diana Kennedy » Thu Oct 19, 2006 10:47 pm

Ok! I found it out! It works! Thanks!
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby DilloDude » Thu Oct 19, 2006 10:49 pm

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Diana Kennedy » Fri Oct 20, 2006 8:35 am

Yes, well it works just nice now! :D
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Diana Kennedy » Sat Oct 21, 2006 11:13 am

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.
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Diana Kennedy » Sun Oct 22, 2006 12:32 am

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.
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby Game A Gogo » Sun Oct 22, 2006 12:49 am

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
}
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby Diana Kennedy » Sun Oct 22, 2006 9:15 pm

Thanks!! 8)
User avatar
Diana Kennedy
 
Posts: 257
Joined: Wed Dec 07, 2005 12:34 am
Location: France, where Presidents who got shot in Texas do exile ;-)
Score: 0 Give a positive score

Postby DarkParadox » Mon Jan 15, 2007 1:35 am

it dosn't work for me :!:
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Postby DarkParadox » Sat Jan 20, 2007 1:08 pm

is there a easier way :?:
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron