Raised This Month: $32 Target: $400
 8% 

Solved How do I prevent rockets from exploding when they collide with each other?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LordHotPocketHomicide
Member
Join Date: Aug 2016
Location: This Realm of Existence
Old 07-14-2021 , 09:11   How do I prevent rockets from exploding when they collide with each other?
Reply With Quote #1

Hey, folks. I've been working on a Freak Fortress ability; essentially, what I want it to do is rapidly fire various skulls (rockets with skull models, basically) with different effects in the user's aim direction, with some customizable spread, speed, etc. To do this, I have it setup to use a timer, which grabs a random float. If this float is less than the user's set chance to fire a particular skull, it fires that skull. This works fine when only one skull is fired, but what causes problems is when the plugin tries to spawn multiple skulls at once, as they all spawn on top of each other and instantly explode. I've tried messing with collision groups and spawning the skulls at random locations around the user, but neither have worked. Does anyone have any ideas? I've got the following code if anyone is interested:

Code:
public Action boner_AttemptCast(Handle boner_AttemptCast, int id) //Yes, boner, I am very mature.
{
	int client = GetClientOfUserId(id);
	
	if (IsValidMulti(client) && FF2_HasAbility(FF2_GetBossIndex(client), SPOOK, BONER) && boner_Active[client])
	{
		float chance = GetRandomFloat(0.0, 1.0);
		
		if (chance <= boner_RedChance[client])
		{
			boner_ShootSkull(client, 0);
		}
		
		if (chance <= boner_BlueChance[client])
		{
			boner_ShootSkull(client, 1);
		}
		
		if (chance <= boner_GreenChance[client])
		{
			boner_ShootSkull(client, 2);
		}
		
		if (chance <= boner_OrangeChance[client])
		{
			boner_ShootSkull(client, 3);
		}
		
		return Plugin_Continue;
	}
	
	KillTimer(boner_AttemptCast);
	return Plugin_Continue;
}

public void boner_ShootSkull(int caster, int mode)
{
	if (IsValidMulti(caster) && FF2_HasAbility(FF2_GetBossIndex(caster), SPOOK, BONER) && boner_Active[caster])
	{
		float vAngles[3]; 
		float vPosition[3];
		
		GetClientEyeAngles(caster, vAngles);
		GetClientEyePosition(caster, vPosition);
		
		//vPosition[1] += GetRandomFloat(-50.0, 50.0);
		//vPosition[2] += GetRandomFloat(-20.0, 20.0);
		
		new iTeam = GetClientTeam(caster);
		new skull = CreateEntityByName("tf_projectile_rocket");
		
		if(!IsValidEntity(skull))
		{
			return;
		}
	
		float vVelocity[3];
		float vBuffer[3];
		
		GetAngleVectors(vAngles, vBuffer, NULL_VECTOR, NULL_VECTOR);
		
		float rocketSpd = GetRandomFloat(boner_MinSpeed[caster], boner_MaxSpeed[caster]);
		vVelocity[0] = vBuffer[0]*rocketSpd;
		vVelocity[1] = vBuffer[1]*rocketSpd * float(GetRandomInt(-boner_Spread[caster], boner_Spread[caster]));
		vVelocity[2] = vBuffer[2]*rocketSpd * float(GetRandomInt(-boner_Spread[caster], boner_Spread[caster]));
		
		SetEntPropEnt(skull, Prop_Send, "m_hOwnerEntity", caster);
		SetEntProp(skull,    Prop_Send, "m_iTeamNum",     iTeam, 1);
		SetEntDataFloat(skull, FindSendPropInfo("CTFProjectile_Rocket", "m_iDeflected") + 4, boner_BaseDMG[caster], true);
		
		TeleportEntity(skull, vPosition, vAngles, NULL_VECTOR);
		SetVariantInt(iTeam);
		AcceptEntityInput(skull, "TeamNum", -1, -1, 0);
		SetVariantInt(iTeam);
		AcceptEntityInput(skull, "SetTeam", -1, -1, 0); 
		
		DispatchSpawn(skull);
			
		SetEntityModel(skull, SKULL_MODEL);	
		SetEntPropFloat(skull, Prop_Send, "m_flModelScale", 1.5); //Removing this doesn't solve the issue either.
		SetEntProp(skull,    Prop_Send, "m_nSkin", mode);
		
		TeleportEntity(skull, NULL_VECTOR, NULL_VECTOR, vVelocity);
	}
}
__________________
Professional retard. I might borrow some code, but I always try to give credit when I do! If you've noticed I've borrowed some of your code, and you have a problem with that, please add me on Steam and let me know so I can correct the problem as soon as possible!

Last edited by LordHotPocketHomicide; 07-15-2021 at 17:47.
LordHotPocketHomicide is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 07-15-2021 , 09:29   Re: How do I prevent rockets from exploding when they collide with each other?
Reply With Quote #2

Have you tried CollisionHook's CH_ShouldCollide?
__________________
MAGNAT2645 is offline
LordHotPocketHomicide
Member
Join Date: Aug 2016
Location: This Realm of Existence
Old 07-15-2021 , 17:47   Re: How do I prevent rockets from exploding when they collide with each other?
Reply With Quote #3

Quote:
Originally Posted by MAGNAT2645 View Post
Have you tried CollisionHook's CH_ShouldCollide?
Ahh, can't believe I forgot about that... Turns out my test server won't let me upload it though

In any case, I was able to solve the problem with just the standard SDKHook_ShouldCollide:

Code:
SDKHook(skull, SDKHook_ShouldCollide, skull_Collision);

public bool:skull_Collision( entity, collisiongroup, contentsmask, bool:result )
{
	if (IsValidEntity(entity))
	{
		result = false;
	}
	
	return result;
}
Thanks a bunch!
__________________
Professional retard. I might borrow some code, but I always try to give credit when I do! If you've noticed I've borrowed some of your code, and you have a problem with that, please add me on Steam and let me know so I can correct the problem as soon as possible!
LordHotPocketHomicide is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 07-16-2021 , 05:13   Re: How do I prevent rockets from exploding when they collide with each other?
Reply With Quote #4

AFAIK in this case projectile will also go through VPhysics entities (not only other projectiles).
__________________

Last edited by MAGNAT2645; 07-16-2021 at 05:14.
MAGNAT2645 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode