Need help with ammo/shooting!

D

Doooooli

Guest
So i've making this platformer game, where the player can shoot bullets! and it works! Now i've also added local coop, so you can play 2 players! And that works aswell!

But my problems is the following:

I want the players to be able to shoot at each other to gain health! Since the ammo is ham it works like a health thingy!

So i have a collision event with the bullet in my characters which has a basic hp += 1;
and that works, it heals when it touches the other player! But what the problem is it is also healing the caster aswell :/ doesn't matter where or how i shoot the ham, it still heals the shooter! So if player 1 has 10 hp and shoot player 1 will gain 1 hp and get 11 hp, and that's not what i want! I want only player 2 to be able to recieve the healing and vice versa!

How would i fix that? thx
 

Bingdom

Googledom
When you create the bullet, you can make it store a variable that holds its creator's id. So whenever the bullet collides with the player, you can check if it doesnt match. If it doesnt match then add health
 
D

Doooooli

Guest
When you create the bullet, you can make it store a variable that holds its creator's id. So whenever the bullet collides with the player, you can check if it doesnt match. If it doesnt match then add health
That sounds great! Do you know how i would do that? i mean can you give an example? :) thx!
 

Bingdom

Googledom
//Creating a bullet
with(instance_create(x,y,OBJ_Bullet) {
creator = other.id
}

//Bullet Collision
if creator != other.id {
//Add health
}
 
D

Doooooli

Guest
//Creating a bullet
with(instance_create(x,y,OBJ_Bullet) {
creator = other.id
}

//Bullet Collision
if creator != other.id {
//Add health
}
I get an error now, and i've never been really good about reading errors :/


___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Eventobj_ammo
for object obj_player:

Variable obj_player.creator(100015, -2147483648) not set before reading it.
at gml_Object_obj_player_CollisionEvent_2_1 (line 1) - if creator != other.id {
############################################################################################

This is my codes:

//Creation
bullet=instance_create(x,y,obj_ammo)
with (bullet) {
move_towards_point(mouse_x,mouse_y,5)
creator = other.id
}

//Collision
if creator != other.id {
hp += 1
}

I have probably made some easy stupid mistake :p
 
Top