LibAction: Difference between revisions

From NPC for VCMP 0.4 Servers
Jump to navigation Jump to search
Line 24: Line 24:
<poem>Called when target is out of range of the weaponrange of the current weapon of npc. If target is not cleared, npc resumes shooting when target comes in range again.   
<poem>Called when target is out of range of the weaponrange of the current weapon of npc. If target is not cleared, npc resumes shooting when target comes in range again.   
</poem>
</poem>
3. '''OnPullingTrigger'''
3. '''OnPullTrigger'''
<source lang="lua">
<source lang="lua">
OnPullingTrigger([integer] keys, [Vector]pos,  [float]angle, [integer]health, [integer]armour, [integer]weapon, [integer]ammo, [Vector]speed, [Vector]aimpos, [Vector]aimdir, [bool]isCrouching, [bool]isReloading )
OnPullTrigger([integer] keys, [Vector]pos,  [float]angle, [integer]health, [integer]armour, [integer]weapon, [integer]ammo, [Vector]speed, [Vector]aimpos, [Vector]aimdir, [bool]isCrouching, [bool]isReloading )
</source>
</source>
<poem>This event is called just before sending the Aiming Packet( with decreased ammo) to server. The purpose is to manually change the aimpos/aimdir for accuracy.
<poem>This event is called just before sending the Aiming Packet( with decreased ammo) to server. The purpose is to manually change the aimpos/aimdir for accuracy.
To manually change, Call [[SendOnFootSyncDataEx]] at this point and then return false.
To manually change, Call [[SendOnFootSyncDataEx]] at this point and then return false.
<source lang="lua">
function OnPullTrigger(keys, pos, angle, health, armour, weapon, ammo, speed, aimpos, aimdir, isCrouching, isReloading)
{
    local aimpos=... //changing or correcting
    local aimdir= ...
    ...
    SendOnFootSyncDataEx(keys, pos, angle, health, armour, weapon, ammo, speed, aimpos, aimdir, isCrouching, isReloading);
    return false;//we send it and library need not send it again.
}
</source>
The automatic sending of aim packet depends on the return value of this function:</poem>
The automatic sending of aim packet depends on the return value of this function:</poem>
{| class="wikitable"  
{| class="wikitable"  
Line 49: Line 59:
|  
|  
|}
|}
==Functions==
==Functions==
1. '''ShootPlayer'''
1. '''ShootPlayer'''

Revision as of 04:45, 20 February 2023

Features

  • Single command ShootPlayer( pid ) and npc starts shooting at the player.
  • Aim Pos and Aim Dir for shooting are internally calculated and user has the option to correct it for more accuracy.
  • Rich callbacks: just before shooting (for correction of aimpos/dir), target out of range or ran out of ammo/gun.
  • No timers/loops.
  • Internally calculate clipsize, firing rate of weapons and do the reloading animation too.

Callbacks

1. OnTargetCleared

OnTargetCleared([integer]targetpid, [integer]reason)

The value of reason can be:

Constant
AMMO_SHORTAGE
PLAYER_STREAMEDOUT
INSTRUCTION_RECEIVED

2. OnTargetOutOfRange

OnTargetOutOfRange([integer]targetid)

Called when target is out of range of the weaponrange of the current weapon of npc. If target is not cleared, npc resumes shooting when target comes in range again.

3. OnPullTrigger

OnPullTrigger([integer] keys, [Vector]pos,  [float]angle, [integer]health, [integer]armour, [integer]weapon, [integer]ammo, [Vector]speed, [Vector]aimpos, [Vector]aimdir, [bool]isCrouching, [bool]isReloading )

This event is called just before sending the Aiming Packet( with decreased ammo) to server. The purpose is to manually change the aimpos/aimdir for accuracy.
To manually change, Call SendOnFootSyncDataEx at this point and then return false.

'"`UNIQ--item-11--QINU`"'
function OnPullTrigger(keys, pos, angle, health, armour, weapon, ammo, speed, aimpos, aimdir, isCrouching, isReloading)'"`UNIQ--item-11--QINU`"'
{'"`UNIQ--item-11--QINU`"'
&#160;&#160;&#160;&#160;local aimpos=... //changing or correcting'"`UNIQ--item-11--QINU`"'
&#160;&#160;&#160;&#160;local aimdir= ...'"`UNIQ--item-11--QINU`"'
&#160;&#160;&#160;&#160;...'"`UNIQ--item-11--QINU`"'
&#160;&#160;&#160;&#160;SendOnFootSyncDataEx(keys, pos, angle, health, armour, weapon, ammo, speed, aimpos, aimdir, isCrouching, isReloading);'"`UNIQ--item-11--QINU`"'
&#160;&#160;&#160;&#160;return false;//we send it and library need not send it again.'"`UNIQ--item-11--QINU`"'
}'"`UNIQ--item-11--QINU`"'

The automatic sending of aim packet depends on the return value of this function:

return value
false will not send packet, assuming the user send it using SendOnFootSyncDataEx or similar functions
0 "
null (or no return value) "

Functions

1. ShootPlayer

ShootPlayer([integer]playerid)

The npc pickup a gun from it's available weapons and starts shooting at the player. To shoot with a specific gun set the weapon of npc prior to the call. From npcscripts this can be done using SetLocalValue with field I_CURWEP
return value: true on success, false on failure (player not streamed in or no proper gun available)

2. ClearTarget

ClearTarget()

Clears the target and calls OnTargetCleared with reason as INSTRUCTION_RECEIVED
return vaue: true (if the npc had a target) or false( if the npc did not had a target)

3. GetTarget

GetTarget()

return value: The player ID of the target or -1 if there is no target.