noclip_crafting Troubleshooting
This guide covers common issues and solutions for the noclip_crafting script, including recent fixes and improvements.
Recent Fixes & Improvements
Latest Version Fixes
- Ingredient Handling: Fixed "attempt to compare table with number" errors by consolidating HasItem functions
- Menu Display: Resolved hazard types and byproduct chance display issues in crafting menu
- Item Labeling: Fixed crafting menu showing item names instead of proper labels
- Skill System: Improved skill requirement checking and experience calculation
- Crafting Success/Failure: Fixed success chance mechanics and ingredient return on failure
- Error Handling: Added comprehensive safety checks and validation throughout the script
- Police Alerts: Added placeholder implementation for SendPoliceAlertWithLocation
- Hazard Effects: Fixed "attempt to index a number value" errors in hazard handling
Common Issues & Solutions
Client-Side Errors
"attempt to compare table with number"
Cause: Ingredient amounts being passed as tables instead of numbers
Solution: This has been fixed in the latest version. The script now properly handles both table and number values for ingredient counts.
Fixed Code Example:
-- The script now automatically sums table values
local function HasItem(source, item, amount)
if type(amount) == "table" then
local total = 0
for _, count in pairs(amount) do
total = total + count
end
amount = total
end
-- Rest of function...
end
"table index is nil" at editable_client.lua line 81
Cause: Missing safety checks in menu creation functions
Solution: Added comprehensive validation and pcall wrappers around menu functions.
Safety Check Example:
-- All menu functions now include safety checks
local success, result = pcall(function()
lib.registerContext({
id = 'crafting_menu',
title = 'Crafting Menu',
options = menuOptions
})
lib.showContext('crafting_menu')
end)
if not success then
print("^1Error creating crafting menu: " .. tostring(result))
end
"attempt to index a number value (field 'damage')"
Cause: Hazard config being sent as number instead of table
Solution: Server now ensures hazard config is always sent as a table to the client.
Server-Side Issues
Server receiving "unknown" as item name
Cause: Missing item field in crafting event
Solution: Fixed client code to include the item field when triggering crafting events.
"attempt to perform arithmetic on a nil value (field 'successExpMultiplier')"
Cause: Incorrect config field reference in experience calculation
Solution: Fixed CalculateExperienceGain function to use correct config field names.
Missing function "SendPoliceAlertWithLocation"
Cause: Function not implemented in the script
Solution: Added placeholder implementation with debug logging.
Placeholder Implementation:
function SendPoliceAlertWithLocation(coords, message)
if Config.Debug then
print("^3[DEBUG] Police Alert: " .. message .. " at " .. tostring(coords))
end
-- Add your police alert system integration here
-- Example: exports['ps-dispatch']:CustomAlert(coords, message)
end
Crafting System Issues
Crafting always succeeds despite low success chance
Cause: Success/fail system was disabled in config
Solution: Success/fail system is now properly enabled and working.
Config Setting:
Config.CraftingSystem = {
enableSuccessFail = true, -- Enable success/fail mechanics
-- Other settings...
}
Ingredients removed then given back on failure
Cause: Missing HandleCraftingFailure function
Solution: Added proper failure handling that only returns ingredients if partial loss is enabled.
Failure Handling:
function HandleCraftingFailure(source, recipe, ingredients)
if Config.CraftingSystem.partialLossOnFailure then
-- Return some ingredients based on partial loss chance
for item, amount in pairs(ingredients) do
local returnAmount = math.floor(amount * Config.CraftingSystem.partialLossChance)
if returnAmount > 0 then
exports.ox_inventory:AddItem(source, item, returnAmount)
end
end
end
-- No ingredients returned if partial loss is disabled
end
Skill requirement not met despite high player level
Cause: Skill system not fully implemented or configured
Solution: Skill system has been improved with better validation and admin commands for testing.
Admin Commands:
/setskill [player_id] [skill_name] [level] -- Set player skill level
/checkskill [player_id] [skill_name] -- Check player skill level
/resetskills [player_id] -- Reset all player skills
Menu Display Issues
Hazard warnings and byproduct chances showing in menu
Cause: Menu description including unwanted information
Solution: Disabled display of hazard warnings, byproduct chances, XP gain, and success chance in menu descriptions.
Menu title showing item names instead of labels
Cause: Missing item label retrieval logic
Solution: Added robust item label handling with special support for weapons.
Item Label Handling:
local function GetItemLabel(itemName)
if Config.UseOxInventory then
local item = exports.ox_inventory:Items(itemName)
if item then
return item.label or itemName
end
end
-- Fallback to QBCore items
local qbItem = QBCore.Shared.Items[itemName]
return qbItem and qbItem.label or itemName
end
Debugging & Testing
Enable Debug Mode
Set Config.Debug = true
in your config to get detailed logging for troubleshooting:
Config = {}
Config.Debug = true -- Enable detailed logging
-- Debug logs will show:
-- - Item data retrieval
-- - Menu creation process
-- - Skill checks
-- - Crafting events
-- - Error details
Admin Commands for Testing
Use these commands to test and debug the crafting system:
/craftingdebug -- Toggle debug mode
/setskill [player_id] [skill] [level] -- Set player skill level
/checkskill [player_id] [skill] -- Check player skill level
/resetskills [player_id] -- Reset all player skills
/giveitem [player_id] [item] [amount] -- Give items for testing
Performance Optimization
Reduce Debug Logging in Production
For better performance in production, ensure debug mode is disabled:
Config.Debug = false -- Disable in production
Optimize Recipe Loading
The script now includes optimized recipe loading with better caching and validation.
Getting Help
If you're still experiencing issues after trying these solutions:
- Enable Debug Mode: Set
Config.Debug = true
and check server console - Check Dependencies: Ensure all OX resources are up to date
- Verify Configuration: Double-check your config.lua settings
- Test with Admin Commands: Use the provided admin commands to test functionality
- Check Item Names: Ensure all item names match exactly between config and ox_inventory
- Contact Support: Provide error messages, config snippets, and steps to reproduce