Jump to content

[Help] Tankdamage script


Hansu42

Recommended Posts

 

Hello, I have a problem with the script, when I add id rhino and id fire truck this script does not work

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>

 

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