Jump to content

[Help] Gun


Erfanice

Recommended Posts

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

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

@Infinity#There are two flaws in your code:

  1. If two players observe vehicle damage, then both send the attacker into the vehicle, causing unnecessary network traffic that could lag the server.
  2. 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 by The_GTA
  • Thanks 1
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...