Last active
May 16, 2017 13:49
-
-
Save sigsegv-mvm/2fce605f5e5ee4273611 to your computer and use it in GitHub Desktop.
Automatic Bananaifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma semicolon 1 | |
#include <sourcemod> | |
#include <sdktools> | |
#include <sdkhooks> | |
#include <tf2> | |
#include <tf2_stocks> | |
#include <tf2items> | |
#include <tf2wearables> | |
#include <equipwearable> | |
public Plugin:myinfo = | |
{ | |
name = "[TF2] Automatic Bananaifier", | |
author = "sigsegv", | |
description = "Forcibly replaces all hats with bananas", | |
version = "1.0", | |
url = "" | |
}; | |
new DEFIDX_BANANA = 30643; | |
public OnPluginStart() | |
{ | |
//PrintToServer("Banana: OnPluginStart"); | |
HookEvent("player_spawn", Hook_PlayerSpawn, EventHookMode_Post); | |
HookEvent("post_inventory_application", Hook_PostInventoryApplication, EventHookMode_Post); | |
//RegAdminCmd("banana", Cmd_Banana, 0); | |
} | |
public Hook_PlayerSpawn(Handle:event, const String:name[], bool:bDontBroadcast) | |
{ | |
new client = GetClientOfUserId(GetEventInt(event, "userid")); | |
//PrintToServer("Banana: Hook_PlayerSpawn %L", client); | |
if (IsClientInGame(client)) { | |
Bananaify(client); | |
} | |
CreateTimer(0.015, Timer_Bananaify, client); | |
} | |
public Hook_PostInventoryApplication(Handle:event, const String:name[], bool:bDontBroadcast) | |
{ | |
new client = GetClientOfUserId(GetEventInt(event, "userid")); | |
//PrintToServer("Banana: Hook_PostInventoryApplication %L", client); | |
if (IsClientInGame(client)) { | |
Bananaify(client); | |
} | |
CreateTimer(0.015, Timer_Bananaify, client); | |
} | |
public Action:Timer_Bananaify(Handle:timer, client) | |
{ | |
//PrintToServer("Banana: Timer_Bananaify %L", client); | |
if (IsClientInGame(client)) { | |
Bananaify(client); | |
} | |
return Plugin_Stop; | |
} | |
public Action:TF2Items_OnGiveNamedItem(client, String:classname[], itemDefinitionIndex, &Handle:hItem) | |
{ | |
//PrintToServer("Banana: OnGiveNamedItem %L", client); | |
/* don't allow hats other than the banana to be equipped */ | |
if (strcmp(classname, "tf_wearable", true) == 0 && | |
itemDefinitionIndex != DEFIDX_BANANA) { | |
//PrintToServer("HANDLED %s %d", classname, itemDefinitionIndex); | |
return Plugin_Handled; | |
} else { | |
//PrintToServer("CONTINUE %s %d", classname, itemDefinitionIndex); | |
return Plugin_Continue; | |
} | |
} | |
public TF2Items_OnGiveNamedItem_Post(client, String:classname[], itemDefinitionIndex, itemLevel, itemQuality, entityIndex) | |
{ | |
//PrintToServer("Banana: OnGiveNamedItem_Post %L", client); | |
if (IsClientInGame(client) && itemDefinitionIndex != 30643) { | |
Bananaify(client); | |
} | |
} | |
/*public Action:Cmd_Banana(client, args) | |
{ | |
PrintToServer("Banana: command called by %L", | |
client); | |
for (new i = 1; i <= MaxClients; ++i) { | |
if (IsClientInGame(i)) { | |
Bananaify(i); | |
} | |
} | |
return Plugin_Continue; | |
}*/ | |
public Bananaify(client) | |
{ | |
PrintToServer("Bananaify(%L)", | |
client); | |
TF2_RemoveAllWearables(client); | |
new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL); | |
TF2Items_SetClassname(item, "tf_wearable"); | |
TF2Items_SetItemIndex(item, DEFIDX_BANANA); | |
TF2Items_SetQuality(item, 6); | |
TF2Items_SetLevel(item, 1); | |
TF2Items_SetNumAttributes(item, 0); | |
new hat = TF2Items_GiveNamedItem(client, item); | |
EquipPlayerWearable(client, hat); | |
CloseHandle(item); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment