Jump to content

CreateWeapon dont hurt others


Recommended Posts

function StandardWep()
	local x, y, z = getElementPosition(getLocalPlayer())
	
	wep = createWeapon("m4", x+5, y, z)

	setWeaponFlags(wep, "shoot_if_blocked", false)
	
	setWeaponFiringRate(wep, 35)
	
	setWeaponProperty(wep, "damage", 25)
	
	setWeaponClipAmmo(wep, 35)
	
	setWeaponAmmo(wep, 100)
end

addCommandHandler("OnStandardWep", function(command, state)
    local s = string.upper(state)
	  if s=="ON" then
      	setWeaponState(wepM16, "firing")
      elseif s=="false" then
      	setWeaponState(wepM16, "ready")
      else
      	outputChatBox("There is no such condition of the weapon, you can only use 'ON / OFF'", 255, 50, 0)
      end
  end
)

The point is that it does not hurt other players, what's more, other players do not even see the line of fire (I mean the yellow line which means how fast the bullets are moving and in which direction) and the weapon itself (M4), I know that you need to use triggerClientEvent but no I know how to apply it, please help me with an example  ; -;

Link to comment

This should work. This snippet will create a weapon for every player though. To control the weapon's firing state you'll need to store the weapon element somehow and trigger another clientEvent when a player types the command.

 

CLIENT

addEvent("weapon:onClientCreateWeapon", true)

function OnClientCreateWeapon(targetPlayer)

	local radius = 1
	local x, y, z = getElementPosition(targetPlayer)
	local _, _, rz = getElementRotation(targetPlayer)
	local tx = x + -(radius) * math.sin(math.rad(rz))
	local ty = y + radius * math.cos(math.rad(rz))
	local weaponElem = createWeapon("m4", tx, ty, z)

	setElementRotation(weaponElem, 0, 0, rz + 90)

	setWeaponFlags(weaponElem, "shoot_if_blocked", false)
	setWeaponFiringRate(weaponElem, 35)
	setWeaponProperty(weaponElem, "damage", 25)
	setWeaponClipAmmo(weaponElem, 35)
	setWeaponAmmo(weaponElem, 100)

	setWeaponState(weaponElem, "firing")
end

function OnClientResourceStart()

	triggerServerEvent("weapon:onCreateWeapon", localPlayer)
end

addEventHandler("weapon:onClientCreateWeapon", root, OnClientCreateWeapon)
addEventHandler("onClientResourceStart", resourceRoot, OnClientResourceStart)

SERVER

addEvent("weapon:onCreateWeapon", true)

function OnCreateWeapon()
	
	triggerClientEvent(root, "weapon:onClientCreateWeapon", resourceRoot, client);
end

addEventHandler("weapon:onCreateWeapon", root, OnCreateWeapon)

 

Edited by Jesseunit
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...