Jump to content

[HELP] How to fix this problem in my script?


Parkercito

Recommended Posts

First of all thank you very much for having bothered to open the post and read it. I tell you, the problem is that when trying to equip a weapon, it does not and it goes into an error in the console. Which I can not afford.

 

ERROR: dayzmode/lib/weapon/s_weap.lua:8: bad argument #1 to 'ipairs' (table expected, got nil)

 

I can pay if you solve the problem.

 

local weapon = {}

function WeaponToHands(source,item)
	local n,id = itemWpn(item.n)
	if n == 1 or n == 3 then
		toggleControl(source,'fire',false)
		local ammo = 0
		for i,item in ipairs(item.a) do
			if itemType(item.n) == 'ammo' or itemType(item.n) == 'maga' then
				ammo = math.max(ammo,item.o)
			elseif itemType(item.n) == 'scop' then
				id = 34
			end
		end
		if ammo > 0 and item.c < 5 then
			toggleControl(source,'fire',true)
		end
		takeWeapon(source,id,getPedTotalAmmo(source))
		giveWeapon(source,id,ammo+1,true)
	elseif n == 2 then
		giveWeapon(source,id,1,true)
	elseif n == 4 then
		if id == 43 or id == 22 then
			toggleControl(source,'fire',false)
		end
		giveWeapon(source,id,2,true)
	end
end

local function invNameSearch(inventory,value)
	if value then
		for n,item in ipairs(inventory) do
			if item.n == value.n then
				return item,n
			end
		end
	end
	return false
end

local Helm = {
	['headhelm'] = true,
	['headgorka'] = true,
	['headmoto'] = true,
	['headfhelm'] = true,
	['headssh68'] = true,
}

local NoneSoundDamage = {
	[17] = true,
	[18] = true,
	[37] = true,
	[41] = true,
	[42] = true,
	[52] = true,
	[53] = true,
}

addEvent('onDamage',true)
addEventHandler('onDamage',root,function(attacker,weapon,body,loss)
	if weapon == 54 or weapon == 53 or weapon == 49 then
		if loss > 30 then
			source:setData('fracture',true)
		end
		source:setData('blood',source:getData('blood')-loss^2)
	elseif weapon == 16 or weapon == 51 then
		source:setData('fracture',true)
		source:setData('pain',true)
		local inventory = source:getData('inventory')
		for i,item in ipairs(inventory) do
			item.c = math.random(math.max(4,item.c),5)
			inventory[i] = item
			if type(item.o) == 'table' then
				for n,item in pairs(item.o) do
					if item then
						item.c = math.random(math.max(4,item.c),5)
					end
					inventory[i].o[tonumber(n)] = item
				end
			end
		end
		source:setData('inventory',inventory)
		source:setData('blood',source:getData('blood')-loss*67)
	elseif weapon > 0 and not NoneSoundDamage[weapon] then
		if attacker and attacker:getType() == 'player' then
			if math.random(4) == 2 then
				source:setData('pain',true)
			end
			local hands = attacker:getData('hands')
			local damage = getWeapInfo(hands and hands.n).damage
			local inventory = source:getData('inventory')
			if body == 3 then
				local item,n = invNameSearch(inventory,source:getData('vest'))
				if item then
					damage = damage/(1+(5-item.c)/10)
					item.c = item.c+2 > 5 and 5 or item.c+2
					inventory[n] = item
				end
				local item,n = invNameSearch(inventory,source:getData('shrt'))
				if item then
					item.c = item.c+2 > 5 and 5 or item.c+2
					inventory[n] = item
				end
			elseif body == 4 then
				local item,n = invNameSearch(inventory,source:getData('bapa'))
				if item then
					damage = damage/(1+(5-item.c)/10)
					item.c = item.c+2 > 5 and 5 or item.c+2
					inventory[n] = item
				end
			elseif body == 5 then
				damage = damage*0.4
			elseif body == 6 then
				local hands = source:getData('hands')
				if hands then
					hands.c = hands.c+2 > 5 and 5 or hands.c+2
					source:setData('hands',hands)
				end
				damage = damage*0.4
			elseif body == 7 or body == 8 then
				local item,n = invNameSearch(inventory,source:getData('pant'))
				if item then
					item.c = item.c+2 > 5 and 5 or item.c+2
					inventory[n] = item
				end
				local item,n = invNameSearch(inventory,source:getData('shoe'))
				if item then
					item.c = item.c+2 > 5 and 5 or item.c+2
					inventory[n] = item
				end
				source:setData('fracture',true)
				damage = damage*0.5

			elseif body == 9 then
				local item,n = invNameSearch(inventory,source:getData('mask'))
				if item then
					damage = damage/(1+(5-item.c)/100)
					item.c = 5
					inventory[n] = item
				end
				local item,n = invNameSearch(inventory,source:getData('head'))
				if item and Helm[item.n] and item.c < 4 then
					damage = damage*(1-item.c/100)
					item.c = 5
					inventory[n] = item
				else
					source:setData('blood',0)
				end
			end
			source:setData('inventory',inventory)
			local damage = damage/(1-(5-(hands and hands.c or 5))/100)
			source:setData('blood',source:getData('blood')-damage)
			if damage > 1000 or math.random(2) == 1 then
				local bleeding = source:getData('bleeding')
				local add = math.floor(loss*0.75)
				if bleeding[1] < add then
					bleeding[1] = add
					bleeding[body-1] = true
					source:setData('bleeding',bleeding)
					outputChat(source,'I bleed','red')
				end
			end
		end
	else
		source:setData('blood',source:getData('blood')-loss*math.random(10))
	end
	if not NoneSoundDamage[weapon] then
		local x,y,z = getElementPosition(source)
		sound3D(source,{'body'..body..'.ogg',x,y,z,10})
	end
end)

addEvent('weaponMTAReload',true)
addEventHandler('weaponMTAReload',root,function()
	local id = source:getWeapon()
	if id == 33 or id == 34 then
		source:setData('anim',{'BUDDY','buddy_reload',false})
	else
		local source = source
		Timer(reloadPedWeapon,50,1,source)
	end
end)

addEvent('createFlare',true)
addEventHandler('createFlare',root,function(trajectory)
	local T1,T2,coord,element = unpack(trajectory)
	if element and isElement(element) and (element:getType() == 'player' or element:getType() == 'ped') then
		element:setOnFire(true)
	end
	local px,py,pz,ex,ey,ez,vx,vy,gz = unpack(coord)
	local objLight = Object(354,px,py,pz)
	local objSmoke = Object(2060,px,py,pz)
	local objMarker = Marker(px,py,pz,'corona',4,255,0,0,150)
	objLight:setCollisionsEnabled(false)
	objSmoke:setCollisionsEnabled(false)
	objSmoke:attach(objLight)
	objMarker:attach(objLight)
	local time = (vx and vy and gz) and T1*1000 or 100
	objLight:move(time,ex,ey,ez,0,0,0,'OutBack')
	Timer(function()
		if vx and vy and gz then
			local time = math.max(T2*200,50)
			objLight:move(time,vx,vy,gz,0,0,0,'OutQuad')
			Timer(function()
				objLight:destroy()
				objSmoke:destroy()
				objMarker:destroy()
			end,time,1)
		else
			Timer(function()
				objLight:destroy()
				objSmoke:destroy()
				objMarker:destroy()
			end,15000,1)
		end
	end,math.max(time-5000,50),1)
end)

 

Link to comment
  • Moderators

Go to the owner of the script and inform him about it. You are now posting his code on the community. I am not sure if you are using a leaked version, but technically this is not allowed to be post without reference to the owner.

Link to comment
26 minutes ago, IIYAMA said:

Go to the owner of the script and inform him about it. You are now posting his code on the community. I am not sure if you are using a leaked version, but technically this is not allowed to be post without reference to the owner.

If you do not want to help I understand. But do not comment to earn points.

Link to comment
  • Moderators

If you do not want to contact the owner then it means it is leaked. I can understand that you want to get rid of me if that is the case.

But even so I gave you a legal and cheap way to solve your problem and yet you call that not helping, OK.

Good luck with it.

 

 

  • Haha 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...