Jump to content

Working car indicators


Rolplay

Recommended Posts

So hi again!

I try to make the separatem but i cant do perfect.

This is the left side: 

local indicator_blink_duration_ms = 333;    -- time in milliseconds that the indicator should blink.
local vehicle_indicator_lights = {
		engineApplyShaderToWorldTexture(shader_right, "p", n);
        engineApplyShaderToWorldTexture(shader_left, "l", n);
};

local function getVehicleIndicatorLights(vehicle)
  if (vehicle_indicator_lights[vehicle]) then
    return vehicle_indicator_lights[vehicle];
  end

  
  local info = {};
  info.indicator_left_on = false;
  info.indicator_left_start = false;
  info.indicator_right_on = false;
  info.indicator.right_start = false;
  info.vehicle = vehicle;
  vehicle_indicator_lights[vehicle] = info;
  return info;
end

local function vehicle_left_down()
		seat = getPedOccupiedVehicleSeat(localPlayer)
		if seat then
		if seat and seat==0 then
			triggerServerEvent("onVehicleTurnOnIndicator", root, "left")
		end
		if (info.indicator_left_on == true) then
			triggerServerEvent("onVehicleTurnOffIndicator", root, "left")
	end
	end
end
bindKey("mouse1", "down", vehicle_left_down)
function destroy()
    if (getElementType(source) == "vehicle") then
    if (vehicle_indicator_lights[vehicle] == true) then
		engineRemoveShaderToWorldTexture(shader_right, "p", n)
        engineRemoveShaderToWorldTexture(shader_left, "l", n)
      vehicle_indicator_lights[source] = nil;
    end
	end
end
addEventHandler("onClientElementDestroy", root, destroy )
function left_indicator()
        local now = getTickCount();
		for _,info in pairs(vehicle_indicator_lights) do
        local vehicle = info.vehicle;
			if (indicator_left_on) then
				local passed_time_ms = now - info.indicator_left_start;
				local period = 1 - math.floor(( passed_time_ms / indicator_blink_duration_ms ) % 2);
				dxSetShaderValue(shader_left, "intensity", 1);
				if (period == 0) then
					dxSetShaderValue(shader_left, "intensity", 0);
				end
			end
		end
        -- TODO: add the same for the right indicator.
    end
addEventHandler("onClientRender", root, left_indicator)
addEvent("onClientVehicleTurnOnIndicator", true);
addEventHandler("onClientVehicleTurnOnIndicator", root, function(left_indicator)
		if (left_indicator == "left") then
		info.indicator_left_on = true;
		info.indicator_left_start = getTickCount();
		end
		end
);

addEvent("onClientVehicleTurnOffIndicator", true);
addEventHandler("onClientVehicleTurnOffIndicator", root, function(left_indicator)
		if (left_indicator == "left") then
		dxSetShaderValue(shader_left, "intensity", 0);
		info.indicator_left_on = false;
		end
  end
);

 

Link to comment
9 hours ago, Rolplay said:

I try to make the separatem but i cant do perfect.

I see that it is the same problem many times so let's look at one examplein line 29:

		if (info.indicator_left_on == true) then

Do you know about Lua tables? You don't have any "info" variable inside of this function. I think you meant to call the getVehicleIndicatorLights function with the vehicle of the local player as argument and then store the result into a local "info" variable. Try doing that at the top of that function.

Then there are many followup errors because you try to look at invalid variables like "shader_left". You forgot to create those shaders inside of the info table between like 18 and 19. And then you have to use those variable from inside the vehicle indicator light info of any vehicle table.

I recommend you to try using Lua tables! Lua tables are essential for good Lua scripters. ;) 

Edited by The_GTA
Link to comment
5 hours ago, The_GTA said:

I see that it is the same problem many times so let's look at one examplein line 29:


		if (info.indicator_left_on == true) then

Do you know about Lua tables? You don't have any "info" variable inside of this function. I think you meant to call the getVehicleIndicatorLights function with the vehicle of the local player as argument and then store the result into a local "info" variable. Try doing that at the top of that function.

Then there are many followup errors because you try to look at invalid variables like "shader_left". You forgot to create those shaders inside of the info table between like 18 and 19. And then you have to use those variable from inside the vehicle indicator light info of any vehicle table.

I recommend you to try using Lua tables! Lua tables are essential for good Lua scripters. ;) 

Thank you, i try to make that.

While i was working, i found a bug. The script changing the texture when the indicator turned on, but if it was off, there are a black texture. In small indicators that is indiscernible but in bigger indicators it is very "ugly".

U can see, if the script is'nt running, there is the texture, but if i start the script that going to black.

Link to comment
15 minutes ago, Rolplay said:

While i was working, i found a bug. The script changing the texture when the indicator turned on, but if it was off, there are a black texture. In small indicators that is indiscernible but in bigger indicators it is very "ugly".

U can see, if the script is'nt running, there is the texture, but if i start the script that going to black.

Thank you for posting about this bug. I think you can fix this by, instead of setting the indicator intensity to 0, set the indicator light intensity to a 0.2 or something close to that. Then you also have to add fog effect as well as ambient lighting of GTA:SA so that the texture looks as if it were rendered by GTA:SA. I will look into it tomorrow.

  • Like 1
Link to comment
  • 6 months later...

 

I apologize in advance for my poor English skills!


Hi, I would have a problem with this by putting in a car model and doing this index for that. But the problem would be that for all the cars that make up this car model, the total goes to the index. So if I sit in a car and have the same one next to me and I start indexing, the index will go on both cars at the same time.

https://imgur.com/YaaQ66I

https://imgur.com/424xkSF

https://imgur.com/z3YkRox

 

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