Raised This Month: $ Target: $400
 0% 

Spawn a rocket on button press


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
walabulu4
Junior Member
Join Date: Sep 2019
Old 10-10-2019 , 01:34   Re: Spawn a rocket on button press
Reply With Quote #1

Quote:
Originally Posted by PC Gamer View Post
I managed to use these tips to spawn a rocket when a player calls for a medic. However, it causes an explosion at the client in addition to firing the rocket.

How can I fire the rocket without causing an explosion at the client?

Code:
Code:
#pragma semicolon 1
#include <TF2_stocks> 

#define RSOUND "weapons/rocket_blackbox_shoot.wav"

public Plugin myinfo = 
{
	name = "The Medic Rocket",
	author = "PC Gamer",
	description = "Shoots Rocket when you call for Medic",
	version = "PLUGIN_VERSION 1.0",
	url = "www.sourcemod.com"	
}

public OnPluginStart()
{ 
	AddNormalSoundHook(GamerSH);
}

public OnMapStart()
{
	PrecacheSound(RSOUND, true);
}

public Action:GamerSH(clients[64], &numClients, String:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
{
	if (!IsValidClient(entity)) return Plugin_Continue;
	if (StrContains(sample, "_medic0", false) != -1)
	{
		sample = RSOUND;

		decl Float:ang[3];
		decl Float:pos[3];
		GetClientEyePosition(entity, pos);
		GetClientEyeAngles(entity, ang);		
		new RTeam = GetClientTeam(entity);
		FireTeamRocket(pos, ang, entity, RTeam);

		return Plugin_Changed;
	}
	return Plugin_Changed;
}

stock FireTeamRocket(Float:vPos[3], Float:vAng[3], iOwner = 0, iTeam = 0, Float:flSpeed = 1100.0, Float:flDamage = 90.0, bool:bCrit = false, iWeapon = -1)
{
	new iRocket = CreateEntityByName("tf_projectile_rocket");
	if (IsValidEntity(iRocket))
	{
		decl Float:vVel[3]; // Determine velocity based on given speed/angle
		GetAngleVectors(vAng, vVel, NULL_VECTOR, NULL_VECTOR);
		ScaleVector(vVel, flSpeed);
		
		SetEntProp(iRocket, Prop_Send, "m_bCritical", bCrit);

		SetRocketDamage(iRocket, flDamage);

		SetEntProp(iRocket, Prop_Send, "m_nSkin", (0, iTeam - 2)); // 0 = RED 1 = BLU
		SetEntProp(iRocket, Prop_Send, "m_iTeamNum", iTeam, 1);
		SetVariantInt(iTeam);
		AcceptEntityInput(iRocket, "TeamNum");
		SetVariantInt(iTeam);
		AcceptEntityInput(iRocket, "SetTeam");

		if (iOwner != -1)
		{
			SetEntPropEnt(iRocket, Prop_Send, "m_hOwnerEntity", iOwner);
		}
		
		TeleportEntity(iRocket, vPos, vAng, vVel);
		DispatchSpawn(iRocket);
		
		if (iWeapon != -1)
		{
			SetEntPropEnt(iRocket, Prop_Send, "m_hOriginalLauncher", iWeapon); // GetEntPropEnt(baseRocket, Prop_Send, "m_hOriginalLauncher")
			SetEntPropEnt(iRocket, Prop_Send, "m_hLauncher", iWeapon); // GetEntPropEnt(baseRocket, Prop_Send, "m_hLauncher")
		}
		
		return iRocket;
	}
	return -1;
}

static s_iRocketDmgOffset = -1;

stock SetRocketDamage(iRocket, Float:flDamage)
{
	if (s_iRocketDmgOffset == -1)
	{
		s_iRocketDmgOffset = FindSendPropInfo("CTFProjectile_Rocket", "m_iDeflected") + 4; // Credit to voogru
	}
	SetEntDataFloat(iRocket, s_iRocketDmgOffset, flDamage, true);
}

stock Float:GetRocketDamage(iRocket)
{
	if (s_iRocketDmgOffset == -1)
	{
		s_iRocketDmgOffset = FindSendPropOffs("CTFProjectile_Rocket", "m_iDeflected") + 4; // Credit to voogru
	}
	return GetEntDataFloat(iRocket, s_iRocketDmgOffset);
}  

stock bool:IsValidClient(client)
{
	if (client <= 0) return false;
	if (client > MaxClients) return false;
	return IsClientInGame(client);
}
On messing arround with it further, when I put a debug PrintToServer in the FireTeamRocket Function it prints like 5 or 6 times when I hit E. I wonder if that is causing the issue?

EDIT: I am dumb, I was testing with bots and each bot caused an additional print string to print. After kicking them the script seems to work mostly fine. I don't get hurt by an explosion before the rocket hits something.

Last edited by walabulu4; 10-10-2019 at 01:39.
walabulu4 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 21:20.


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