Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, VoroneTZ, dpn), 1,346 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
reload problem #170468
12/01/07 18:04
12/01/07 18:04
Joined: Jan 2005
Posts: 30
F
fp Offline OP
Newbie
fp  Offline OP
Newbie
F

Joined: Jan 2005
Posts: 30
I´ve got a weapon which can shot 18 times. Every shot adds 1 to “shot counter”.
If you pick up an ammo pack there will be 18 added to “ammo_available”.
If you shot 18 times or you press the r-Key and “ammo_available is > 0 the weapon reloads automaticly.
That works fine but:

Let´s say there are 18 bullets in the weapon, that means you can shot 18 times.
But your “ammo_available” is just 3 bullets.
Then the result is that “shot_counter” counts 18 and adds 18 to “current_ammo”, but “ammo_available”
is now -15 ( because of: “if (ammo_available > 0)”
But that is not correct. If I got lets say just 3 bullets in reserve it should just add this 3 bullets to “current_ammo”
How can I fix the problem?


Here is the code:



var current_ammo = 18;
var ammo_available = 0;
var shot_counter = 0;



function reload()
{
if (ammo_available > 0)
{
ammo_available -= shot_counter;
current_ammo += shot_counter;
current_ammo = min(18, current_ammo);

while (weapon2.frame <=160)
{
weapon2.frame += 3 * time_step;
wait(1);
}
snd_play (reload_wav, 50, 0);
shot_counter = 0;
}
}



action ammo_pack2
{
my.passable = on;
while (player == null) {wait (1);}
while (vec_dist (player.x, my.x) > 70) || (ammo_available >= 180 )
{
my.pan += 3 * time_step;
wait (1);
}
ent_remove (my);
ammo_available += 18; // add more ammo
ammo_available = min(180, ammo_available);
}

Re: reload problem [Re: fp] #170469
12/02/07 16:05
12/02/07 16:05
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
Think it thru ...
If you have more than 0 ammo_available , add 18 to current_ammo...no good (ammo_available becomes less than 0) , > 18 working...
Solution :
If you have more than 0 ammo_available ,
If ammo available is < than 18
add ammo_available to current_ammo
set ammo_available to 0
Else
add 18 to current_ammo
substract 18 from ammo available

Too lazy to correct your script You'll have to do it yourself


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: reload problem [Re: EpsiloN] #170470
12/02/07 20:07
12/02/07 20:07
Joined: Jan 2005
Posts: 30
F
fp Offline OP
Newbie
fp  Offline OP
Newbie
F

Joined: Jan 2005
Posts: 30
Thank you EpsiloN, but i think that will not work.
What i want is: When reloading the weapon there will be added the same number of bullets that you have fired.
Example: You shot 3 times, current_ammo + 3, ammo_available - 3
That is why i use "ammo_counter".
It works as long as you fire 18 bullets and the weapon reloads automaticly.
But if you reload in between by pressing the "r-Key" it do not work any longer, because current_ammo should be between 0 (no Ammo in Weapon) and 18 (full weapon) I think that your example don´t work like that, right?

Re: reload problem [Re: fp] #170471
12/03/07 17:04
12/03/07 17:04
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
My example will add until your current_ammmo reaches 18 , and will substract exactly what it added from ammo_available.

To make it add exactly what you fired (wich is pointless I think since you'll always get 18 bullets anyway) :
Count the shots in ammo_counter
If ammo_counter <= ammo_available , substract ammo_counter from ammo_available and add it to current_ammo
Else , add ammo_available to current_ammo and set ammo_available to 0.
You'll get the same result , because :
You start with 18 bullets and 18 ammo_available...
You shoot 3 bullets...current_ammo is 15.
You reload (ammo_available becomes 15 (substracted 3 because of ammo_counter) and current_ammo becomes 18.
My first explanation :
You start with 18 bullets and 18 ammo_available...
You shoot 3 bullets...current_ammo is 15.
You reload (ammo_available becomes 15 (substracted 3 because thats how many you have to add till 18 for current_ammo) and current_ammo becomes 18. Do you see a diffrence ? Adding exactly what you fired thru a counter is the same as directly checking how many bullets you have to add till 18 and adding them (even without using the counter).


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1