I've finally completed making a working bodygroup clothing item. I scrolled on the internet and found Gr4SS's equipable item base. I used its essential code to create a working bodygroup item that can be used. Here is the code..
Code:
local ITEM = Clockwork.item:New("clothes_base");
ITEM.name = "Green Beanie";
ITEM.uniqueID = "green_beanie";
ITEM.cost = 15;
ITEM.weight = 0.5;
ITEM.business = true;
ITEM.category = "Accessories";
ITEM.access = "z";
ITEM.description = "A simple green beanie.";
ITEM:AddData("equipped", false, true);
-- Called when the player equips the item.
-- Override this function if you need to add your own behaviour for when a player equips/unequips this item
function ITEM:OnWearEquipableItem(player, bIsWearing) end;
-- Called when the player tries to equip the item.
-- Override this functions if you need to add your own behaviour for if a player can equip this item
-- Returning false will keep a player from equipping it, returning true or nil will allow him to equip it
function ITEM:CanPlayerWear(player, itemEntity) end;
-- Called when a player equips the item.
function ITEM:OnWearItem(player, bIsWearing)
self:SetData("equipped", bIsWearing);
self:OnWearEquipableItem(player, bIsWearing);
end;
function ITEM:HasPlayerEquipped(player, bIsValidWeapon)
return self:GetData("equipped", false);
end;
-- Called when a player uses the item.
function ITEM:OnUse(player, itemEntity)
player:SetBodygroup(4, 2);
if (player:Alive() and !player:IsRagdolled()) then
if (self:GetData("equipped") != true) then
if (self:CanPlayerWear(player, itemEntity) != false) then
self:SetData("equipped", true);
self:OnWearItem(player, true);
player:RebuildInventory();
return true;
end;
else
Clockwork.player:Notify(player, "You are already wearing this item!");
end;
else
Clockwork.player:Notify(player, "You cannot do this action at the moment!");
end;
return false;
end;
function ITEM:OnPlayerUnequipped(player, extraData)
player:SetBodygroup(4, 0);
self:OnWearItem(player, false);
player:RebuildInventory();
end;
function ITEM:OnStorageGive(player, storageTable)
if (self:GetData("equipped") == true) then
self:OnWearItem(player, false);
end;
end;
function ITEM:OnDrop(player, position)
player:SetBodygroup(4, 0);
if (self:GetData("equipped") == true) then
self:OnWearItem(player, false);
end;
end;
-- Called when a player's character has loaded.
function Clockwork:PlayerCharacterLoaded(player)
player:SetBodygroup(4, 0);
end;
ITEM:Register();
It works and I'm satisfied. Although I have another question. How do you change the thumbnail for the item?
The item shows by default as a barrel, does anyone know how to change this?