For some reason when I use a weapon using one of my attributes I made, it toggles the attribute on everyone on the server.
Code:
#pragma semicolon 1
#include <tf2_stocks>
#include <sdkhooks>
#include <customweaponstf>
#define PLUGIN_VERSION "beta 2"
public Plugin:myinfo = {
name = "Custom Attributes",
author = "Bitl",
description = "Attributes for Custom Weapons",
version = PLUGIN_VERSION,
url = ""
};
new bool:HasAttribute[2049];
new bool:PowerPlayOnKill[2049];
new bool:BloodAndJarate[2049];
new bool:BloodAndMilk[2049];
new bool:PowerPlayOP[2049];
new bool:SkeleOnKill[2049];
new bool:HelpfulSkele[2049];
new Float:g_pos[3];
public OnPluginStart()
{
HookEvent("player_death", event_PlayerDeath);
//HookEvent("player_spawn", event_PlayerSpawn);
for (new i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i)) continue;
OnClientPutInServer(i);
}
}
public OnClientPutInServer(client)
{
//SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
SDKHook(client, SDKHook_OnTakeDamagePost, OnTakeDamagePost);
//SDKHook(client, SDKHook_TraceAttack, OnTraceAttack);
}
//Attributes In This Plugin:
//
//"powerplay on kill five secs"
//If you kill a player, you get powerplay for 5 seconds.
//
//"jarate and bleed"
//If you hit a player, they will get covered in jarate and bleed for 15 seconds.
//
//"mad milk and bleed"
//If you hit a player, they will get covered in mad milk and bleed for 15 seconds.
//
//"powerplay on kill op"
//If you kill a player, you get powerplay permanently for your current life.
//
//"skeleton on kill"
//If you kill a player, a skeleton pops out of your victim's body and KILLS YOU for 25 seconds.
//
//"friendly skeleton on kill"
//If you press ATTACK3, a skeleton spawns where you look and HELPS YOU KILL for 25 seconds.
public Action:CustomWeaponsTF_OnAddAttribute(weapon, client, const String:attrib[], const String:plugin[], const String:value[])
{
if (!StrEqual(plugin, "customattributes")) return Plugin_Continue;
new Action:action;
if (StrEqual(attrib, "powerplay on kill five secs"))
{
PowerPlayOnKill[weapon] = true;
action = Plugin_Handled;
}
else if (StrEqual(attrib, "jarate and bleed"))
{
BloodAndJarate[weapon] = true;
action = Plugin_Handled;
}
else if (StrEqual(attrib, "mad milk and bleed"))
{
BloodAndMilk[weapon] = true;
action = Plugin_Handled;
}
else if (StrEqual(attrib, "powerplay on kill op"))
{
PowerPlayOP[weapon] = true;
action = Plugin_Handled;
}
else if (StrEqual(attrib, "skeleton on kill"))
{
SkeleOnKill[weapon] = true;
action = Plugin_Handled;
}
else if (StrEqual(attrib, "friendly skeleton on kill"))
{
HelpfulSkele[weapon] = true;
action = Plugin_Handled;
}
if (!HasAttribute[weapon]) HasAttribute[weapon] = bool:action;
return action;
}
// ^ Remember, this is called once for every custom attribute (attempted to be) applied!
public event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "attacker"));
new victim = GetClientOfUserId(GetEventInt(event, "userid"));
if (!IsClientInGame(client)) return;
if (!IsPlayerAlive(client)) return;
new wep = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if (wep == -1) return;
if (!HasAttribute[wep]) return;
if (wep > -1)
{
if (HasAttribute[wep])
{
if (PowerPlayOnKill[wep])
{
CreateTimer(0.1, Timer_PowerPlay, client);
}
if (PowerPlayOP[wep])
{
TF2_SetPlayerPowerPlay(client, true);
}
if (SkeleOnKill[wep])
{
SpawnSkeleton(victim);
}
if (HelpfulSkele[wep])
{
SpawnSkeletonAtClientPoint(client);
}
}
}
}
//public event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
//{
//new client = GetClientOfUserId(GetEventInt(event, "userid"));
//if (!IsClientInGame(client)) return;
//if (!IsPlayerAlive(client)) return;
//new wep = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
//if (wep == -1) return;
//if (!HasAttribute[wep]) return;
//}
public OnTakeDamagePost(victim, attacker, inflictor, Float:damage, damagetype, weapon, const Float:damageForce[3], const Float:damagePosition[3])
{
if (attacker <= 0 || attacker > MaxClients) return;
if (weapon == -1) return;
if (!HasAttribute[weapon]) return;
if (weapon > -1)
{
if (HasAttribute[weapon])
{
if (BloodAndJarate[weapon] && victim != attacker && HasAttribute[weapon])
{
TF2_MakeBleed(victim, attacker, 15.0);
TF2_AddCondition(victim, TFCond_Jarated, 15.0);
}
if (BloodAndMilk[weapon] && victim != attacker && HasAttribute[weapon])
{
TF2_MakeBleed(victim, attacker, 15.0);
TF2_AddCondition(victim, TFCond_Milked, 15.0);
}
}
}
}
public Action:Timer_PowerPlay(Handle:timer, any:client)
{
TF2_SetPlayerPowerPlay(client, true);
CreateTimer(5.0, Timer_PowerPlayEnd, client);
return Plugin_Stop;
}
public Action:Timer_PowerPlayEnd(Handle:timer, any:client)
{
TF2_SetPlayerPowerPlay(client, false);
return Plugin_Stop;
}
SpawnSkeletonAtClientPoint(client)
{
if(!SetTeleportEndPoint(client))
{
PrintToChat(client, "[SM] Could not find spawn point.");
}
if(GetEntityCount() >= GetMaxEntities()-32)
{
PrintToChat(client, "[SM] Entity limit is reached. Can't spawn anymore pumpkin lords. Change maps.");
}
new entity = CreateEntityByName("tf_zombie");
if(IsValidEntity(entity))
{
g_pos[2] -= 10.0;
TeleportEntity(entity, g_pos, NULL_VECTOR, NULL_VECTOR);
SetEntProp(entity, Prop_Send, "m_iTeamNum", GetClientTeam(client));
SetEntProp(entity, Prop_Send, "m_nSkin", GetClientTeam(client) - 2);
CreateTimer(1.0, Timer_SpawnDelay, entity);
}
}
SpawnSkeleton(client)
{
new Float:vecOrigin[3];
new Float:vecAngles[3];
GetClientAbsOrigin(client, vecOrigin);
new entity = CreateEntityByName("tf_zombie"); // Skeleton
if(IsValidEntity(entity))
{
vecAngles[1] = GetRandomFloat(1.0, 360.0);
TeleportEntity(entity, vecOrigin, vecAngles, NULL_VECTOR);
SetEntProp(entity, Prop_Send, "m_iTeamNum", GetClientTeam(client));
SetEntProp(entity, Prop_Send, "m_nSkin", GetClientTeam(client) - 2);
CreateTimer(1.0, Timer_SpawnDelay, entity);
}
}
public Action:Timer_SpawnDelay(Handle:timer, any:entity)
{
DispatchSpawn(entity);
CreateTimer(24.0, Timer_KillSkeleton, entity);
return Plugin_Stop;
}
public Action:Timer_KillSkeleton(Handle:timer, any:entity)
{
if(IsValidEntity(entity))
{
AcceptEntityInput(entity, "Kill");
}
return Plugin_Stop;
}
stock bool:IsValidClient(client)
{
if (client <= 0 || client > MaxClients) return false;
if (!IsClientInGame(client)) return false;
if (IsClientSourceTV(client) || IsClientReplay(client)) return false;
return true;
}
SetTeleportEndPoint(client)
{
decl Float:vAngles[3];
decl Float:vOrigin[3];
decl Float:vBuffer[3];
decl Float:vStart[3];
decl Float:Distance;
GetClientEyePosition(client,vOrigin);
GetClientEyeAngles(client, vAngles);
//get endpoint for teleport
new Handle:trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer);
if(TR_DidHit(trace))
{
TR_GetEndPosition(vStart, trace);
GetVectorDistance(vOrigin, vStart, false);
Distance = -35.0;
GetAngleVectors(vAngles, vBuffer, NULL_VECTOR, NULL_VECTOR);
g_pos[0] = vStart[0] + (vBuffer[0]*Distance);
g_pos[1] = vStart[1] + (vBuffer[1]*Distance);
g_pos[2] = vStart[2] + (vBuffer[2]*Distance);
}
else
{
CloseHandle(trace);
return false;
}
CloseHandle(trace);
return true;
}
public bool:TraceEntityFilterPlayer(entity, contentsMask)
{
return entity > GetMaxClients() || !entity;
}