Edit: I found this
http://forums.alliedmods.net/showpos...08&postcount=9 but I cannot get it to work.
Edit Edit: From code that I've found and threw together I have made what I was looking for.
Here it is.
To use friendly: sm_friendly (toggles)
Cvar to enable/disable blocked weapons: sm_friendly_blockweps 1/0 (enable/disable) default: 0 (disabled)
Cvar to remember friendly after you die/switch classes: sm_friendly_remember 1/0 (enable/disable) default 0: (disabled)
To use this you have to have admin flag "d" (ADMFLAG_BAN)
This plugin does the following:
Enables Buddha mode
Gives you immunity to sentries (they cannot target you)
Stops damage you do to others
Stops damage done to buildings (sentries, dispensers, teleporters)
Blocks the following weapons if cvar is enabled: tf_weapon_flamethrower(prevent airblasting non friendlies) tf_weapon_medigun(prevent healing non friendlies) tf_weapon_builder(prevent buliding stuff/sappers) tf_weapon_bonesaw(prevent performing ubersaw taunt on non friendlies) tf_weapon_compound_bow(prevent performing huntsman taunt on non friendlies) tf_weapon_bat_wood(prevent using sandman ball on non friendlies) tf_weapon_jar(prevent throwing piss on non friendlies) tf_weapon_jar_milk(prevent throwing milk on non friendlies) tf_weapon_fireaxe(prevent destroying sappers(homewrecker)) tf_weapon_lunchbox(prevent healing non friendlies) tf_weapon_crossbow(prevent healing non friendlies)
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <sdkhooks>
new bool:ClientIsBuddah[MAXPLAYERS+1] = {false, ...};
new Handle:hBlockWeps = INVALID_HANDLE;
new Handle:hRemember = INVALID_HANDLE;
public OnPluginStart()
{
for(new i=1; i<MAXPLAYERS+1; i++)
ClientIsBuddah[i] = false;
hBlockWeps = CreateConVar("sm_friendly_blockweps", "0", "Enable/Disable(1/0) Blocked Weapons", FCVAR_PLUGIN|FCVAR_NOTIFY);
hRemember = CreateConVar("sm_friendly_remember", "0", "Enable/Disable(1/0) Remember Friendly", FCVAR_PLUGIN|FCVAR_NOTIFY);
RegAdminCmd("sm_friendly", OnToggleFriendly, ADMFLAG_BAN, "Toggles friendly on/off");
HookEvent("player_death", OnPlayerDeath);
HookEvent("player_spawn", OnPlayerSpawned);
}
public Action:OnToggleFriendly(client, args)
{
if(IsPlayerAlive(client))
{
if (ClientIsBuddah[client] == true) {
ClientIsBuddah[client] = false;
new flags = GetEntityFlags(client)&~FL_NOTARGET;
SetEntityFlags(client, flags);
SetEntProp(client, Prop_Data, "m_takedamage", 2, 1);
ReplyToCommand(client, "Freindly mode disabled.");
}
else {
ClientIsBuddah[client] = true;
new flags = GetEntityFlags(client)|FL_NOTARGET;
SetEntityFlags(client, flags);
SetEntProp(client, Prop_Data, "m_takedamage", 1, 1);
ReplyToCommand(client, "Friendly mode enabled.");
}
}
else
ReplyToCommand(client, "You cannot apply !friendly when dead.");
return Plugin_Handled;
}
public OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(ClientIsBuddah[client] && !GetConVarBool(hRemember))
{
ClientIsBuddah[client] = false;
SetEntProp(client, Prop_Data, "m_takedamage", 2, 1);
new flags = GetEntityFlags(client)&~FL_NOTARGET;
SetEntityFlags(client, flags);
ReplyToCommand(client, "Freindly mode disabled on death.");
}
}
public OnPlayerSpawned(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(ClientIsBuddah[client] && GetConVarBool(hRemember))
{
ClientIsBuddah[client] = true;
new flags = GetEntityFlags(client)|FL_NOTARGET;
SetEntityFlags(client, flags);
SetEntProp(client, Prop_Data, "m_takedamage", 1, 1);
ReplyToCommand(client, "Friendly mode re-enabled on spawn.");
}
}
public OnEntityCreated(building, const String:classname[])
{
SDKHook(building, SDKHook_Spawn, OnEntitySpawned);
}
public OnEntitySpawned(building)
{
SDKHook(building, SDKHook_OnTakeDamage, BuildingTakeDamage);
}
public OnClientPutInServer(client)
{
ClientIsBuddah[client] = false;
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
}
public Action:OnWeaponSwitch(client, weapon)
{
decl String:sWeapon[32];
GetEdictClassname(weapon, sWeapon, sizeof(sWeapon));
if(ClientIsBuddah[client] && GetConVarBool(hBlockWeps))
{
if(StrEqual(sWeapon, "tf_weapon_flamethrower") || StrEqual(sWeapon, "tf_weapon_medigun") || StrEqual(sWeapon, "tf_weapon_builder") || StrEqual(sWeapon, "tf_weapon_bonesaw") || StrEqual(sWeapon, "tf_weapon_compound_bow") || StrEqual(sWeapon, "tf_weapon_bat_wood") || StrEqual(sWeapon, "tf_weapon_jar") || StrEqual(sWeapon, "tf_weapon_jar_milk") || StrEqual(sWeapon, "tf_weapon_fireaxe") || StrEqual(sWeapon, "tf_weapon_lunchbox") || StrEqual(sWeapon, "tf_weapon_crossbow"))
return Plugin_Handled;
}
return Plugin_Continue;
}
public Action:BuildingTakeDamage(building, &attacker, &inflictor, &Float:damage, &damagetype)
{
if (attacker < 1 || attacker > MaxClients)
{
return Plugin_Continue;
}
new String:classname[64];
GetEntityClassname(building, classname, sizeof(classname));
if (StrEqual(classname, "obj_sentrygun", false) || StrEqual(classname, "obj_dispenser", false) || StrEqual(classname, "obj_teleporter", false)) // make sure it is a building
{
if(ClientIsBuddah[attacker])
{
damage = 0;
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public Action:OnTakeDamage(client, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3])
{
decl String:weapon[32];
GetClientWeapon(attacker, weapon, sizeof(weapon));
if (attacker < 1 || attacker > MaxClients || client == attacker)
{
return Plugin_Continue;
}
if (ClientIsBuddah[attacker] || ClientIsBuddah[client])
{
damage = 0;
return Plugin_Handled;
}
return Plugin_Continue;
}
If you use this plugin please post here and let me know what you think
NOTE: You have to restart the current map after adding this plugin. You can also restart your server if you want.
Reason: SDKhooks checks damage by attaching a hook to a player when that player joins the game. If you start the plugin when the server/map is already going it will not attach the hook.
If you are curious about the plugin:
People like to be "friendly" on the server that I am an admin on. I have it set to admin flag "d" or the ban flag here because of possible abuse by non admins. People will find any way to abuse anything. (Ex: Turning friendly off right next to a player on the other team and killing them, then turning friendly back on right after they do so.)
They like to sit around and rocket jump or just sit and stare at each other (idk) and not kill or be killed by others. I have a lot of complaints about people killing other people that are trying to be friendly. This plugin should help the people that want to be friendly and still allow them to rocket jump/sticky jump without getting hurt from fall damage and at the same time not abusing buddha by killing other people while they are using it. I just felt like making this plugin for fun. I am happy with it. I used it on the server that I am an admin on for a little while but people can and will find any way to abuse it. So here is the code open for anyone to use/alter/do whatever they want with. Thanks for using/anything you do with it.