Skip to main content
LadyMo218
Up and Coming
March 13, 2025
Question

Scripting a Grenade - Codeblocks

If i put a script on a grenade and connect to the trigger that when entered by a player (target player) would this script work?

(I have a playerManager script that this would be linked to)

Thanks in advance

16 replies

LadyMo218
LadyMo218Author
Up and Coming
March 13, 2025

Looking back over, this wouldnt work. The trigger would become enabled but it would still be sitting under the world somewhere and never triggering the explosion because it wouldn't be receiving a player.  So what about this:

 

gausroth
Honored Contributor
March 14, 2025

There is a chance that the grenade will still be moving after detonate has been called. But this seems to be more like a mine than a grenade. I would call the grenade event right after the detonate and you don't even need the trigger.

GitHub: https://github.com/Gausroth/HorizonWorldsTutorials.git Discord: https://discord.gg/hNyDQwdw4N YouTube: https://www.youtube.com/@GausRothTutorials
LadyMo218
LadyMo218Author
Up and Coming
March 14, 2025

So would I move β€œconnect grenadeTrig” event down under when β€œdetonate is received” rather than when world is started?

Meta Employee
March 14, 2025

In Desert Sand PVP I run a While loop on detonation to check the distance from each player's position in the world, if their position is within the range of the blast, I send the applyDamage event to that player. This also gives you flexibility to set different distances to be able to apply different amounts of damage depending on how close to the blast they are adding a bit more realism.

gausroth
Honored Contributor
March 14, 2025

Curious to what your using as the check in the while loop. 

GitHub: https://github.com/Gausroth/HorizonWorldsTutorials.git Discord: https://discord.gg/hNyDQwdw4N YouTube: https://www.youtube.com/@GausRothTutorials
LadyMo218
LadyMo218Author
Up and Coming
March 14, 2025

You mean in my player manager? 

LadyMo218
LadyMo218Author
Up and Coming
March 14, 2025

Lol of course you both would suggest something that’s above my pay grade πŸ˜†πŸ˜†πŸ˜†

gausroth
Honored Contributor
March 14, 2025

I'm thinking it would look something like this. 

 

 

GitHub: https://github.com/Gausroth/HorizonWorldsTutorials.git Discord: https://discord.gg/hNyDQwdw4N YouTube: https://www.youtube.com/@GausRothTutorials
Meta Employee
March 14, 2025

I apologize for not being thorough, I thought it was implied that I was iterating through the list. I was answering your question as to what the check was within the while loop. You are absolutely correct, you must use an iterator. I also scripted this 2 years ago and those while loops are probably pretty bulky. I try not to have too many lines in there which is why I just check for the distance from the player to the blast position and send the event out to calculate appropriate damage in the subsequent event.

LadyMo218
LadyMo218Author
Up and Coming
March 14, 2025

🀯