Jump to content

"onClientPlayerWeaponFire" Trouble


Recommended Posts

Hello!

I am trying to make it so that:

A) Every time a player fires a Silenced Pistol, a Satchel is placed at the pistol's target.

B) Every time the Satchel Detonator is used, a detonation sound is played.

I have made a script for this, but it is not working:

client.lua

-- This function gets triggered everytime player shoots.
function onClientPlayerWeaponFireFunc(weapon,ammo,ammoInClip,hitX,hitY,hitZ,hitElement)
if weapon == 23 then -- If Silenced Pistol is Used...
local aimSpot = getPedTarget(getLocalPlayer())
if aimSpot then
createProjectile(getLocalPlayer(),39,getElementPosition(aimSpot)) then -- Then Create a Satchel at Target if Targeting
outputChatBox("Satchel Created", source)
else
outputChatBox("no target!", source)
end
end
 
if weapon == 40 then -- If Satchel Detonator is Used...
local satchSnd = playSound("detonate.mp3") -- Play Detonation Sound
end
end
 
-- Don't forget to add the onClientPlayerWeaponFireFunc function as a handler for onClientPlayerWeaponFire.
addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFireFunc)

I have a folder named modweapons where I put my three files in it; the script above, detonate.mp3, and this meta.xml file:

<meta>
  <info type="script" author="Cecil G. Bowen" Version="1.0" name="ModWeapons" />
  <script src="script.lua" type="client" />
  <file src="detonate.mp3" />
</meta>

Help would be really appreciated!

Thanks in advance!

Link to comment

there is some redundancy to your script, using OnClientPlayerWeaponFire alows you with args for weapon, ammo, ammoInClip, hitX, hitY, hitZ, and hitElement.

so no need to get target since its already supplied xyz coords and if you hit an element it gives you the element.

Link to comment

Okay I just edited the code a little and this works, though it is more limited:

function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement )
if weapon == 23 and getElementType(hitElement)=="vehicle" then -- If the player shoots with a minigun, and hits another player...
createProjectile(getLocalPlayer(),39,hitX,hitY,hitZ)
end
end
-- Add this as a handler so that the function will be triggered every time the local player fires.
addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFireFunc )

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