Along with working on RayJay, I've been touching up some of my plugins to make them easier to use. For example, a crafting blueprint looked like this before:
Code:
local ITEM = Clockwork.item:New("blueprint_base");
ITEM.name = "9mm Pistol Blueprint";
ITEM.model = "models/weapons/w_pistol.mdl";
ITEM.weight = 0.8;
ITEM.category = "Weapon Blueprints"
ITEM.crafting = true;
ITEM.description = "Requirements: \nx1 Broken 9mm Pistol \nx2 Reclaimed Metal \nx1 Box of Screws \nx1 Screw Driver";
-- A function to check for the required materials for a craft.
function ITEM:HasMaterials(player)
return (
player:HasItemByID("broken_9mm_pistol") and
player:HasItemByID("reclaimed_metal") and (table.Count(player:GetItemsByID("reclaimed_metal")) >= 2) and
player:HasItemByID("box_of_screws") and
player:HasItemByID("screw_driver")
)
end;
-- A function to take the required materials for a craft.
function ITEM:TakeMaterials(player)
return (
player:TakeItem(player:FindItemByID("broken_9mm_pistol")) and
player:TakeItem(player:FindItemByID("reclaimed_metal")) and
player:TakeItem(player:FindItemByID("box_of_screws")) )
end;
-- A function to give a player a crafted item.
function ITEM:GiveCraft(player)
return (
player:GiveItem(Clockwork.item:CreateInstance("weapon_pistol"))
)
end;
ITEM:Register();
Now it will look like this:
Code:
local ITEM = Clockwork.item:New("blueprint_base");
ITEM.name = "9mm Pistol Blueprint";
ITEM.model = "models/weapons/w_pistol.mdl";
ITEM.weight = 0.8;
ITEM.category = "Weapon Blueprints"
ITEM.crafting = true;
ITEM.description = "Requirements: \nx1 Broken 9mm Pistol \nx2 Reclaimed Metal \nx1 Box of Screws \nx1 Screw Driver";
-- A function to check for the required materials for a craft.
function ITEM:HasMaterials(player)
return {
"broken_9mm_pistol",
{"reclaimed_metal", 2},
"box_of_screws",
"screw_driver"
}
end;
-- A function to take the required materials for a craft.
function ITEM:TakeMaterials(player)
return {
"broken_9mm_pistol",
{"reclaimed_metal", 2},
"box_of_screws"
}
end;
-- A function to give a player a crafted item.
function ITEM:GiveCraft(player)
return {
"weapon_pistol"
}
end;
ITEM:Register();
The only downside to this is that the item cannot have a name that is 1 character long otherwise you won't be able to use multi checking, giving and taking (which is negligible considering how the blueprints will be a lot more clean).