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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Akow), 1,361 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
AUM58 workshop 33 question #319880
04/18/10 15:19
04/18/10 15:19
Joined: Apr 2010
Posts: 23
G
GieskeBon Offline OP
Newbie
GieskeBon  Offline OP
Newbie
G

Joined: Apr 2010
Posts: 23
Hello guys,

Just started with 3D Gamestudio and got a question about AUM 58, workshop33. In that example you can shoot with a rifle one bullet at a time. But I want to create a rifle who can shoot more bullets at a time randomly (like a sawed-off shotgun). I succeed, but I have a problem. The bullets are coming out randomly, but when the bullets hit each other, the program will remove the bullets.

So what I want is, how can the bullets ignore each other?


This is not the whole code, but just a part off it.

function fire_bullets()
{
proc_kill(4); // don't allow more than 1 copy of this function to run
while (mouse_left == on) // this loop runs for as long as the left mouse button is pressed
{
vec_for_vertex (temp.x, weapon1, 29); // get the coordinates for the bullets' origin
// create the bullet at camera's position and attach it the "move_bullets" function
ent_create (bullet_mdl, temp.x, move_bullets);
ent_create (bullet_mdl, temp.x, move_bullets);
ent_create (bullet_mdl, temp.x, move_bullets);
ent_create (bullet_mdl, temp.x, move_bullets);
ent_create (muzzle_pcx, temp.x, display_muzzle); // create the gun muzzle
snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100
sleep (0.14); // fire 7 bullets per second (0.14 * 7 = 1 second)
}
}

function move_bullets()
{
var bullet_speed; // this var will store the speed of the bullet
my.enable_impact = on; // the bullet is sensitive to impact
my.enable_entity = on; // and to other entities
my.enable_block = on; // as well as to level blocks
my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run
my.pan = camera.pan; // the bullet has the same pan
my.tilt = camera.tilt; // and tilt with the camera
bullet_speed.x = 200 * time; // adjust the speed of the bullet here
bullet_speed.y = (-1+random(2)); // the bullet does move sideways
bullet_speed.z = (-2+random(4));
while (my != null) // this loop will run for as long as the bullet exists (it isn't "null")
{
// move the bullet ignoring the passable entities and store the result in distance_covered
c_move (my, bullet_speed, nullvector, ignore_passable);
wait (1);
}
}

function remove_bullets() // this function runs when the bullet collides with something
{
wait (1); // wait a frame to be sure (don't trigger engine warnings)
ent_create (explosion_pcx, my.x, explosion_sprite); // create the explosion sprite
my.passable = on; // the bullets becomes passable and invisible now
my.invisible = on; // so it can't harm anyone anymore
sleep (2); // wait until the explosion_sprite() function is over
ent_remove (my); // and then remove the bullet
}

Last edited by GieskeBon; 04/18/10 15:24.
Re: AUM58 workshop 33 question [Re: GieskeBon] #319882
04/18/10 15:52
04/18/10 15:52
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Take a skill from your bullets and set this skill for each bullet to a value.
Example:
my.skill99 = 1;

Now you can check in the event remove_bullets with the skill if the you-entity is a bullet.
if(you.skill99 == 1) {return;}

I use for all my entities the skill99 for identification.
Enemies skill99 = 2;
Player skill99 = 3;
Items skill99 = 4;
and so on....

Re: AUM58 workshop 33 question [Re: Widi] #319889
04/18/10 16:55
04/18/10 16:55
Joined: Apr 2010
Posts: 23
G
GieskeBon Offline OP
Newbie
GieskeBon  Offline OP
Newbie
G

Joined: Apr 2010
Posts: 23
Thanks for the quick reply Widi.

So, in the function move_bullets I had put the my.skill99 = 1; .

function remove_bullets() // this function runs when the bullet collides with something
{
wait (1); // wait a frame to be sure (don't trigger engine warnings)

if(you.skill99 == 1) {return;}

ent_create (explosion_pcx, my.x, explosion_sprite); // create the explosion sprite
my.passable = on; // the bullets becomes passable and invisible now
my.invisible = on; // so it can't harm anyone anymore
sleep (2); // wait until the explosion_sprite() function is over
ent_remove (my); // and then remove the bullet
}

When testing it, gamestudio gives a error after the first 2 bullets touching each other. The error is "Empty pointer in remove_bullets (you.skill99==1)".

I'm still doing something wrong here...

Re: AUM58 workshop 33 question [Re: GieskeBon] #319892
04/18/10 17:40
04/18/10 17:40
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
You have to check first whether the pointer you is valid:


if(you)
{
if(you.skill99 == 1) {return;}
}

Re: AUM58 workshop 33 question [Re: Pappenheimer] #319900
04/18/10 18:10
04/18/10 18:10
Joined: Apr 2010
Posts: 23
G
GieskeBon Offline OP
Newbie
GieskeBon  Offline OP
Newbie
G

Joined: Apr 2010
Posts: 23
Stupid me wink

ok, no more errors! The only thing now is, when the bullets touch each other, they won't move any more. They just stop.

Last edited by GieskeBon; 04/18/10 18:11.

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