Hello fellows.
I've been messing with tf_wearable_item entities as of lately, for creating a hats plugin (attaching the wearables to the player).
The thing is the system works perfectly, but it seems to give a small error if the entity is created by the normal ways (CreateEntityByName). It prompts the following error:
Quote:
Item 'tf_wearable_item' not setup correctly. Attempting to create attributes on an unitialized item.
|
My current code is:
PHP Code:
// Create wearable item and equip.
Entity = CreateEntityByName("tf_wearable_item");
if (!IsValidEntity(Entity)) return;
DispatchSpawn(Entity);
SDKCall(hEquipWearable, Client, Entity);
// Setup hat
DispatchKeyValue(Entity, "targetname", StrHatName);
DispatchKeyValue(Entity, "model", HatModel[Hat]);
SetEntityModel(Entity, HatModel[Hat]);
// Spawn and turn on
ActivateEntity(Entity);
AcceptEntityInput(Entity, "TurnOn");
The plugin works just fine, the only thing it gives that error. I was just wondering if there was any variables I needed to setup first before attaching to the player.
Also, some screenshots to prove it works, even using custom hats (and not only hats, they can be attached to any bone). I'll be releasing the plugin if I get to fix this issue:
Screenshot 1
Screenshot 2
Screenshot 3
Screenshot 4
Edit: Problem solved, after messing a little with the code I cut down some lines of the creation of the wearable and it seems to properly initialice the entity now:
PHP Code:
// Create wearable item and equip.
Entity = CreateEntityByName("tf_wearable_item");
if (!IsValidEntity(Entity)) return;
SDKCall(hEquipWearable, Client, Entity); // Equip the client with it.
SetEntityModel(Entity, HatModel[Hat]); // Set the correct model
DispatchKeyValue(Entity, "targetname", StrHatName); // And dispatch a name for it to be identified.
__________________