Skip to content

Commit

Permalink
call pawn events
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Jan 31, 2025
1 parent a763ece commit 5e462c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions Server/Components/NPCs/npcs_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void NPCComponent::onInit(IComponentList* components)
{
npcNetwork.init(core, this);
core->getEventDispatcher().addEventHandler(this);
core->getPlayers().getPlayerDamageDispatcher().addEventHandler(this);
}

void NPCComponent::free()
Expand Down
16 changes: 16 additions & 0 deletions Server/Components/Pawn/Scripting/NPC/Events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ struct NPCEvents : public NPCEventHandler, public Singleton<NPCEvents>
{
PawnManager::Get()->CallAllInEntryFirst("OnNPCDestroy", DefaultReturnValue_True, npc.getID());
}

void onNPCWeaponStateChange(INPC& npc, PlayerWeaponState newState, PlayerWeaponState oldState) override
{
PawnManager::Get()->CallAllInEntryFirst("OnNPCWeaponStateChange", DefaultReturnValue_True, npc.getID(), int(newState), int(oldState));
}

bool onNPCTakeDamage(INPC& npc, IPlayer& damager, float damage, uint8_t weapon, BodyPart bodyPart) override
{
auto result = !!PawnManager::Get()->CallAllInEntryFirst("OnNPCTakeDamage", DefaultReturnValue_True, npc.getID(), damager.getID(), damage, weapon, int(bodyPart));
return result;
}

void onNPCDeath(INPC& npc, IPlayer* killer, int reason) override
{
PawnManager::Get()->CallAllInEntryFirst("OnNPCDeath", DefaultReturnValue_True, npc.getID(), killer ? killer->getID() : INVALID_PLAYER_ID, reason);
}
};
18 changes: 9 additions & 9 deletions Server/Components/Pawn/Scripting/NPC/Natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,25 @@ SCRIPT_API(NPC_GetAmmo, int(INPC& npc))
return npc.getAmmo();
}

SCRIPT_API(NPC_SetWeaponSkillLevel, bool(INPC& npc, uint8_t skill, int level))
SCRIPT_API(NPC_SetKeys, bool(INPC& npc, uint16_t upAndDown, uint16_t leftAndDown, uint16_t keys))
{
npc.setWeaponSkillLevel(PlayerWeaponSkill(skill), level);
npc.setKeys(upAndDown, leftAndDown, keys);
return true;
}

SCRIPT_API(NPC_GetWeaponSkillLevel, int(INPC& npc, int skill))
SCRIPT_API(NPC_GetKeys, bool(INPC& npc, uint16_t& upAndDown, uint16_t& leftAndDown, uint16_t& keys))
{
return npc.getWeaponSkillLevel(PlayerWeaponSkill(skill));
npc.getKeys(upAndDown, leftAndDown, keys);
return true;
}

SCRIPT_API(NPC_SetKeys, bool(INPC& npc, uint16_t upAndDown, uint16_t leftAndDown, uint16_t keys))
SCRIPT_API(NPC_SetWeaponSkillLevel, bool(INPC& npc, uint8_t skill, int level))
{
npc.setKeys(upAndDown, leftAndDown, keys);
npc.setWeaponSkillLevel(PlayerWeaponSkill(skill), level);
return true;
}

SCRIPT_API(NPC_GetKeys, bool(INPC& npc, uint16_t& upAndDown, uint16_t& leftAndDown, uint16_t& keys))
SCRIPT_API(NPC_GetWeaponSkillLevel, int(INPC& npc, int skill))
{
npc.getKeys(upAndDown, leftAndDown, keys);
return true;
return npc.getWeaponSkillLevel(PlayerWeaponSkill(skill));
}

0 comments on commit 5e462c1

Please sign in to comment.