Jump to content

What if I put addEventHandler inside function


maffius97

Recommended Posts

Can you help me to move this 2 functions to clientside?

addCommandHandler("sting", 
    function(player) 
        if (player) then 
        local x,y,z = getElementPosition(player) 
        local xr,yr,zr = getElementRotation(player) 
        px, py, pz = getElementPosition(player) 
        prot = getPedRotation(player) 
        local offsetRot = math.rad(prot+90) 
        local vx = px + 5 * math.cos(offsetRot) 
        local vy = py + 5 * math.sin(offsetRot) 
        local vx2 = px + 2 * math.cos(offsetRot) 
        local vy2 = py + 2 * math.sin(offsetRot) 
        local vx3 = px + 3 * math.cos(offsetRot) 
        local vy3 = py + 3 * math.sin(offsetRot) 
        local vx4 = px + 4 * math.cos(offsetRot) 
        local vy4 = py + 4 * math.sin(offsetRot) 
        local vz = pz + 2 
        local vrot = prot+180 
        spike = createObject(2892,vx,vy,z-0.95,0,0,vrot) 
        setObjectScale(spike,0.7) 
        local x2, y2, z2 = getElementPosition(spike) 
        local blow = createColTube (x2, y2, z2-0.25, 0.9,2) 
        local blow2 = createColTube (vx2, vy2, z2-0.25, 0.9,2) 
        local blow3 = createColTube (vx3, vy3, z2-0.25, 0.9,2) 
        local blow4 = createColTube (vx4, vy4, z2-0.25, 0.9,2) 
        addEventHandler("onColShapeHit",blow, wylaczKola) 
        addEventHandler("onColShapeHit",blow2,wylaczKola) 
        addEventHandler("onColShapeHit",blow3,wylaczKola) 
        addEventHandler("onColShapeHit",blow4,wylaczKola) 
    end 
end) 
  
  
function wylaczKola (player) 
    if player and getElementType(player) == "player" then 
        if isPedInVehicle(player) then 
            local pveh = getPedOccupiedVehicle(player)      
            setVehicleWheelStates(pveh,1,1,1,1) 
        end 
    end 
end 

Link to comment

For this you must use onClientColShapeHit. By the way, i think you can use this for server-side(not tested):

local spike = { } 
local blows = { } 
  
addCommandHandler("sting", 
    function(player) 
        if (player) then 
        local x,y,z = getElementPosition(player) 
        local xr,yr,zr = getElementRotation(player) 
        px, py, pz = getElementPosition(player) 
        prot = getPedRotation(player) 
        local offsetRot = math.rad(prot+90) 
        local vx = px + 5 * math.cos(offsetRot) 
        local vy = py + 5 * math.sin(offsetRot) 
        local vx2 = px + 2 * math.cos(offsetRot) 
        local vy2 = py + 2 * math.sin(offsetRot) 
        local vx3 = px + 3 * math.cos(offsetRot) 
        local vy3 = py + 3 * math.sin(offsetRot) 
        local vx4 = px + 4 * math.cos(offsetRot) 
        local vy4 = py + 4 * math.sin(offsetRot) 
        local vz = pz + 2 
        local vrot = prot+180 
        spike[player] = createObject(2892,vx,vy,z-0.95,0,0,vrot) 
        setObjectScale(spike,0.7) 
        local x2, y2, z2 = getElementPosition(spike) 
        local blows[player] = {createColTube (x2, y2, z2-0.25, 0.9,2), createColTube (vx2, vy2, z2-0.25, 0.9,2), createColTube (vx3, vy3, z2-0.25, 0.9,2), createColTube (vx4, vy4, z2-0.25, 0.9,2) } 
        addEventHandler("onColShapeHit",blows[player], wylaczKola) 
    end 
end) 
  
  
function wylaczKola (player) 
    if player and getElementType(player) == "player" then 
        if isPedInVehicle(player) then 
            local pveh = getPedOccupiedVehicle(player)     
            setVehicleWheelStates(pveh,1,1,1,1) 
        end 
    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...