The_GTA

Members
  • Content Count

    244
  • Joined

  • Last visited

  • Days Won

    16

The_GTA last won the day on March 29

The_GTA had the most liked content!

Community Reputation

105 Excellent

5 Followers

About The_GTA

  • Rank
    Red-Headed Stepchild

Recent Profile Visitors

1,353 profile views
  1. This is not that hard. If the player was already inside of the rectangle then you can remember his last position inside it and just reset him back to that position, like... local last_valid_player_pos = {}; local shape; -- the colshape. setTimer( function() for m,n in ipairs(getElementsByType("player")) do if (isElementWithinColShape(n, shape)) then last_valid_player_pos[n] = { getElementPosition(n) }; else local last_valid_pos = last_valid_player_pos[n]; if (last_valid_pos) then setElementPosition(n, unpack(last_valid_pos)); end end end end, 1000, 0 ); If you want to handle vehicles aswell then you have to extend the script. You also should handle the case if the script is started when the player was never inside the rectangle.
  2. Hello matin, this looks like a mathematical problem. What you want to calculate is the line intersection between the player position and a 2D rectangle. But I don't know where exactly the player should be dragged back to. Do you want push the player toward the center of the rectangle? Or do you want to pick the closest distance to the rectangle?
  3. No, you just have to replace the 1 within the original script with something more fitting. I don't want to give it away, it is the point of the exercise, it is really easy, but you have to understand how Lua scripting works. Let's say that I did the groundwork already. Hint #1: the variable period is a number that switches between 1 and 0 in 500ms time distances.
  4. The_GTA

    Weapon Block

    Then you need to patch the freeroam resource using the hasObjectPermissionTo function across all functions (giveMeWeapon, etc) so that the ACL priviledges are honored.
  5. Hello DigDim, did you know that MTA's Lua functions require different arguments on client-side than on server-side despite being shared functions? outputChatBox ("function TagStaffInvisible Chamada", thePlayer) Here you have used "thePlayer" as second parameter to outputChatBox but that is wrong. You can just remove that parameter because it is executed on the client and on every client there is only one chatbox. Did you also know that you can use the /debugscript command in the MTA client to find out about errors in your script?
  6. Hello iwalidza, if you want to have the camera move around in a circle around a point then you can simply use the math.sin and math.cos functions of Lua in combination with MTA's setCameraMatrix function local cam_move_start = getTickCount(); local cam_radius = 50; local cam_move_circle_duration = 15000; local cam_move_angle_start = 0; local cam_movearound_point_x = 0; local cam_movearound_point_y = 0; local cam_movearound_point_z = 0; local cam_height_offset = 20; local function get_camera_point_circular() local now = getTickCount(); local passed_time = now - cam_move_start; local progress_circle = passed_time / cam_move_circle_duration; local cam_current_angle = math.rad(cam_move_angle_start + progress_circle * 360); local cam_pos_x = cam_movearound_point_x + cam_radius * math.cos(cam_current_angle); local cam_pos_y = cam_movearound_point_y + cam_radius * math.sin(cam_current_angle); return cam_pos_x, cam_pos_y, cam_pos_z + cam_height_offset; end addEventHandler("onClientPreRender", root, function() local cam_pos_x, cam_pos_y, cam_pos_z = get_camera_point_circular(); setCameraMatrix(cam_pos_x, cam_pos_y, cam_pos_z, cam_movearound_point_x, cam_movearound_point_y, cam_movearound_point_z); end ); (code has not been tested) The math.cos and math.sin functions are used to model a circle in math. You should learn about those in your school math classes. Extended knowledge can be gained in University which I highly recommend to attend to! - Martin
  7. I am back after sleeping (GMT+1). So let's hook up your functions to a key bind, shall we? Here is the improved sample code: improved shader code: texture Tex0 < string textureState="0,Texture"; >; float4x4 World; float4x4 View; float4x4 Projection; float4x4 WorldViewProjection; float Time; float intensity = 0; sampler Sampler0 = sampler_state { Texture = (Tex0); }; struct VSInput { float3 Position : POSITION; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; struct PSInput { float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; struct VSOutput { PSInput psInput; float4 Position : POSITION; }; VSOutput PassthroughVS(VSInput input) { VSOutput output; output.psInput.Diffuse = input.Diffuse; output.psInput.TexCoord = input.TexCoord; //-- Transform vertex position (You nearly always have to do something like this) output.Position = mul(float4(input.Position, 1), WorldViewProjection); return output; } float4 IndicatorMultiply(PSInput input) : COLOR0 { float4 texColor = tex2D(Sampler0, input.TexCoord); return texColor * intensity; } technique indicators { pass P0 { VertexShader = compile vs_2_0 PassthroughVS(); PixelShader = compile ps_2_0 IndicatorMultiply(); } }; client-side Lua code: local vehicleTXD = engineLoadTXD("car.txd"); engineImportTXD(vehicleTXD, 400); local vehicleDFF = engineLoadDFF("car.dff", 400); engineReplaceModel(vehicleDFF, 400); local shader_left = dxCreateShader("indicatorshader.fx"); local shader_right = dxCreateShader("indicatorshader.fx"); outputChatBox("Loaded indicator lights shader and car model!"); for m,n in ipairs(getElementsByType("vehicle")) do if (getElementModel(n) == 400) then engineApplyShaderToWorldTexture(shader_right, "p", n); engineApplyShaderToWorldTexture(shader_left, "l", n); end end -- Starting time in milliseconds for the indicators. local indicator_blink_duration_ms = 500; -- time in milliseconds that the indicator should blink. local indicator_left_on = false; -- is the left indicator on? local indicator_left_start; local indicator_right_on = false; local indicator_right_start; local function vehicle_left_down() indicator_left_on = true; indicator_left_start = getTickCount(); end bindKey("vehicle_left", "down", vehicle_left_down) local function vehicle_left_up() dxSetShaderValue(shader_left, "intensity", 0); indicator_left_on = false; end bindKey("vehicle_left", "up", vehicle_left_up) -- TODO: add key binds for the right indicator. addEventHandler("onClientRender", root, function() local now = getTickCount(); if (indicator_left_on) then local passed_time_ms = now - indicator_left_start; local period = 1 - math.floor(( passed_time_ms / indicator_blink_duration_ms ) % 2); -- TODO: write 1 to intensity if the blinker is on, write 0 if the blinker if off. -- the blinker is off if the variable "period" is 0, the blinker is on if it is 1. dxSetShaderValue(shader_left, "intensity", 1); end -- TODO: add the same for the right indicator. end ); -- TODO: make sure the logic is synchronized across clients. -- TODO: make sure that each vehicle has its own indicator blinking start time, on/off switch, shader; right now each vehicle shares the same indicator logic. I did some non-trivial improvement on the shader code so that it reads from the GTA:SA texture instead of a fixed color. Seeing that you have some trouble coding in Lua I have helped you out again. The Lua code is not done yet. There are several exercises left for you: how do you implement blinking to the left indicator? (easy) how do you implement the indicator light for the right indicators? (easy) how to synchronize the indicator lights across multiple game clients? (medium) how to allow indicator lights for each vehicle separately? (hard) Try doing the above exercises to finish your indicator lights script. I think that you should be able to do the first two points. If you have any trouble further down the line then feel free to ask
  8. Sure! You can use the dxSetShaderValue function to set a float value "intensity" and define it as global in the HLSL script. Then you can multiply the color with it inside of the "IndicatorMultiply" pixel shader function. In your client.Lua script you set intensity to 0 if the indicator lights are disabled and to 1 if they are enabled. Use the bindKey function with the "vehicle_left" and "vehicle_right" controls in combination with the intensity shader variable to achieve that. I have not investigated which of "p" or "l" is the left or right indicator texture. I would be very thankful if you could investigate and answer this question for us.
  9. The script just works if you put the car.dff (copcarla.dff) and car.txd (copcarla.txd) into the resource because "p" and "l" are inside of the car.txd file, like shown in Magic.TXD above. meta.xml <meta> <file src="indicatorshader.fx" type="client" /> <file src="car.dff" type="client" /> <file src="car.txd" type="client" /> <script src="client.Lua" type="client" /> </meta>
  10. The_GTA

    Weapon Block

    Does the freeroam resource even check the player ACL for permission? No, it does not. If you use the freeroam GUI then either everyone gets the weapons or nobody. Do you really need the F1 GUI in your server?
  11. I have hacked together a little HLSL sample script for you. It is up to you to actually implement indicator light logic to this: indicatorshader.fx texture Tex0; float4x4 World; float4x4 View; float4x4 Projection; float4x4 WorldViewProjection; float Time; sampler Sampler0 = sampler_state { Texture = (Tex0); }; struct VSInput { float3 Position : POSITION; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; struct PSInput { float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; struct VSOutput { PSInput psInput; float4 Position : POSITION; }; VSOutput PassthroughVS(VSInput input) { VSOutput output; output.psInput.Diffuse = input.Diffuse; output.psInput.TexCoord = input.TexCoord; //-- Transform vertex position (You nearly always have to do something like this) output.Position = mul(float4(input.Position, 1), WorldViewProjection); return output; } float4 IndicatorMultiply(PSInput input) : COLOR0 { return float4(1, 1, 0, 1); } technique indicators { pass P0 { VertexShader = compile vs_2_0 PassthroughVS(); PixelShader = compile ps_2_0 IndicatorMultiply(); } }; client.Lua local vehicleTXD = engineLoadTXD("car.txd"); engineImportTXD(vehicleTXD, 400); local vehicleDFF = engineLoadDFF("car.dff", 400); engineReplaceModel(vehicleDFF, 400); local shader = dxCreateShader("indicatorshader.fx"); outputChatBox("Loaded indicator lights shader and car model!"); for m,n in ipairs(getElementsByType("vehicle")) do if (getElementModel(n) == 400) then engineApplyShaderToWorldTexture(shader, "p", n); engineApplyShaderToWorldTexture(shader, "l", n); end end As you can see the script uses the Landstalker vehicle as an example. Just spawn a Landstalker and start the resource. You should see the indicator lights in yellow color. Take a look at the MTA wiki to find out more about shaders. You can find really cool effects over there!
  12. Hello Rolplay, I have checked out the mod with Magic.TXD and the TXD does contain the following indicator textures named "p" and "l": In order to apply special effects to these textures I recommend using the engineApplyShaderToWorldTexture function with textures named "p" and "l". With this function you can multiply the color of the indicator lights to make it brighter or darker depending on your style But you have to know how to code in HLSL to do this. Learning shader languages is really worth it!
  13. This is getting pretty shady 🤣 🚓🚓🚓 But sorry I cannot recommend any reliable MP3 conversion service that will continue to exist and has a HTTP API.
  14. Yes. If you typed /testcmd into the chat you would see that (you did). Looking at string representations of variables is a daily driver for debugging MTA:SA Lua scripts.
  15. Good idea! Honestly I would prefer if there was a direct MTA function for checking this, but sometimes we have to create makeshift solutions like this which approximate the issue just right