Skip to content

Commit

Permalink
merging remote rocket fix
Browse files Browse the repository at this point in the history
  • Loading branch information
higps committed Feb 7, 2024
1 parent 0594a3d commit 08e7bd7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 80 deletions.
2 changes: 1 addition & 1 deletion cfg/robots/paid_damage_rockets_soldier_kappy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
}
"custom_attributes_weapon"
{
// "custom buff type" "rocket-aiming-control"
"custom buff type" "rocket-aiming-control"
"rocket control buff turn rate" "0.045"
}
}
Expand Down
141 changes: 62 additions & 79 deletions mm_attribute_remote_control_rockets.sp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ int RocketID[MAXPLAYERS+1];
float LastControlTime[MAXPLAYERS+1] = {-1.0, ...};

//rocket settings
float g_rocketTurnRate;
int g_rocketAimType;
float g_rocketTurnRate = 180.0;
int g_rocketAimType = 1;


bool HasStat(int client)
Expand All @@ -42,14 +42,16 @@ bool HasStat(int client)
}

char stat_buffer[256];
if (!TF2CustAttr_GetString(Weapon1, "mouse-control-rocket", stat_buffer, sizeof(stat_buffer))) {
return false;
if (!TF2CustAttr_GetString(Weapon1, "mouse-control-rocket", stat_buffer, sizeof(stat_buffer)))
{
return false;
}
g_rocketTurnRate = ReadFloatVar(stat_buffer, "turnspeed", 1.0);
g_rocketTurnRate = ReadFloatVar(stat_buffer, "turnspeed", 180.0);
g_rocketAimType = ReadIntVar(stat_buffer, "aim-mode", 1);
// g_UpdateHitBox = ReadIntVar(stat_buffer, "update-hitbox", 1);
// g_bmod_disciplinary = ReadIntVar(stat_buffer, "bmod-disciplinary", 0);
// PlayerControlRockets[client] = false;

return true;
}

Expand Down Expand Up @@ -80,13 +82,12 @@ public Plugin MyInfo =

public void OnPluginStart()
{


//Events

HookEvent("player_death", PlayerDeath);
HookEvent("object_deflected", OnAirblasted);

// RegConsoleCmd("sm_rc", CmdControl);
//RegConsoleCmd("sm_rc", CmdControl);

for (int client = 1; client <= MaxClients; client++)
{
Expand All @@ -97,30 +98,39 @@ public void OnPluginStart()
}
}

public void OnMapStart()
{

}
//Action CmdControl(int client, int args)
//{
// ToggleControl[client] = !ToggleControl[client];
// PrintToChat(client, "RC Rockets: %s", ToggleControl[client] ? "True" : "False");
//
// return Plugin_Handled;
//}

public Action PlayerDeath(Handle event, const char[] name, bool dBroad)
Action PlayerDeath(Handle event, const char[] name, bool dBroad)
{
int victim = GetClientOfUserId(GetEventInt(event, "userid"));
if (ControllingRocket[victim])
{
SetPlayerRCMode(victim, false);
}

return Plugin_Continue;
}

// public Action PlayerJoinClass(int client, const char[] command, int argc)
// {
// if (TF2_GetPlayerClass(client) == TFClass_Soldier && PlayerControlRockets[client])
// {
// PlayerControlRockets[client] = false;
// PrintToChat(client, "[SM] Disabling RC rockets due to class change.");
// }
// return Plugin_Continue;
// }
Action OnAirblasted(Event event, const char[] name, bool dBroad)
{
int entity = event.GetInt("object_entindex");
if (IsValidEdict(entity) && entity > 0 && RocketOverride[entity])
{
int owner = GetClientOfUserId(event.GetInt("ownerid"));
if (owner > 0 && owner <= MaxClients && IsClientInGame(owner))
{
SetPlayerRCMode(owner, false);
}
}

return Plugin_Handled;
}

public void OnClientPostAdminCheck(int client)
{
Expand All @@ -130,25 +140,11 @@ public void OnClientPostAdminCheck(int client)
RocketID[client] = INVALID_ENT_REFERENCE;
}

// Action CmdControl(int client)
// {
// if (TF2_GetPlayerClass(client) != TFClass_Soldier)
// {
// PrintToChat(client, "[SM] You must be a soldier to use this attribute!");
// }
// else
// {
// PlayerControlRockets[client] = !PlayerControlRockets[client];
// }
// }

public void OnEntityCreated(int entity, const char[] classname)
{
if (!(StrContains(classname, "tf_projectile_rocket")))
{
//SDKHook(entity, SDKHook_SpawnPost, OnRocketSpawned);
RequestFrame(OnRocketSpawned, entity);
SDKHook(entity, SDKHook_Touch, OnRocketEnd);
}
}

Expand All @@ -157,10 +153,24 @@ public void OnEntityDestroyed(int entity)
if (entity <= 0 || entity > 2048) return; //prevent ent refs being used
if (IsValidEntity(entity))
{
if (RocketOverride[entity])
{
DisableRocket(entity);
}
RocketOverride[entity] = false;
}
}

void DisableRocket(int entity)
{
int owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
if (owner > 0 && owner <= MaxClients && IsClientInGame(owner))
{
RocketID[owner] = INVALID_ENT_REFERENCE;
SetPlayerRCMode(owner, false);
}
}

public void OnRocketSpawned(int rocket)
{
int owner = GetEntPropEnt(rocket, Prop_Send, "m_hOwnerEntity");
Expand All @@ -184,39 +194,13 @@ void SetPlayerRCMode(int client, bool status)
{
SetClientViewEntity(client, client);
SetEntityMoveType(client, MOVETYPE_WALK);
RocketID[client] = INVALID_ENT_REFERENCE;
}
}

//Make sure to take the player out of the remote control state upon a rocket hitting something
public Action OnRocketEnd(int rocket, int victim)
{
if (RocketOverride[rocket])
{
int owner = GetEntPropEnt(rocket, Prop_Send, "m_hOwnerEntity");
if (!IsValidClient(victim))
{
char classname[64];
GetEntityClassname(victim, classname, sizeof classname);
if (victim == 0 || !StrContains(classname, "prop_", false) || !StrContains(classname, "obj_", false) || !StrContains(classname, "func_door")) //solid props
{
SetPlayerRCMode(owner, false);
}
}
else if (IsValidClient(victim))
int rocket = RocketID[client];
if (rocket > 0 && IsValidEdict(rocket))
{
bool sameTeam = (GetClientTeam(owner) == GetClientTeam(victim)); //check if the player we hit is an enemy player
if (sameTeam)
{
//return Plugin_Handled; //pass through teammates to prevent control being lost on player overlap - DOESNT WORK NEED A BETTER METHOD
}
else
{
SetPlayerRCMode(owner, false);
}
RocketOverride[rocket] = false;
}
RocketID[client] = INVALID_ENT_REFERENCE;
}
return Plugin_Continue;
}

bool g_PushButton[MAXPLAYERS + 1] = {false, ...};
Expand All @@ -237,18 +221,20 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
PlayerControlRockets[client] = true;

PrintCenterText(client, "REMOTE ROCKET CONTROL: ON");
}
else if (PlayerControlRockets[client] == true /*&& ControllingRocket[client] == false*/)
{
PlayerControlRockets[client] = false;

if (ControllingRocket[client])
{
SetPlayerRCMode(client, false);
}

}else if (PlayerControlRockets[client] == true && ControllingRocket[client] == false) {

PlayerControlRockets[client] = false;

PrintCenterText(client, "REMOTE ROCKET CONTROL: OFF");
PrintCenterText(client, "REMOTE ROCKET CONTROL: OFF");
}
g_PushButton[client] = true;
CreateTimer(0.2, Button_Reset, client);


}

if (HasStat(client) && buttons & (IN_ATTACK3|IN_USE) && !g_PushButton[client])
Expand All @@ -259,19 +245,16 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3

SetVariantInt(1);
AcceptEntityInput(client, "SetForcedTauntCam");
}else if (g_toggethirdperson[client] == true && ControllingRocket[client] == false) {

}
else if (g_toggethirdperson[client] == true && ControllingRocket[client] == false)
{
g_toggethirdperson[client] = false;



SetVariantInt(0);
AcceptEntityInput(client, "SetForcedTauntCam");
}
g_PushButton[client] = true;
CreateTimer(0.2, Button_Reset, client);


}

if (HasStat(client) && IsValidRocket(RocketID[client]))
Expand Down

0 comments on commit 08e7bd7

Please sign in to comment.