Jump to content

[REQ] Indicator MOD [REQ]


Recommended Posts

Hello! I'm requesting help!

I need this mod a Indicator Mod the flashing lights from the car that people, can see, I want to download the mod onto my server! I kept searching for Mods and it shows Cleo's, :redhotevil: but I don't need cleo's I need the MTA Scripts.

Here's an example

https://community.multitheftauto.com/index.php?p= ... ils&id=942 :redhotevil:

It's a Good MTA Mod but, my friend tried it, and it only shows the light showing to him, I cannot see anything.

So that what screws it up, I need one that it can appear to us.

I hope I can get the Indicator Mod it will be an honour!

~ Residents illestiraqi :D

EDIT: Heres the code for the indicator mod I want it fixed and by fixed I mean the other players can see it too because atm its only me who can see the indicator on no one else and I want all to see it.

Client:

--------the Bind Key's 
KEY_LEFT_INDICATOR = ","; -- Keyboard: < 
KEY_RIGHT_INDICATOR = "."; -- Keyboard: > 
  
CMD_LEFT_INDICATOR = "ic_left"; 
CMD_RIGHT_INDICATOR = "ic_right"; 
  
-- Some variables. 
indicatorInfo = nil; -- Will be a table later 
isLeftOn = false; 
isRightOn = false; 
local frameCount = 1; 
  
-------- light left on  
function flashLeft() 
    if getVehicleOverrideLights(indicatorInfo['vehicle']) == 1 then 
        setVehicleOverrideLights(indicatorInfo['vehicle'], 2); 
        setVehicleLightState(indicatorInfo['vehicle'], 1, 1); 
        setVehicleLightState(indicatorInfo['vehicle'], 2, 1); 
        setElementData(indicatorInfo['vehicle'], "vehicle.override.handheld", true); 
    end 
     
    if indicatorInfo['flashed'] == true then 
        setVehicleLightState(indicatorInfo['vehicle'], 0, 1); 
        setVehicleLightState(indicatorInfo['vehicle'], 3, 1); 
        indicatorInfo['flashed'] = false; 
    else 
        setVehicleLightState(indicatorInfo['vehicle'], 0, 0); 
        setVehicleLightState(indicatorInfo['vehicle'], 3, 0); 
        indicatorInfo['flashed'] = true; 
    end 
end 
  
------- light right on 
function flashRight() 
    if getVehicleOverrideLights(indicatorInfo['vehicle']) == 1 then 
        setVehicleOverrideLights(indicatorInfo['vehicle'], 2); 
        setVehicleLightState(indicatorInfo['vehicle'], 0, 1); 
        setVehicleLightState(indicatorInfo['vehicle'], 3, 1); 
        setElementData(indicatorInfo['vehicle'], "vehicle.override.handheld", true); 
    end 
     
    if indicatorInfo['flashed'] == true then 
        setVehicleLightState(indicatorInfo['vehicle'], 1, 1); 
        setVehicleLightState(indicatorInfo['vehicle'], 2, 1); 
        indicatorInfo['flashed'] = false; 
    else 
        setVehicleLightState(indicatorInfo['vehicle'], 1, 0); 
        setVehicleLightState(indicatorInfo['vehicle'], 2, 0); 
        indicatorInfo['flashed'] = true; 
    end 
end 
  
------ light function 
function startIndicator() 
    if frameCount == 20 then 
        if indicatorInfo['left'] == true then 
            flashLeft(); 
        else 
            flashRight(); 
        end 
         
        frameCount = 0; 
    end 
     
    frameCount = frameCount + 1; 
end 
  
----lights <  > off 
function turnIndicatorOff(vehicle) 
    removeEventHandler("onClientRender", getRootElement(), startIndicator); 
    if getElementData(vehicle, "vehicle.override.handheld") == true then 
        setVehicleOverrideLights(vehicle, 1); 
        setElementData(vehicle, "vehicle.override.handheld", false); 
    end 
     
    setVehicleLightState(vehicle, 0, 0); 
    setVehicleLightState(vehicle, 1, 0); 
    setVehicleLightState(vehicle, 2, 0); 
    setVehicleLightState(vehicle, 3, 0); 
end 
  
----command function 
function cmdIndicator(cmd) 
    cmd = cmd or nil; 
    local vehicle, player; 
    player = getLocalPlayer(); 
    vehicle = getPedOccupiedVehicle(player); 
     
    local vehicleModel = tostring(getElementModel(vehicle)); 
     
     
    if not vehicle then 
        outputChatBox("You need to be in a vehicle to use this function.", player); 
        return; 
    end 
     
    if getVehicleController(vehicle) ~= player then 
        outputChatBox("You need to be the driver of this vehicle.", player); 
        return; 
    end 
  
    if cmd == CMD_LEFT_INDICATOR then 
        if isLeftOn == true then 
            -- Turn it off. 
            isLeftOn = false; 
            turnIndicatorOff(vehicle); 
             
            return; 
        end 
     
        if isRightOn == true then 
            -- Turn it off. 
            isRightOn = false; 
            turnIndicatorOff(vehicle); 
        end 
         
        indicatorInfo = { 
            flashed = false, 
            vehicle = vehicle, 
            left = true, 
        } 
         
        isLeftOn = true; 
         
        addEventHandler("onClientRender", getRootElement(), startIndicator); 
    else 
        if isRightOn == true then 
            -- Turn it off. 
            isRightOn = false; 
            turnIndicatorOff(vehicle); 
             
            return; 
        end 
         
        if isLeftOn == true then 
            -- Turn it off. 
            isLeftOn = false; 
            turnIndicatorOff(vehicle); 
        end 
         
        indicatorInfo = { 
            flashed = false, 
            vehicle = vehicle, 
            left = false, 
        } 
         
        isRightOn = true; 
         
        addEventHandler("onClientRender", getRootElement(), startIndicator); 
    end 
end 
  
addCommandHandler(CMD_LEFT_INDICATOR, cmdIndicator); 
addCommandHandler(CMD_RIGHT_INDICATOR, cmdIndicator); 
  
addEventHandler("onClientVehicleEnter", getRootElement(), function() 
    setVehicleOverrideLights(source, 1); 
end); 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() 
    bindKey(KEY_LEFT_INDICATOR, "down", CMD_LEFT_INDICATOR); 
    bindKey(KEY_RIGHT_INDICATOR, "down", CMD_RIGHT_INDICATOR); 
end); 

Link to comment

Try this:

CLIENT:

  
 
--[[ Configuration ]]--
local INDICATOR_SIZE = 0.32                     -- Size for the corona markers
local INDICATOR_COLOR = { 255, 100, 10, 255 }   -- Color in R G B A format
local INDICATOR_FADE_MS = 160                   -- Miliseconds to fade out the indicators
local INDICATOR_SWITCH_TIMES = { 300, 400 }     -- In miliseconds. First is time to switch them off, second to switch them on.
local INDICATOR_AUTOSWITCH_OFF_THRESHOLD = 62   -- A value in degrees ranging (0, 90) preferibly far from the limits.
 
 
--[[ Some globals to this context ]]--
local root = getRootElement()
local localPlayer = getLocalPlayer()
local vehiclesWithIndicator = {}
 
 
-- Precalculate some stuff
INDICATOR_AUTOSWITCH_OFF_THRESHOLD = INDICATOR_AUTOSWITCH_OFF_THRESHOLD / 90
 
 
--[[
* vectorLength
Gets the length of a vector.
--]]
local function vectorLength ( vector )
    return math.sqrt ( vector[1]*vector[1] + vector[2]*vector[2] + vector[3]*vector[3] )
end
 
--[[
* normalizeVector
Normalizes a vector, when possible, and returns the normalized vector plus the length.
--]]
local function normalizeVector ( vector )
    local length = vectorLength ( vector )
    if length > 0 then
        local normalizedVector = {}
        normalizedVector[1] = vector[1] / length
        normalizedVector[2] = vector[2] / length
        normalizedVector[3] = vector[3] / length
        return normalizedVector, length
    else
        return nil, length
    end
end
 
--[[
* crossProduct
Calculates the cross product of two vectors.
--]]
local function crossProduct ( v, w )
    local result = {}
    result[1] = v[2]*w[3] - v[3]*w[2]
    result[2] = w[1]*v[3] - w[3]*v[1]
    result[3] = v[1]*w[2] - v[2]*w[1]
    return result
end
 
--[[
* getFakeVelocity
Gets a fake unitary velocity for a vehicle calculated using the current vehicle angle.
--]]
local function getFakeVelocity ( vehicle )
    -- Get the angle around the Z axis
    local _, _, angle = getElementRotation ( vehicle )
    local velocity = { 0, 0, 0 }
    velocity[1] = -math.sin ( angle )
    velocity[2] = math.cos ( angle )
    return velocity
end
 
--[[
* createIndicator
Creates a marker for an indicator.
--]]
local function createIndicator ()
    local x, y, z = getElementPosition(localPlayer)
    local indicator = createMarker (    x, y, z+4, 'corona',
                                        INDICATOR_SIZE,
                                        INDICATOR_COLOR[1],
                                        INDICATOR_COLOR[2],
                                        INDICATOR_COLOR[3],
                                        0
                                    )
    setElementStreamable ( indicator, false )
    return indicator
end
 
--[[
* createIndicatorState
Creates a table with information about the indicators state.
--]]
local function createIndicatorState ( vehicle, indicatorLeft, indicatorRight )
    local t = { vehicle       = vehicle,        -- The vehicle that this state refers to
                left          = indicatorLeft,  -- The state of the left indicator
                right         = indicatorRight, -- The state of the right indicator
                coronaLeft    = nil,            -- The corona elements for the left indicator
                coronaRight   = nil,            -- The corona elements for the right indicator
                nextChange    = 0,              -- The time for the next change of the indicators
                timeElapsed   = 0,              -- Elapsed time since the last change
                currentState  = false,          -- If set to true, the coronas are activated.
                activationDir = nil,            -- Direction that the vehicle was following when the indicator got activated, for auto shut down.
              }
    return t
end
 
--[[
* updateIndicatorState
Updates the indicator state (i.e. creates/destroys the coronas).
--]]
local function updateIndicatorState ( state )
    if not state then return end
 
    -- Store the number of indicators activated
    local numberOfIndicators = 0
   
    -- Get the vehicle bounding box
    local xmin, ymin, zmin, xmax, ymax, zmax = getElementBoundingBox ( state.vehicle )
 
    -- Transform the bounding box positions to fit properly the vehicle
    xmin = xmin + 0.2
    xmax = xmax - 0.2
    ymin = ymin + 0.2
    ymax = ymax - 0.2
    zmin = zmin + 0.6
 
    -- Check the left indicator
    if state.left then
        if not state.coronaLeft then
            state.coronaLeft = { createIndicator (), createIndicator () }
            attachElements ( state.coronaLeft[1], state.vehicle, xmin,  ymax, zmin )
            attachElements ( state.coronaLeft[2], state.vehicle, xmin, -ymax, zmin )
        end
        numberOfIndicators = numberOfIndicators + 1
    elseif state.coronaLeft then
        destroyElement ( state.coronaLeft[1] )
        destroyElement ( state.coronaLeft[2] )
        state.coronaLeft = nil
    end
   
    -- Check the right indicator
    if state.right then
        if not state.coronaRight then
            state.coronaRight = { createIndicator (), createIndicator () }
            attachElements ( state.coronaRight[1], state.vehicle, -xmin,  ymax, zmin )
            attachElements ( state.coronaRight[2], state.vehicle, -xmin, -ymax, zmin )
        end
        numberOfIndicators = numberOfIndicators + 1
    elseif state.coronaRight then
        destroyElement ( state.coronaRight[1] )
        destroyElement ( state.coronaRight[2] )
        state.coronaRight = nil
    end
   
    -- Check if this is the car that you are driving and that there is one and only one indicator
    -- to enable auto switching off
    if numberOfIndicators == 1 and getVehicleOccupant ( state.vehicle, 0 ) == localPlayer then
        -- Store the current velocity, normalized, to check when will we have to switch it off.
        state.activationDir = normalizeVector ( { getElementVelocity ( state.vehicle ) } )
        if not state.activationDir then
            -- The vehicle is stopped, get a fake velocity from the angle.
            state.activationDir = getFakeVelocity ( state.vehicle )
        end
    else
        state.activationDir = nil
    end
end
 
--[[
* destroyIndicatorState
Destroys an indicator state, deleting all its resources.
--]]
local function destroyIndicatorState ( state )
    if not state then return end
   
    -- Destroy the left coronas
    if state.coronaLeft then
        destroyElement ( state.coronaLeft[1] )
        destroyElement ( state.coronaLeft[2] )
        state.coronaLeft = nil
    end
   
    -- Destroy the right coronas
    if state.coronaRight then
        destroyElement ( state.coronaRight[1] )
        destroyElement ( state.coronaRight[2] )
        state.coronaRight = nil
    end
   
    -- If I am the driver, reset the element data.
    if getVehicleOccupant ( state.vehicle ) == localPlayer then
        setElementData ( state.vehicle, 'i:left', false, true )
        setElementData ( state.vehicle, 'i:right', false, true )
    end
end
 
--[[
* performIndicatorChecks
Checks how the indicators state should be: created, updated or destroyed.
--]]
local function performIndicatorChecks ( vehicle )
    -- Get the current indicator states
    local indicatorLeft = getElementData(vehicle, 'i:left')
    local indicatorRight = getElementData(vehicle, 'i:right')
 
    -- Check if we at least have one indicator running
    local anyIndicator = indicatorLeft or indicatorRight
   
    -- Grab the current indicators state in the flashing period.
    local currentState = vehiclesWithIndicator [ vehicle ]
 
    -- If there's any indicator running, push it to the list of vehicles to draw the indicator.
    -- Else, remove it from the list.
    if anyIndicator then
        -- Check if there is already a state for this vehicle
        if currentState then
            -- Update the state
            currentState.left = indicatorLeft
            currentState.right = indicatorRight
        else
            -- Create a new state
            currentState = createIndicatorState ( vehicle, indicatorLeft, indicatorRight )
            vehiclesWithIndicator [ vehicle ] = currentState
        end
        updateIndicatorState ( currentState )
    elseif currentState then
        -- Destroy the current state
        destroyIndicatorState ( currentState )
        vehiclesWithIndicator [ vehicle ] = nil
    end
end
 
--[[
* setIndicatorsAlpha
Sets all the active indicators alpha.
--]]
local function setIndicatorsAlpha ( state, alpha )
    if state.coronaLeft then
        setMarkerColor ( state.coronaLeft[1],   INDICATOR_COLOR[1],
                                                INDICATOR_COLOR[2],
                                                INDICATOR_COLOR[3],
                                                alpha )
        setMarkerColor ( state.coronaLeft[2],   INDICATOR_COLOR[1],
                                                INDICATOR_COLOR[2],
                                                INDICATOR_COLOR[3],
                                                alpha )
    end
    if state.coronaRight then
        setMarkerColor ( state.coronaRight[1],  INDICATOR_COLOR[1],
                                                INDICATOR_COLOR[2],
                                                INDICATOR_COLOR[3],
                                                alpha )
       
Link to comment
  • 5 years later...

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