Skip to content

Commit

Permalink
Fixed callbacks incorrect order
Browse files Browse the repository at this point in the history
Altered event handling behavior on fail
updated sdk
SendClientMessage native
  • Loading branch information
Battlerax committed Apr 14, 2019
1 parent 8442e22 commit a26ddc4
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 83 deletions.
66 changes: 30 additions & 36 deletions RagePawn/callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ class EventHandler :
IBlipHandler *GetBlipHandler() override { return this; }
ITickHandler *GetTickHandler() override { return this; }

// forward OnIncomingConnection(playerid, ip_address[], serial[])
// forward OnIncomingConnection(playerid, ip_address[])
// todo: different than on samp: http://wiki.sa-mp.com/wiki/OnIncomingConnection
void OnPlayerJoin(rage::IPlayer* player) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnIncomingConnection", "d", (int)player->GetId(), "s", player->GetIp().c_str(), "s", player->GetSerial().c_str());
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnIncomingConnection", "sd", player->GetIp().c_str(), (int)player->GetId());
}

// forward OnPlayerConnect(playerid);
void OnPlayerReady(rage::IPlayer *player) override
{
for (auto &script : scripts)
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerConnect", "d", (int)player->GetId());
}

Expand Down Expand Up @@ -62,7 +62,7 @@ class EventHandler :
}

for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerConnect", "d", (int)player->GetId(), "d", result, "s", reason ? reason : "");
Pawn::CallPublicEx(&script.amx, "OnPlayerDisconnect", "sdd", reason ? reason : "", result, (int)player->GetId());
}

// forward OnPlayerSpawn(playerid);
Expand All @@ -76,7 +76,7 @@ class EventHandler :
void OnPlayerDeath(rage::IPlayer* player, rage::hash_t reason, rage::IPlayer* killer) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerDeath", "d", (int)player->GetId(), "d", killer ? killer->GetId() : -1, "d", (int)reason);
Pawn::CallPublicEx(&script.amx, "OnPlayerDeath", "ddd", (int)reason, killer ? killer->GetId() : -1, (int)player->GetId());
}

// forward OnVehicleDeath(vehicleid, killerid);
Expand All @@ -86,24 +86,23 @@ class EventHandler :
{
for (auto &script : scripts)
{
Pawn::CallPublicEx(&script.amx, "OnPlayerDeath", "d", (int)vehicle->GetId(), "d", killer ? killer->GetId() : -1);
Pawn::CallPublicEx(&script.amx, "OnPlayerDeathEx", "d", (int)vehicle->GetId(), "d", killer ? killer->GetId() : -1, "d", (int)reason);
Pawn::CallPublicEx(&script.amx, "OnPlayerDeath", "dd", killer ? killer->GetId() : -1, (int)vehicle->GetId());
Pawn::CallPublicEx(&script.amx, "OnPlayerDeathEx", "ddd", (int)reason, killer ? killer->GetId() : -1, (int)vehicle->GetId());
}
}

// forward OnPlayerText(playerid, text[]);
void OnPlayerChat(rage::IPlayer* player, const std::u16string& text) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerText", "d", (int)player->GetId(), "s", text.c_str());
Pawn::CallPublicEx(&script.amx, "OnPlayerText", "sd", text.c_str(), (int)player->GetId());
}

// forward OnPlayerCommandText(playerid, cmdtext[]);
// todo: cmdtest[] does not contain the '/' command prefix
void OnPlayerCommand(rage::IPlayer* player, const std::u16string& command) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerCommandText", "d", (int)player->GetId(), "s", command.substr(command.find('/') + 1).c_str());
Pawn::CallPublicEx(&script.amx, "OnPlayerCommandText", "sd", command.substr(command.find('/') + 1).c_str(), (int)player->GetId());
}

// forward OnPlayerEnterVehicle(playerid, vehicleid, ispassenger);
Expand All @@ -113,50 +112,48 @@ class EventHandler :
{
for (auto &script : scripts)
{
Pawn::CallPublicEx(&script.amx, "OnPlayerEnterVehicle", "d", (int)player->GetId(), "d", (int)vehicle->GetId(), "d", (int)seatId == 0 ? 0 : 1);
Pawn::CallPublicEx(&script.amx, "OnPlayerEnterVehicleEx", "d", (int)player->GetId(), "d", (int)vehicle->GetId(), "d", (int)seatId);
Pawn::CallPublicEx(&script.amx, "OnPlayerEnterVehicle", "ddd", (int)seatId == 0 ? 0 : 1, (int)vehicle->GetId(), (int)player->GetId());
Pawn::CallPublicEx(&script.amx, "OnPlayerEnterVehicleEx", "ddd", (int)seatId, (int)vehicle->GetId(), (int)player->GetId());
}
}

// forward OnPlayerExitVehicle(playerid, vehicleid);
void OnPlayerExitVehicle(rage::IPlayer* player, rage::IVehicle* vehicle) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerExitVehicle", "d", (int)player->GetId(), "d", (int)vehicle->GetId());
Pawn::CallPublicEx(&script.amx, "OnPlayerExitVehicle", "dd", (int)vehicle->GetId(), (int)player->GetId());
}

// forward OnPlayerDamage(playerid, Float:healthLoss, Float:armorLoss)
// forward OnPlayerDamage(playerid, Float:healthLoss, Float:armorLoss);
// todo: Different than on samp: http://wiki.sa-mp.com/wiki/OnPlayerTakeDamage
void OnPlayerDamage(rage::IPlayer* player, float healthLoss, float armorLoss) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerDamage", "d", (int)player->GetId(), "f", healthLoss, "f", armorLoss);
Pawn::CallPublicEx(&script.amx, "OnPlayerDamage", "ffd", armorLoss, healthLoss, (int)player->GetId());
}

//forward OnPlayerStartEnterVehicle(playerid, vehicleid, seatid);
void OnPlayerStartEnterVehicle(rage::IPlayer* player, rage::IVehicle* vehicle, uint8_t seatId) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerStartEnterVehicle", "d", (int)player->GetId(), "d", (int)vehicle->GetId(), "d", (int)seatId);
Pawn::CallPublicEx(&script.amx, "OnPlayerStartEnterVehicle", "ddd", (int)seatId, (int)vehicle->GetId(), (int)player->GetId());
}
//forward OnPlayerStartExitVehicle(playerid,vehicleid);
void OnPlayerStartExitVehicle(rage::IPlayer* player, rage::IVehicle* vehicle) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerStartEnterVehicle", "d", (int)player->GetId(), "d", (int)vehicle->GetId());
Pawn::CallPublicEx(&script.amx, "OnPlayerStartEnterVehicle", "dd", (int)vehicle->GetId(), (int)player->GetId());
}

//forward OnPlayerWeaponChange(
//forward OnPlayerWeaponChange(playerid, oldWeapon, newWeapon);
void OnPlayerWeaponChange(rage::IPlayer* player, rage::hash_t oldWeapon, rage::hash_t newWeapon) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerWeaponChange", "d", (int)player->GetId(), "d", (int)oldWeapon, "d", (int)newWeapon);
Pawn::CallPublicEx(&script.amx, "OnPlayerWeaponChange", "ddd", (int)newWeapon, (int)oldWeapon, (int)player->GetId());
}


//void OnPlayerRemoteEvent(rage::IPlayer* player, uint64_t eventNameHash, const rage::args_t& args) override;


void OnEntityCreated(rage::IEntity* entity) override
{
for (auto &script : scripts)
Expand All @@ -169,17 +166,16 @@ class EventHandler :
Pawn::CallPublicEx(&script.amx, "OnEntityDestroyed", "d", (int)entity->GetId());
}


void OnEntityModelChange(rage::IEntity* entity, rage::hash_t oldModel) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnEntityModelChange", "d", (int)entity->GetId(), "d", (int)oldModel);
Pawn::CallPublicEx(&script.amx, "OnEntityModelChange", "dd", (int)oldModel, (int)entity->GetId());
}

void OnPlayerCreateWaypoint(rage::IPlayer* player, const rage::vector3& position) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerCreateWaypoint", "d", (int)player->GetId(), "f", position.x, "f", position.y, "f", position.z);
Pawn::CallPublicEx(&script.amx, "OnPlayerCreateWaypoint", "ffd", position.z, position.y, position.x, (int)player->GetId());
}

void OnPlayerReachWaypoint(rage::IPlayer* player) override
Expand All @@ -188,56 +184,54 @@ class EventHandler :
Pawn::CallPublicEx(&script.amx, "OnPlayerReachWaypoint", "d", (int)player->GetId());
}


void OnPlayerEnterColshape(rage::IPlayer* player, rage::IColshape* colshape) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerEnterColShape", "d", (int)player->GetId(), "d", (int)colshape->GetId());
Pawn::CallPublicEx(&script.amx, "OnPlayerEnterColShape", "dd", (int)colshape->GetId(), (int)player->GetId());
}


void OnPlayerExitColshape(rage::IPlayer* player, rage::IColshape* colshape) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerExitColshape", "d", (int)player->GetId(), "d", (int)colshape->GetId());
Pawn::CallPublicEx(&script.amx, "OnPlayerExitColshape", "dd", (int)colshape->GetId(), (int)player->GetId());
}

void OnPlayerEnterCheckpoint(rage::IPlayer* player, rage::ICheckpoint* checkpoint) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerEnterCheckpoint", "d", (int)player->GetId(), "d", (int)checkpoint->GetId());
Pawn::CallPublicEx(&script.amx, "OnPlayerEnterCheckpoint", "dd", (int)checkpoint->GetId(), (int)player->GetId());
}


void OnPlayerExitCheckpoint(rage::IPlayer* player, rage::ICheckpoint* checkpoint) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnPlayerExitCheckpoint", "d", (int)player->GetId(), "d", (int)checkpoint->GetId());
Pawn::CallPublicEx(&script.amx, "OnPlayerExitCheckpoint", "dd", (int)checkpoint->GetId(), (int)player->GetId());
}

void OnTrailerAttached(rage::IVehicle* vehicle, rage::IVehicle* trailer) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnTrailerAttached", "d", (int)vehicle->GetId(), "d", (int)vehicle->GetId());
Pawn::CallPublicEx(&script.amx, "OnTrailerAttached", "dd", (int)trailer->GetId(), (int)vehicle->GetId());
}

//todo: Add the ability to pass boolean values to CallPublicEx
void OnVehicleSirenToggle(rage::IVehicle* vehicle, bool toggle) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnVehicleSirenToggle", "d", (int)vehicle->GetId(), "d", (int)toggle);
Pawn::CallPublicEx(&script.amx, "OnVehicleSirenToggle", "dd", (int)toggle, (int)vehicle->GetId());
}

void OnVehicleDamage(rage::IVehicle* vehicle, float bodyHealthLoss, float engineHealthLoss) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnVehicleDamage", "d", (int)vehicle->GetId(), "f", bodyHealthLoss, "f", engineHealthLoss);
Pawn::CallPublicEx(&script.amx, "OnVehicleDamage", "ffd", engineHealthLoss, bodyHealthLoss, (int)vehicle->GetId());
}


void OnVehicleHornToggle(rage::IVehicle* vehicle, bool toggle) override
{
for (auto &script : scripts)
Pawn::CallPublicEx(&script.amx, "OnVehicleHornToggle", "d", (int)vehicle->GetId(), "d", (int)toggle);
Pawn::CallPublicEx(&script.amx, "OnVehicleHornToggle", "dd", (int)toggle, (int)vehicle->GetId());
}

};
8 changes: 4 additions & 4 deletions RagePawn/pawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,17 @@ void Pawn::CallPublic(AMX *amx, const char* name)
amx_Exec(amx, nullptr, id);
}

// Note: Params must be sent in REVERSE order to the function.
void Pawn::CallPublicEx(AMX *amx, const char *name, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);

int index;
int err = amx_FindPublic(amx, name, &index);
if (err != AMX_ERR_NONE)
{
Terminate(err);
if(err != AMX_ERR_NOTFOUND) Terminate(err);
return;
}

Expand Down Expand Up @@ -203,10 +204,9 @@ void Pawn::CallPublicEx(AMX *amx, const char *name, const char *fmt, ...)
amx_Release(amx, i);
i = NULL;
}

addresses.clear();
va_end(args);

std::cout << "Finished callback..." << std::endl;
}

int Pawn::joaat(std::string string)
Expand Down
13 changes: 13 additions & 0 deletions RagePawn/player_natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,22 @@ NATIVE (n_TriggerClientEvent)
return false;
}

NATIVE(n_SendClientMessage)
{
HAS_PLAYER(player, params[1])
{
char* fName;
GET_STRING(amx, params[2], fName);
if(fName) player->OutputChatBox(fName);
return true;
}
return false;
}

const AMX_NATIVE_INFO player_Natives[] =
{
{ "GetPlayerName", n_GetPlayerName },
{ "SendClientMessage", n_SendClientMessage },
{ "TriggerClientEvent", n_TriggerClientEvent },
{ NULL, NULL }
};
Expand Down
20 changes: 7 additions & 13 deletions ragemp-cppsdk/Entities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ namespace rage
uint8_t colour;
};

struct headBlend_t
{
uint8_t m_shape[3];
uint8_t m_skin[3];
float m_shapeMix;
float m_skinMix;
float m_thirdMix;
};

enum class material_t : uint8_t
{
Color,
Expand Down Expand Up @@ -79,11 +70,7 @@ namespace rage
};

using Entity =
#ifdef IS_MP
multiplayer::Entity;
#else
IEntity;
#endif

class IPlayer
: public Entity
Expand Down Expand Up @@ -126,6 +113,13 @@ namespace rage
virtual void SetDecoration(uint32_t collection, uint32_t overlay) = 0;
virtual void SetDecorations(std::vector<std::pair<uint32_t, uint32_t>> decorations) = 0;

virtual void ClearDecorations() = 0;

virtual void EnableVoiceTo(IPlayer *target) = 0;
virtual void DisableVoiceTo(IPlayer *target) = 0;

virtual std::vector<IPlayer*> GetVoiceListeners() = 0;

virtual void Eval(const std::string& code) = 0;

virtual const std::string& GetName() = 0;
Expand Down
52 changes: 23 additions & 29 deletions ragemp-cppsdk/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,31 @@ namespace rage
TextLabel,
};

class IEntity;

#pragma pack(push, 1)
struct clothData_t
{
union
{
struct
{
uint8_t drawableId;
uint8_t textureId;
uint8_t paletteId;
} a;
uint32_t i;
};
uint8_t drawableId;
uint8_t textureId;
uint8_t paletteId;
};

struct propData_t
struct headBlend_t
{
union
{
struct
{
uint8_t drawableId;
uint8_t textureId;
} a;
uint32_t i;
};
uint8_t m_shape[3];
uint8_t m_skin[3];
float m_shapeMix;
float m_skinMix;
float m_thirdMix;
};

class IEntity;

struct propData_t
{
uint8_t drawableId;
uint8_t textureId;
};

#pragma pack(push, 1)
struct arg_t
{
public:
Expand All @@ -108,12 +102,12 @@ namespace rage
};

arg_t() : type(val_t::Null), v{} { }
explicit arg_t(bool b) : type(val_t::Boolean), v { b } { }
explicit arg_t(int i) : type(val_t::Int), v { i } { }
explicit arg_t(float f) : type(val_t::Float), v { f } { }
explicit arg_t(const std::string& str) : type(val_t::String), v { new char[str.length() + 1] } { memcpy(v.str, str.c_str(), str.length()); v.str[str.length()] = 0; }
explicit arg_t(entity_t entityType, entityId_t id, rage::IEntity *entity) : type(val_t::Entity), v{ entityType, id, entity } { }
explicit arg_t(const arg_t& r) : type(val_t::Null) { *this = r; }
arg_t(bool b) : type(val_t::Boolean), v { b } { }
arg_t(int i) : type(val_t::Int), v { i } { }
arg_t(float f) : type(val_t::Float), v { f } { }
arg_t(const std::string& str) : type(val_t::String), v { new char[str.length() + 1] } { memcpy(v.str, str.c_str(), str.length()); v.str[str.length()] = 0; }
arg_t(entity_t entityType, entityId_t id, rage::IEntity *entity) : type(val_t::Entity), v{ entityType, id, entity } { }
arg_t(const arg_t& r) : type(val_t::Null) { *this = r; }

void SetNull() { DeleteString(); type = val_t::Null; }
void SetBoolean(bool b) { DeleteString(); type = val_t::Boolean; v.b = b; }
Expand Down
Loading

0 comments on commit a26ddc4

Please sign in to comment.