Jump to content

عند المرور على ماركر توقف السيارة


Recommended Posts

مو شغال اخوي

الكود

-- Server Side -- 
             lowspedMarker = createMarker (1808.0489501953, -2164.6923828125, 13.3828125, "cylinder", 20.0, 0, 0, 255, 0) 
             stopspedMarker = createMarker (1787.9403076172, -2164.2365722656, 13.3828125, "cylinder", 20.0, 0, 0, 255, 0) 
  
addEventHandler("onMarkerHit",lowspedMarker, 
    function ( player ) 
        if ( getElementType ( player ) == "player" and isPedInVehicle ( player ) and getElementSpeed(player, "kph")) then 
            setElementSpeed(player, "kph", 30) 
        end 
    end,false 
) 
  
addEventHandler("onMarkerHit",stopspedMarker, 
    function ( player ) 
        if ( getElementType ( player ) == "player" and isPedInVehicle ( player )  and getElementSpeed(player, "kph")) then 
            setElementSpeed(player, "kph", 0) 
        end 
    end,false 
) 

Link to comment

-- # Server Side ... 
function setElementSpeed(element, unit, speed) -- only work if element is moving! 
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then -- if true - element is valid, no need to check again 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
        return true 
    end 
  
    return false 
end 
  
function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
  
local lowspedMarker = createMarker (1808.0489501953, -2164.6923828125, 13.3828125, "cylinder", 20.0, 0, 0, 255, 0) 
local stopspedMarker = createMarker (1787.9403076172, -2164.2365722656, 13.3828125, "cylinder", 20.0, 0, 0, 255, 0) 
  
addEventHandler("onMarkerHit",lowspedMarker, 
    function ( vehicle ) 
        if ( getElementType ( vehicle ) == "vehicle" ) then 
            setElementSpeed(vehicle, "kph", 30) 
        end 
    end,false 
) 
  
addEventHandler("onMarkerHit",stopspedMarker, 
    function ( vehicle ) 
        if ( getElementType ( vehicle ) == "vehicle" ) then 
            setElementSpeed(vehicle, "kph", 0) 
        end 
    end,false 
) 
Link to comment
مو شغال اخوي

الكود

-- Server Side -- 
             lowspedMarker = createMarker (1808.0489501953, -2164.6923828125, 13.3828125, "cylinder", 20.0, 0, 0, 255, 0) 
             stopspedMarker = createMarker (1787.9403076172, -2164.2365722656, 13.3828125, "cylinder", 20.0, 0, 0, 255, 0) 
  
addEventHandler("onMarkerHit",lowspedMarker, 
    function ( player ) 
        if ( getElementType ( player ) == "player" and isPedInVehicle ( player ) and getElementSpeed(player, "kph")) then 
            setElementSpeed(player, "kph", 30) 
        end 
    end,false 
) 
  
addEventHandler("onMarkerHit",stopspedMarker, 
    function ( player ) 
        if ( getElementType ( player ) == "player" and isPedInVehicle ( player )  and getElementSpeed(player, "kph")) then 
            setElementSpeed(player, "kph", 0) 
        end 
    end,false 
) 

جرب

tM = createMarker( ..... ) 
  
addEventHandler('onMarkerHit', tM, 
function( tV ) 
   if getElementType( tV ) == 'vehicle' then 
   setElementSpeed( tV, 'kph', 30 ) 
   end 
end 
) 
  
  
  
function setElementSpeed(element, unit, speed) -- only work if element is moving! 
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then -- if true - element is valid, no need to check again 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
        return true 
    end 
  
    return false 
end 
  
function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return 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...