Jump to content

Help with isElementWithinColShape


adamb

Recommended Posts

for k,v in ipairs(getElementsByType("player")) do 
 bindKey(v, "o", "down", "pullover") 
end 
  
local circlearea = createColCircle ( 0, 0, 10 ) 
  
function ColShapeHit ( su, matchingDimension ) 
    local detection = isElementWithinColShape ( su, circlearea ) 
    if detection  then 
        if ( getElementType ( su ) == "vehicle" ) then 
            setVehicleEngineState ( su, false ) 
        end 
    end 
end 
  
addCommandHandler("pullover", ColShapeHit) 
  

Basically supposed to stop the NPC ped in the colsphere, doesn't work for some reason, can anyone look thru it and correct it?

Link to comment
  • Moderators

try this:

for k,v in pairs(getElementsByType("player")) do 
 bindKey(v, "o", "down", "pullover") 
end 
  
local circlearea = createColCircle ( 0, 0, 10 ) 
  
function ColShapeHit ( su, command) 
    local vehicle =getPedOccupiedVehicle ( su ) 
    if isElementWithinColShape ( vehicle, circlearea ) and getElementType ( vehicle ) == "vehicle"  then 
            setVehicleEngineState ( vehicle, false ) 
    end 
end 
  
addCommandHandler("pullover", ColShapeHit) 
  

Link to comment
  
local circlearea = createColCircle ( 0, 0, 10 ) 
  
function ColShapeHit ( hitElement, matchingDimension ) 
    local detection = isElementWithinColShape ( hitElement, circlearea ) 
    if (detection and (getElementType(hitElement) == "vehicle")) then 
        setVehicleEngineState (hitElement, false) 
    end 
end 
addEventHandler("onColShapeHit", circlearea, ColShapeHit) 
  

It will not work with Command handler becouse the parameters are hitElement and the dimension. CommandHandler givs player, commandname and rest. And a Player is not a vehicle. Use onColShapeHit or make 2 functions:

  
local circlearea = createColCircle ( 0, 0, 10 ) 
  
function ColShapeHit ( hitElement, matchingDimension ) 
    local detection = isElementWithinColShape ( hitElement, circlearea ) 
    if (detection and (getElementType(hitElement) == "vehicle")) then 
        setVehicleEngineState (hitElement, false) 
    end 
end 
addEventHandler("onColShapeHit", circlearea, ColShapeHit) 
  
function triggerEventColShapeHit(player) 
local pVeh = getPedOccupiedVehicle ( player ) 
local curDimen = getElementDimension(player) 
    if (pVeh and curDimen) then 
        triggerEvent("onColShapeHit", player, pVeh, curDimen) 
    else 
        outputChatBox("Vehicle not found! Enter a vehicle", player, 255, 0, 0) 
    end 
end 
addCommandHandler("tColshape", triggerEventColShapeHit) 
  

Not tested at all but after debugging it should work like this

Link to comment
  • Moderators
  
for k,v in pairs(getElementsByType("player")) do 
     bindKey(v, "o", "down", "pullover") 
end 
  
local circlearea = createColCircle ( 0, 0, 10 ) 
  
addCommandHandler("pullover",   
function ( su, command) 
    local vehicle =getPedOccupiedVehicle ( su ) 
    if vehicle and isElementWithinColShape ( vehicle, circlearea ) then 
        setVehicleEngineState ( vehicle, false ) 
    end 
end) 
  
  

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