Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crafting system issue #25

Open
pedroxvb opened this issue Nov 3, 2017 · 1 comment
Open

crafting system issue #25

pedroxvb opened this issue Nov 3, 2017 · 1 comment

Comments

@pedroxvb
Copy link

pedroxvb commented Nov 3, 2017

when you craft something, that has multiple items, for example i want to do that :

local RECIPE = {}
RECIPE.uid = "example"
RECIPE.name = "A Skull"
RECIPE.category = nut.lang.Get( "icat_material" )
RECIPE.model = Model( "models/Gibs/HGIBS.mdl" )
RECIPE.desc = "A Skull."
--RECIPE.noBlueprint = true
RECIPE.items = {
	["bone"] = 2,
}
RECIPE.result = {
	["skull"] = 1,
}
RECIPES:Register( RECIPE )

It is actually set to use 2 bones to craft a skull, but it doesn't work, the craft is successfull even if i use only one bone.
I mean if i use 2 bones they both disapear from my inventory and i got the skull but if i use only one bone it will give me the skull aswell and remove the single bone.
I'm sorry for terrible explanation, i'm not very good at explaining things.
Can you help me with this i don't know what i need to change in the code to make it properly work, i know i need to modify something in this area but i'm new to lua and i don't know how to fix this myself :

function RECIPES:Register( tbl )
	if !tbl.CanCraft then
		function tbl:CanCraft( player )
			for k, v in pairs( self.items ) do
				if !player:HasItem( k, v ) then
					return false
				end
			end
			return true
		end
	end
	if !tbl.ProcessCraftItems then
		function tbl:ProcessCraftItems( player )

			player:EmitSound( "items/ammo_pickup.wav" )
			for k, v in pairs( self.items ) do
				for i = 1, v do
					if player:getChar():getInv():hasItem( k ) then
						player:getChar():getInv():remove( player:getChar():getInv():hasItem( k ):getID() )
					end
				end
			end
			for k, v in pairs( self.result ) do
				--print(player:getChar():getInv():add(k, v))
				--if (!player:getChar():getInv():add(k, v)) then
					for i = 1, v do
					nut.item.spawn(k, player:getItemDropPos())
					end
				--else
					--netstream.Start(client, "vendorAdd", uniqueID)
				--end
			end
			player:notifyLocalized( "donecrafting", self.name )

		end
	end
	self.recipes[ tbl.uid ] = tbl
end

Hope it is clear, and thanks for any help by advance :).

@Stanstar22
Copy link
Contributor

Stanstar22 commented Sep 21, 2018

Hello I know I am almost a year late, but better late than never!
I managed to fix this script with just a few small edits

for k, v in pairs( self.items ) do
	if player:HasItem( k, v ) then
		if player:getChar():getInv():getItemCount(k) < v then
			return false
		end
	end
	if !player:HasItem( k, v ) then
		return false
	end
end
return true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants