OnPlayerWeaponShot: Difference between revisions
From Onset Developer Wiki
Created page with "{{Info|Event|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|OnPlayerWeaponShot}} {{FuncParameters}} == Example == __EDIT_ME__ {{RelatedFunctions}} {{ServerEvents}}" |
No edit summary |
||
(15 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Info|Event|Server|1.0}} | {{Info|Event|Server & Client|1.0}} | ||
{{FuncDescription| | {{FuncDescription|Called when a player has shot their weapon and the hit was authorized by the server but not yet processed its impact. You can call return '''false''' in this event to prevent this hit from further processing. (Server only)}} | ||
{{FuncSyntax|OnPlayerWeaponShot}} | {{FuncSyntax|OnPlayerWeaponShot(player, weapon, hittype, hitid, hitX, hitY, hitZ, startX, startY, startZ, normalX, normalY, normalZ, BoneName)}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
== Example == | {{FuncParam|player|The player that has shot the weapon.}} | ||
{{FuncParam|weapon|Weapon model id.}} | |||
{{FuncParam|hittype|The [[HitType|type of entity]] which was hit.}} | |||
{{FuncParam|hitid|The identifier of the entity which was hit.}} | |||
{{FuncParam|hitX|The X coordinate of this hit.}} | |||
{{FuncParam|hitY|The Y coordinate of this hit.}} | |||
{{FuncParam|hitZ|The Z coordinate of this hit.}} | |||
{{FuncParam|startX|The X coordinate of where this shot started from.}} | |||
{{FuncParam|startY|The Y coordinate of where this shot started from.}} | |||
{{FuncParam|startZ|The Z coordinate of where this shot started from.}} | |||
{{FuncParam|normalX|Impact normal X of the hit.}} | |||
{{FuncParam|normalY|Impact normal Y of the hit.}} | |||
{{FuncParam|normalZ|Impact normal Z of the hit.}} | |||
{{FuncParam|BoneName|Bone name of this hit. (For players)}} | |||
== Example Server == | |||
<syntaxhighlight lang="Lua"> | |||
function OnPlayerWeaponShot(player, weapon, hittype, hitid, hitx, hity, hitz, startx, starty, startz, normalx, normaly, normalz, BoneName) | |||
local action = { | |||
"in the air", | |||
"at player", | |||
"at vehicle", | |||
"an NPC", | |||
"at object", | |||
"on ground", | |||
"in water" | |||
} | |||
print(GetPlayerName(player).."("..player..") shot "..action[hittype].." (ID "..hitid..") using weapon ("..weapon..")") | |||
if (hittype == HIT_NPC) then | |||
AddPlayerChat(player, "Hey you, don't shoot at NPCs!") | |||
end | |||
end | |||
AddEvent("OnPlayerWeaponShot", OnPlayerWeaponShot) | |||
</syntaxhighlight> | |||
== Example Client == | |||
The parameters on the client are slightly different. If you want to detect weapon shots on the client for other players you can use [[OnPlayWeaponHitEffects]]. | |||
<syntaxhighlight lang="Lua"> | |||
function OnPlayerWeaponShot(weaponid, hittype, hitid, hitX, hitY, hitZ, startX, startY, startZ, normalX, normalY, normalZ, BoneName) | |||
print(hitX, hitY, hitZ) | |||
end | |||
AddEvent("OnPlayerWeaponShot", OnPlayerWeaponShot) | |||
</syntaxhighlight> | |||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
{{ | {{PlayerEvents}} |
Latest revision as of 12:14, 4 November 2020
Description
Called when a player has shot their weapon and the hit was authorized by the server but not yet processed its impact. You can call return false in this event to prevent this hit from further processing. (Server only)
Syntax
OnPlayerWeaponShot(player, weapon, hittype, hitid, hitX, hitY, hitZ, startX, startY, startZ, normalX, normalY, normalZ, BoneName)
Parameters
- player
The player that has shot the weapon. - weapon
Weapon model id. - hittype
The type of entity which was hit. - hitid
The identifier of the entity which was hit. - hitX
The X coordinate of this hit. - hitY
The Y coordinate of this hit. - hitZ
The Z coordinate of this hit. - startX
The X coordinate of where this shot started from. - startY
The Y coordinate of where this shot started from. - startZ
The Z coordinate of where this shot started from. - normalX
Impact normal X of the hit. - normalY
Impact normal Y of the hit. - normalZ
Impact normal Z of the hit. - BoneName
Bone name of this hit. (For players)
Example Server
function OnPlayerWeaponShot(player, weapon, hittype, hitid, hitx, hity, hitz, startx, starty, startz, normalx, normaly, normalz, BoneName)
local action = {
"in the air",
"at player",
"at vehicle",
"an NPC",
"at object",
"on ground",
"in water"
}
print(GetPlayerName(player).."("..player..") shot "..action[hittype].." (ID "..hitid..") using weapon ("..weapon..")")
if (hittype == HIT_NPC) then
AddPlayerChat(player, "Hey you, don't shoot at NPCs!")
end
end
AddEvent("OnPlayerWeaponShot", OnPlayerWeaponShot)
Example Client
The parameters on the client are slightly different. If you want to detect weapon shots on the client for other players you can use OnPlayWeaponHitEffects.
function OnPlayerWeaponShot(weaponid, hittype, hitid, hitX, hitY, hitZ, startX, startY, startZ, normalX, normalY, normalZ, BoneName)
print(hitX, hitY, hitZ)
end
AddEvent("OnPlayerWeaponShot", OnPlayerWeaponShot)
See also
- OnPlayerServerAuth
- OnPlayerSteamAuth
- OnPlayerStreamIn
- OnPlayerStreamOut
- OnPlayerJoin
- OnPlayerQuit
- OnPlayerSpawn
- OnPlayerDeath
- OnPlayerWeaponShot
- OnPlayerDamage
- OnPlayerChat
- OnPlayerChatCommand
- OnPlayerInteractDoor
- OnPlayWeaponHitEffects
- OnPlayerSwitchCamera
- OnPlayerEnterWater
- OnPlayerLeaveWater
- OnPlayerCrouch
- OnPlayerEndCrouch
- OnPlayerEndFall
- OnPlayerFall
- OnPlayerTalking