Quote:
Originally Posted by WildCard65
what's index set to?
|
Index used to refer to a weapon index I set for the program (Primary slot, 45 (Force-a-Nature) to be precise). It's been now rewritten for 3 slots for more testing purposes.
Quote:
Originally Posted by Powerlord
You're remembering to remove the previous weapon before giving them the new one?
|
Yes, in both my Post_Inventory_Application & Player_Spawn hooks. Here is the full code of the program, I apologize for not posting it sooner:
Spoiler
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <tf2items>
#include <tf2itemsinfo>
#include <tf2>
#include <tf2_stocks>
#define MAX_CLASSNAME_SIZE 45
public Plugin:myinfo =
{
name = "NULL",
author = "NULL",
description = "NULL",
version = "NULL",
url = "NULL"
};
new MyWeapons[3];
new bool:MyClass = false;
public OnPluginStart()
{
HookEvent("post_inventory_application", Event_InvChange);
HookEvent("player_spawn", Event_PlayerSpawn);
}
public Event_InvChange(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!MyClass)
return;
new slot = GetClientOfUserId(GetEventInt(event, "userid"));
decl entityStorage;
for (new i = 0; i < 3; i++)
{
entityStorage = GetPlayerWeaponSlot(slot, i);
if ( GetEntProp(entityStorage, Prop_Send, "m_iItemDefinitionIndex") != MyWeapons[i] )
{
TF2_RemoveWeaponSlot(slot, i);
GiveWeapon(slot, MyWeapons[i]);
PrintToServer("Slot %i does not match", i);
}
}
}
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new slot = GetClientOfUserId(GetEventInt(event, "userid"));
new team = GetEventInt(event, "team");
if (team > 1)
{
if (TF2_GetPlayerClass(slot) != TFClass_Scout)
{
TF2_SetPlayerClass(slot, TFClass_Scout, false);
TF2_RespawnPlayer(slot);
}
else
MyClass = true;
TF2_RemoveAllWeapons(slot);
GiveWeapon(slot, 45);
MyWeapons[0] = 45;
GiveWeapon(slot, 46);
MyWeapons[1] = 46;
GiveWeapon(slot, 450);
MyWeapons[2] = 450;
TF2_RegeneratePlayer(slot);
}
}
public GiveWeapon(UserSlot, index)
{
new Handle:hWeapon = TF2Items_CreateItem(OVERRIDE_CLASSNAME | OVERRIDE_ITEM_DEF | FORCE_GENERATION | PRESERVE_ATTRIBUTES);
new String:classname[MAX_CLASSNAME_SIZE];
TF2Items_SetItemIndex(hWeapon, index);
TF2II_GetItemClass(index, classname, sizeof(classname), TFClass_Scout);
TF2Items_SetClassname(hWeapon, classname);
new wEntity = TF2Items_GiveNamedItem(UserSlot, hWeapon);
CloseHandle(hWeapon);
EquipPlayerWeapon(UserSlot, wEntity);
}
This force-spawns you as a Scout with the Force-a-Nature, Bonk! and Atomizer. They all do what they're supposed to (knockback, consumable/immunity and triple jump, respectively) and have proper skins, but, for example, the Atomizer still has the Bat taunt (that's how I noticed that the indexes differ in the first place).