Skip to content

Commit

Permalink
add health, armour and animation natives
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Oct 20, 2024
1 parent 5980d0f commit 3e101db
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SDK
20 changes: 20 additions & 0 deletions Server/Components/NPCs/NPC/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,26 @@ void NPC::setVelocity(Vector3 velocity, bool update)
needsVelocityUpdate_ = update;
}

void NPC::setHealth(float health)
{
footSync_.HealthArmour.x = health;
}

float NPC::getHealth() const
{
return footSync_.HealthArmour.x;
}

void NPC::setArmour(float armour)
{
footSync_.HealthArmour.y = armour;
}

float NPC::getArmour() const
{
return footSync_.HealthArmour.y;
}

void NPC::sendFootSync()
{
// Only send foot sync if player is spawned
Expand Down
8 changes: 8 additions & 0 deletions Server/Components/NPCs/NPC/npc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class NPC : public INPC, public PoolIDProvider, public NoCopy

void setVelocity(Vector3 position, bool update = false) override;

void setHealth(float health) override;

float getHealth() const override;

void setArmour(float armour) override;

float getArmour() const override;

void sendFootSync();

void tick(Microseconds elapsed, TimePoint now);
Expand Down
29 changes: 29 additions & 0 deletions Server/Components/Pawn/Scripting/NPC/Natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,32 @@ SCRIPT_API(NPC_GetInterior, int(INPC& npc))
{
return npc.getInterior();
}

SCRIPT_API(NPC_SetHealth, bool(INPC& npc, float health))
{
npc.setHealth(health);
return true;
}

SCRIPT_API(NPC_GetHealth, float(INPC& npc))
{
return npc.getHealth();
}

SCRIPT_API(NPC_SetArmour, bool(INPC& npc, float armour))
{
npc.setArmour(armour);
return true;
}

SCRIPT_API(NPC_GetArmour, float(INPC& npc))
{
return npc.getArmour();
}

SCRIPT_API(NPC_ApplyAnimation, bool(INPC& npc, const std::string& animlib, const std::string& animname, float delta, bool loop, bool lockX, bool lockY, bool freeze, uint32_t time, int sync))
{
const AnimationData animationData(delta, loop, lockX, lockY, freeze, time, animlib, animname);
npc.getPlayer()->applyAnimation(animationData, PlayerAnimationSyncType_SyncOthers);
return true;
}

0 comments on commit 3e101db

Please sign in to comment.