Jump to content

[Help] Script does not work


Hansu42

Recommended Posts

local function isExplosiveWeapon(id)
    local t = {35, 36, 16, 18, 39}
    for _, i in ipairs(t) do
        if i == id then return true end
    end
    return false
end
addEventHandler("onClientVehicleDamage", root, function(_, wpn, loss)
    if wpn and not isExplosiveWeapon(tonumber(wpn)) then
        cancelEvent()
    elseif wpn and isExplosiveWeapon(tonumber(wpn)) then
        setElementHealth(source, getElementHealth(source) - loss)
    end
end)
addEventHandler("onClientPedDamage", root, function(attacker, wpn, bodypart)
    if isPedInVehicle(source) then
        cancelEvent()
    else
        if attacker ~= source and bodypart == 9 then
            killPed(source, attacker, wpn)
        end
    end
end)
Vehicles have still immortality and I would like selected weapons to destroy the vehicle
Edited by Hansu42
Link to comment
  • Moderators

I don't know why, but if I shoot the vehicle with rocket laucher it get damage by weapon id 51.

But weapon with id 51 is not exists. (51 is the explosion's damage id)

 

local explosiveWeapon = {
	[16] = true,
	[18] = true,
	[35] = true,
	[36] = true,
	[37] = true, -- fire
	[39] = true,
	[51] = true, -- explosion
}

addEventHandler("onClientVehicleDamage", root, function(_, wpn)
	if explosiveWeapon[wpn] then
		cancelEvent()
	end
end)

 

Link to comment
3 minutes ago, stPatrick said:

I don't know why, but if I shoot the vehicle with rocket laucher it get damage by weapon id 51.

But weapon with id 51 is not exists. (51 is the explosion's damage id)

 


local explosiveWeapon = {
	[16] = true,
	[18] = true,
	[35] = true,
	[36] = true,
	[37] = true, -- fire
	[39] = true,
	[51] = true, -- explosion
}

addEventHandler("onClientVehicleDamage", root, function(_, wpn)
	if explosiveWeapon[wpn] then
		cancelEvent()
	end
end)

 

Did not work
Link to comment
  • Moderators
3 minutes ago, Hansu42 said:

Did not work

 

I missed. If you want to block all damage and enable only the rockets, place a not before explosiveWeapon[wpn] at line 13.

if not explosiveWeapon[wpn] then

 

Edited by stPatrick
Link to comment

 

Yes, but I would like only RPG and HS to deal damage to the vehicle and M4 and ak no longer

 

 

 

 

7 minutes ago, stPatrick said:

 

I missed. If you want to block all damage and enable only the rockets, place a not before explosiveWeapon[wpn] at line 13.


if not explosiveWeapon[wpn] then

 

Yes, but I would like only RPG and HS to deal damage to the vehicle and M4 and ak no longer
8 minutes ago, stPatrick said:

 

I missed. If you want to block all damage and enable only the rockets, place a not before explosiveWeapon[wpn] at line 13.


if not explosiveWeapon[wpn] then

 

It also does not work
Edited by Hansu42
Link to comment
4 minutes ago, stPatrick said:

I can't belive that.

 


addEventHandler("onClientVehicleDamage", root, function(_, wpn)
	if wpn ~= 51 then -- explosive
		cancelEvent()
	end
end)

 

Try that.

Now the car has immortality on all weapons
Link to comment
2 minutes ago, stPatrick said:

Niemożliwy.

Myślę, że jeden z twoich zasobów zmodyfikuje go.

I will go and see on the local server
16 minutes ago, stPatrick said:

Impossible.

I think one of your resources is modify it.

tankdx = 2
tankdy = 4
tankdz = 2

function boomOn ()
	booming = true
	--outputDebugString("Boomon!")
end

function start ()
	maxDamage = get("maxTankDamage")
	eightDistance = get("eightTankDistance")
	--outputDebugString("tankdamage settings: maxTankDamage = "..tostring(maxDamage).." - eightTankDistance = "..tostring(eightDistance))
	boomOn()
end

addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),start)

function boom (x,y,z,boomType)
--outputDebugString("boom type "..tostring(boomType))
if booming then
	booming = false
	boomTimer = setTimer(boomOn,1000,1)
	--outputDebugString("location: " .. tostring(x) .. "," .. tostring(y) .. "," .. tostring(z))
	local rhinos = getVehiclesOfType(432)
	--outputDebugString(tostring(#rhinos).." rhinos found")
	for i,vehicle in ipairs (rhinos) do
	 if getElementModel(vehicle) == 432 then
		local vx, vy, vz = getElementPosition(vehicle)
		local sx = x - vx
		local sy = y - vy
		local sz = z - vz
		--outputDebugString("distance to rhino: " .. tostring(sx) .. "," .. tostring(sy) .. "," .. tostring(sz))
		if sx^2 + sy^2 + sz^2 < 1000 then
			
			local rotvX,rotvY,rotvZ = getVehicleRotation(vehicle)
			
			local t = math.rad(rotvX)
			local p = math.rad(rotvY)
			local f = math.rad(rotvZ)
			
			local ct = math.cos(t)
			local st = math.sin(t)
			local cp = math.cos(p)
			local sp = math.sin(p)
			local cf = math.cos(f)
			local sf = math.sin(f)
			
			local dz = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy
			local dx = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy
			local dy = st*sz - sf*ct*sx + cf*ct*sy
			
			local damage
			if math.abs(dx) < tankdx and math.abs(dy) < tankdy and math.abs(dz) < tankdz then
				damage = maxDamage
			else
				dx = math.abs(dx) -tankdx
				dy = math.abs(dy) -tankdy
				dz = math.abs(dz) -tankdz
				if dx < 0 then dx=0 end
				if dy < 0 then dy=0 end
				if dz < 0 then dz=0 end
				local distance = math.sqrt(dx^2+dy^2+dz^2)
				if distance > 10 then damage = 0
				elseif distance < 1 then damage = maxDamage
				else damage = maxDamage*((distance/eightDistance)+1)^(-3) end
				--outputDebugString("explosion distance: ".. tostring(distance))
			end
			setElementHealth(vehicle,getElementHealth(vehicle)-damage)
			-- outputDebugString("tank damaged " .. tostring(damage))
		end
	 end
	end
	
end
end
function boom (x,y,z,boomType)
	triggerServerEvent("onBoom",getLocalPlayer(),x,y,z,boomType)
end

addEventHandler("onClientExplosion",getRootElement(),boom)
<meta>
	<info author="Killeryoyo" name="tankdamage"  version="0.2.2" type="script"/>
	<script src="tankdamage.lua" type="server" />
	<script src="tankdamageCL.lua" type="client" />
	<settings>
		<setting name="*maxTankDamage" value="250"/>
		<setting name="*eightTankDistance" value="20"/>
	</settings>
</meta>
I only have this script that destroys the tank after 3 shots.I was on a local server and your script worked. is it possible for these 2 scripts to work with each other?

 
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...