Skip to content

Instantly share code, notes, and snippets.

@mribbons
Created July 15, 2021 04:09
Show Gist options
  • Select an option

  • Save mribbons/e89facfb93a8e10a307a03f226f3b795 to your computer and use it in GitHub Desktop.

Select an option

Save mribbons/e89facfb93a8e10a307a03f226f3b795 to your computer and use it in GitHub Desktop.
OnPressCraftButton function
function OnPressCraftButton(button)
if not LOCAL_PLAYER.clientUserData.currentlyCrafting and SpamPrevent(itemRecipe.craftTime) and craftButton == button then
CraftProgress.progress = 0
craftingCount = 0
currentHealth = LOCAL_PLAYER.hitPoints
craftingTimer = itemRecipe.craftTime or 1
-- Send a crafting event to the server which checks the player's inventory for
ingredientsPanel.visibility = Visibility.FORCE_OFF
CraftProgress.visibility = Visibility.FORCE_ON
LOCAL_PLAYER.clientUserData.currentlyCrafting = true
local reward = ItemDatabase:GetItemFromMUID(itemRecipe.reward)
ProgressText.text = "Crafting:" .. reward:GetName()
Events.BroadcastToServer("PLAYER_ANIM", LOCAL_PLAYER, Animation, craftingTimer)
currentlyCrafting =
Task.Spawn(
function()
for _, ingredient in ipairs(itemRecipe.ingredients) do
local ingredientItem = ItemDatabase:GetItemFromMUID(ingredient.requirement)
inventory:RemoveItem(ingredientItem, ingredient.count)
World.SpawnAsset(craftCompleteAudio, {position = LOCAL_PLAYER:GetWorldPosition()})
end
if inventory:GetFreeBackpackSlot() or inventory:_CanAccommodateStackableItem(reward) then
inventory:AddItem(reward)
else
-- If the item can't fit into the inventory then drop the item below the player.
Events.BroadcastToServer(
"OnDropSpecificHashLoot",
reward:RuntimeHash(),
LOCAL_PLAYER:GetWorldPosition() - Vector3.UP * 100
)
end
if itemRecipe.skillId and Skills() and Skills()[itemRecipe.skillId] then
local skillId = itemRecipe.skillId
Skills().AddSkillXp(LOCAL_PLAYER, Skills()[skillId], itemRecipe.xp)
end
LOCAL_PLAYER.clientUserData.currentlyCrafting = false
craftingCount = 0
currentlyCrafting = nil
end,
craftingTimer
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment