Erfanice Posted September 15, 2021 Share Posted September 15, 2021 Hello Guys I want him to get in the car when the player shoots. Help me, thank you Link to comment
The_GTA Posted September 15, 2021 Share Posted September 15, 2021 If I understand you correctly then you want the shooting animation and behaviour to be possible WHILE the player is also in the animation of entering or leaving a vehicle. Since this is not possible in the regular game, I think you will need a custom MTA resource. Just saying: this is not going to be as simple as you might think. Link to comment
Erfanice Posted September 15, 2021 Author Share Posted September 15, 2021 3 hours ago, The_GTA said: If I understand you correctly then you want the shooting animation and behaviour to be possible WHILE the player is also in the animation of entering or leaving a vehicle. Since this is not possible in the regular game, I think you will need a custom MTA resource. Just saying: this is not going to be as simple as you might think. Hello .. No, you didn't understand what I meant .. When a player fires at a car with a gun, the player gets in the car (( Car Controller )) Link to comment
Infinity# Posted September 16, 2021 Share Posted September 16, 2021 client.lua addEventHandler("onClientVehicleDamage", root, function(attacker, weapon, loss, x, y, z, tire) if (weapon and getElementType(source) == "vehicle" and getElementType(attacker) == "player") then triggerServerEvent("mtasa.warpPed", attacker, source) end end) server.lua addEvent("mtasa.warpPed", true) addEventHandler("mtasa.warpPed", root, function(vehicle) if (isElement(vehicle) and getElementType(vehicle) == "vehicle") then warpPedIntoVehicle(source, vehicle, 0) end end) meta.xml <meta> <script src="client.lua" type="client"/> <script src="server.lua" type="server"/> </meta> @M.Wizard Link to comment
The_GTA Posted September 16, 2021 Share Posted September 16, 2021 (edited) @Infinity#There are two flaws in your code: If two players observe vehicle damage, then both send the attacker into the vehicle, causing unnecessary network traffic that could lag the server. Since you can damage a vehicle with a shovel, this is an undesired effect. You should limit it to known weapon-ids only by checking the weapon parameter. Both can be fixed by adjusting the client.lua the following way: local function is_gun_id(id) if (type(id) == "number") and ((id >= 22 and id <= 34) or (id == 38)) then return true end return false end addEventHandler("onClientVehicleDamage", root, function(attacker, weapon, loss, x, y, z, tire) if (is_gun_id(weapon) and getElementType(source) == "vehicle" and getElementType(attacker) == "player" and attacker == localPlayer) then triggerServerEvent("mtasa.warpPed", attacker, source) end end) If you want to make it somewhat more secure you would use the "client" event variable on the serverside. Edited September 16, 2021 by The_GTA 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now