Skip to content

Commit

Permalink
add set and get weapon accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Feb 5, 2025
1 parent b29015b commit f4e9095
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SDK
21 changes: 21 additions & 0 deletions Server/Components/NPCs/NPC/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,27 @@ bool NPC::isAimingAtPlayer(IPlayer& player) const
return aiming_ && hitType_ == PlayerBulletHitType_Player && hitId_ == player.getID();
}

void NPC::setWeaponAccuracy(uint8_t weapon, float accuracy)
{
auto data = WeaponSlotData(weapon);
if (data.slot() != INVALID_WEAPON_SLOT && weapon < weaponAccuracy.size())
{
weaponAccuracy[weapon] = accuracy;
}
}

float NPC::getWeaponAccuracy(uint8_t weapon) const
{
float ret = 0.0f;
auto data = WeaponSlotData(weapon);
if (data.slot() != INVALID_WEAPON_SLOT && weapon < weaponAccuracy.size())
{
ret = weaponAccuracy[weapon];
}

return ret;
}

void NPC::setWeaponState(PlayerWeaponState state)
{
if (state == PlayerWeaponState_Unknown)
Expand Down
4 changes: 4 additions & 0 deletions Server/Components/NPCs/NPC/npc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class NPC : public INPC, public PoolIDProvider, public NoCopy

bool isAimingAtPlayer(IPlayer& player) const override;

void setWeaponAccuracy(uint8_t weapon, float accuracy) override;

float getWeaponAccuracy(uint8_t weapon) const override;

void setWeaponState(PlayerWeaponState state);

void updateWeaponState();
Expand Down
11 changes: 11 additions & 0 deletions Server/Components/Pawn/Scripting/NPC/Natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,14 @@ SCRIPT_API(NPC_IsAimingAtPlayer, bool(INPC& npc, IPlayer& atPlayer))
{
return npc.isAimingAtPlayer(atPlayer);
}

SCRIPT_API(NPC_SetWeaponAccuracy, bool(INPC& npc, int weapon, float accuracy))
{
npc.setWeaponAccuracy(weapon, accuracy);
return true;
}

SCRIPT_API(NPC_GetWeaponAccuracy, float(INPC& npc, int weapon))
{
return npc.getWeaponAccuracy(weapon);
}

0 comments on commit f4e9095

Please sign in to comment.