Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Cloned Enemies with individual health.
- ret12345647
- Scratcher
20 posts
Cloned Enemies with individual health.
Hi! So I'm making a Mega Turrican inspired game (Mega Turrican is a run and gun game) and, I'm having trouble with enemy clone health. I made a script witch was this:
when I start as a cloneI hope this script explained my problem well!
forever
if <touching [ Shot Type] ?> then
if <not <(Current Weapon) = [Flamethrower]>> then
change [Health] by (([Shot Power] of [Shoot Type]) * (-1))
else
change [Health] by (([Shot Power] of [Shoot Type]) * (-1))
repeat (4)
change [Health] by (-1)
wait (1) secs
end
end
end
if <(Health) < [0]> then
delete this clone
end
end
Last edited by ret12345647 (March 31, 2024 23:20:24)
- Scorbunny456
- Scratcher
63 posts
Cloned Enemies with individual health.
To have each sprite have its own health, the variable has to be for that sprite only. If it is a variable for all sprites, each clone won't have its own copy of it.
I also recommend setting the health at the top of the ‘When I start as a Clone’ script, but if you have this elsewhere it might be ok.
I hope this helps!
I also recommend setting the health at the top of the ‘When I start as a Clone’ script, but if you have this elsewhere it might be ok.
I hope this helps!
- ret12345647
- Scratcher
20 posts
Cloned Enemies with individual health.
The Health Variable is not for all sprites, but every time I shoot the enemy, it dies in one shot, even though it's not supposed to. I know I but the health variable set to one somewhere in the script, but when I shoot the enemy that isn't supposed to have 1 health, it dies immediately, therefore implying that only the 1 health enemy would work. When shooting it.
- Scorbunny456
- Scratcher
63 posts
Cloned Enemies with individual health.
I would try setting the health at the top of the when I start as a Clone script and see if that works The Health Variable is not for all sprites, but every time I shoot the enemy, it dies in one shot, even though it's not supposed to. I know I but the health variable set to one somewhere in the script, but when I shoot the enemy that isn't supposed to have 1 health, it dies immediately, therefore implying that only the 1 health enemy would work. When shooting it.
- MrKingofScratch
- Scratcher
100+ posts
Cloned Enemies with individual health.
First of all, instead of using
Here are a few ideas to solve your issue with enemies dying in one hit:
- make sure that the Shot Power variable is set to the right amount
- make sure the the health variable for enemies is set to the right amount before the clones are created.
- Check to make sure that there aren't multiple clones of the Shoot Type sprite hitting the enemy at once
- If you have any broadcasts that mess with variables, know that every clone will run the broadcast script (so if you have created 10 clones and run a broadcast with a script that decreases a health variable by one, it will actually be decreased by 11 because the main sprite and all of the clones will run it)
- Check that you don't have any other scripts in the sprite killing the enemies or changing health values
It would be very helpful if you shared the project and provided a link.
<(health) < [0]>you should use
<not <(health) > [0]>>This will make it so that the enemy can't live on 0 hp.
Here are a few ideas to solve your issue with enemies dying in one hit:
- make sure that the Shot Power variable is set to the right amount
- make sure the the health variable for enemies is set to the right amount before the clones are created.
- Check to make sure that there aren't multiple clones of the Shoot Type sprite hitting the enemy at once
- If you have any broadcasts that mess with variables, know that every clone will run the broadcast script (so if you have created 10 clones and run a broadcast with a script that decreases a health variable by one, it will actually be decreased by 11 because the main sprite and all of the clones will run it)
- Check that you don't have any other scripts in the sprite killing the enemies or changing health values
It would be very helpful if you shared the project and provided a link.
Last edited by MrKingofScratch (March 31, 2024 23:51:58)
- ret12345647
- Scratcher
20 posts
Cloned Enemies with individual health.
https://scratch.mit.edu/projects/986595721/ Here's the project. The code is in the enemy sprite.
Last edited by ret12345647 (April 1, 2024 00:00:47)
- MrKingofScratch
- Scratcher
100+ posts
Cloned Enemies with individual health.
Try deleting the bullet clone when it touches an enemy, the enemies might be taking damage multiple times from the same bullet!
- ret12345647
- Scratcher
20 posts
Cloned Enemies with individual health.
I'll try that!
IT WORKED! THANK YOU!!!
IT WORKED! THANK YOU!!!
forever
say [Thanks!!!!]
end
Last edited by ret12345647 (April 1, 2024 00:30:53)
- Discussion Forums
- » Help with Scripts
- » Cloned Enemies with individual health.