Jump to content

Spike system


at2008

Recommended Posts

local robberTeams = { ["Robber"] = true }


function onStingerHit(hitElement, matchingDimension)
	if hitElement and matchingDimension then
		if hitElement:getType() == "vehicle" then
			local vehicleController = hitElement:getController() or false
			if vehicleController then
        		local team = vehicleController:getTeam()
				if not team then return false end
				if robberTeams[team:getName()] then
					hitElement:setWheelStates(1, 1, 1, 1)
				end
			end
		end
	end
end

Something like this maybe? You would need to attach col shape or marker  to the stinger object and then add the "onStingerHit" function to onColShapeHit / onMarkerHit

 

stinger = Object.create(objectID, position, rotation)
stingerCol = ColShape.Sphere(position, 2)

stingerCol:attach(stinger)
stingerCol:setAttachedOffsets(0,0,-0.25)

addEventHandler("onColShapeHit", stingerCol, onStingerHit)

 

You can also use this method if you are having multiple stingers:

 

Edited by msyyn
Link to comment
addCommandHandler("putaspiketotheground",  --
    function(player, source)
        if (player) then 
		
		local px, py, pz = getElementPosition ( player )
		local rz = getPedRotation ( player )
		local distance = 5
		local x = distance*math.cos((rz+90)*math.pi/180)
		local y = distance*math.sin((rz+90)*math.pi/180)
		local b2 = 15 / math.cos(math.pi/180)
		local nx = px + x
		local ny = py + y
		local nz = pz - 0.8
		local provz = rz + 90
		local spike = createObject ( 2892, nx, ny, nz, 0.0, 0.0, provz)
		
        local x, y, z = getElementPosition(player)
        local x2, y2, z2 = getElementPosition(spike) 
        local blow = createColSphere(x2, y2, z2, 3)
        addEventHandler("onColShapeHit",blow,function (player)
        if player and getElementType(player) == "player" then
		local pveh = getPedOccupiedVehicle(player) 
        if isPedInVehicle(player) then
			if (getTeamName(getPlayerTeam(player)) ~= "robber" then return false end
				setVehicleWheelStates(pveh,1,1,1,1) 
				setVehicleColor( pveh, 247, 39, 157 ) 
				end
            end 
        end) 
    
		end
end) 

I made this script, but i have an error : 

WARNING: mypluginsfolder/myplugin.lua:line : Bad argument @ 'getPlayerTeam' [Excepted player at argument 1, got nil]
WARNING: mypluginsfolder/myplugin.lua:line : Bad argument @ 'getTeamName' [Excepted player at argument 1, got boolean]
--I got these errors from console

 

Link to comment
  • Moderators

This code:

if (getTeamName(getPlayerTeam(player)) ~= "robber" then return false end

Shouldn't be able to executed because of:

if player and getElementType(player) == "player" then

So I am not sure if I am looking at the right code.

 

 


 

Do no attach functions which are inside of other functions directly in an addEventHandler! They are not destroy able without accessing the globals: _G

The function will be created infinity times! I recommend you to create a function outside of the block.

addCommandHandler("putaspiketotheground", --

function(player, source)

if (player) then

 

local px, py, pz = getElementPosition ( player )

local rz = getPedRotation ( player )

local distance = 5

local x = distance*math.cos((rz+90)*math.pi/180)

local y = distance*math.sin((rz+90)*math.pi/180)

local b2 = 15 / math.cos(math.pi/180)

local nx = px + x

local ny = py + y

local nz = pz - 0.8

local provz = rz + 90

local spike = createObject ( 2892, nx, ny, nz, 0.0, 0.0, provz)

 

local x, y, z = getElementPosition(player)

local x2, y2, z2 = getElementPosition(spike)

local blow = createColSphere(x2, y2, z2, 3)

addEventHandler("onColShapeHit",blow,function (player)

if player and getElementType(player) == "player" then

local pveh = getPedOccupiedVehicle(player)

if isPedInVehicle(player) then

if (getTeamName(getPlayerTeam(player)) ~= "robber" then return false end

setVehicleWheelStates(pveh,1,1,1,1)

setVehicleColor( pveh, 247, 39, 157 )

end

end

end)

 

end

end)

 

 

  • Like 1
Link to comment

Try it :
 

addCommandHandler("putaspiketotheground", 
    function(player, cmd)
		if (player) then 
			  local px, py, pz = getElementPosition ( player )
			  local rz = getPedRotation ( player )
			  local distance = 5
			  local x = distance*math.cos((rz+90)*math.pi/180)
			  local y = distance*math.sin((rz+90)*math.pi/180)
			  local b2 = 15 / math.cos(math.pi/180)
			  local nx = px + x
			  local ny = py + y
			  local nz = pz - 0.8
			  local provz = rz + 90
			  local spike = createObject ( 2892, nx, ny, nz, 0.0, 0.0, provz)
			  local x, y, z = getElementPosition(player)
			  local x2, y2, z2 = getElementPosition(spike) 
			  local blow = createColSphere(x2, y2, z2, 3)
			  addEventHandler("onColShapeHit",blow,
				function (element)
					if element and getElementType(element) == "player" then
					local pveh = getPedOccupiedVehicle(element) 
						if isPedInVehicle(element) then
							if ( getTeamName( getPlayerTeam( element ) ) ~= "robber" ) then return end
							setVehicleWheelStates(pveh, 1, 1, 1, 1) 
							setVehicleColor( pveh, 247, 39, 157 ) 
						end
					end 
				end
			  ) 
		end
	end
) 

 

Edited by iMr.WiFi..!
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...