You're welcome! Here's a slightly different version that doesn't require TF2Items.
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <tf2_stocks>
#define PLUGIN_VERSION "1.1"
#define MAGIC "vo/halloween_merasmus/sf12_staff_magic13.mp3"
public Plugin:myinfo =
{
name = "Spellbook",
author = "PC Gamer",
description = "Give Spellbook with Spells",
version = PLUGIN_VERSION,
url = "www.sourcemod.com"
}
Handle g_hWearableEquip;
public OnPluginStart()
{
LoadTranslations("common.phrases");
RegAdminCmd("sm_spellbook", Command_nobook, ADMFLAG_SLAY, "Give Spells");
GameData hTF2 = new GameData("sm-tf2.games"); // sourcemod's tf2 gamedata
if (!hTF2)
SetFailState("This plugin is designed for a TF2 dedicated server only.");
StartPrepSDKCall(SDKCall_Player);
PrepSDKCall_SetVirtual(hTF2.GetOffset("RemoveWearable") - 1); // EquipWearable offset is always behind RemoveWearable, subtract its value by 1
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
g_hWearableEquip = EndPrepSDKCall();
if (!g_hWearableEquip)
SetFailState("Failed to create call: CBasePlayer::EquipWearable");
delete hTF2;
}
public OnMapStart()
{
PrecacheSound(MAGIC, true);
}
public Action:Command_nobook(client, args)
{
decl String:arg1[32];
if (args < 1)
{
arg1 = "@me";
}
else GetCmdArg(1, arg1, sizeof(arg1));
new String:target_name[MAX_TARGET_LENGTH];
new target_list[MAXPLAYERS], target_count;
new bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg1,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_ALIVE|(args < 1 ? COMMAND_FILTER_NO_IMMUNITY : 0),
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
for (new i = 0; i < target_count; i++)
{
forceSpellbook(target_list[i]);
SetSpell2(target_list[i], 0, 10);
EmitSoundToClient(target_list[i],MAGIC);
PrintToChat(target_list[i], "You received 10 Fireball Spells. Use 'H' key to cast.");
}
return Plugin_Handled;
}
stock forceSpellbook(client)
{
TF2_RemoveWeaponSlot(client, 10);
CreateHat(client, 1132, 100, 6); //Spellbook
TF2_RegeneratePlayer(client);
}
SetSpell2(client, spell, uses)
{
new ent = GetSpellBook(client);
if(!IsValidEntity(ent)) return;
SetEntProp(ent, Prop_Send, "m_iSelectedSpellIndex", spell);
SetEntProp(ent, Prop_Send, "m_iSpellCharges", uses);
}
GetSpellBook(client)
{
new entity = -1;
while((entity = FindEntityByClassname(entity, "tf_weapon_spellbook")) != INVALID_ENT_REFERENCE)
{
if(GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity") == client) return entity;
}
return -1;
}
bool CreateHat(int client, int itemindex, int level, int quality)
{
int hat = CreateEntityByName("tf_wearable");
if (!IsValidEntity(hat))
{
return false;
}
char entclass[64];
GetEntityNetClass(hat, entclass, sizeof(entclass));
SetEntData(hat, FindSendPropInfo(entclass, "m_iItemDefinitionIndex"), itemindex);
SetEntData(hat, FindSendPropInfo(entclass, "m_bInitialized"), 1);
SetEntData(hat, FindSendPropInfo(entclass, "m_iEntityLevel"), level);
SetEntData(hat, FindSendPropInfo(entclass, "m_iEntityQuality"), quality);
if (level)
{
SetEntData(hat, FindSendPropInfo(entclass, "m_iEntityLevel"), level);
}
else
{
SetEntData(hat, FindSendPropInfo(entclass, "m_iEntityLevel"), GetRandomInt(1,100));
}
DispatchSpawn(hat);
SDKCall(g_hWearableEquip, client, hat);
return true;
}