Skip to content

Commit

Permalink
Implement GetPlayerName and misc
Browse files Browse the repository at this point in the history
  • Loading branch information
GTANAdam committed Aug 3, 2018
1 parent 5929602 commit 8d6f6d2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,5 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

api.hpp
4 changes: 3 additions & 1 deletion RagePawn/RagePawn.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@
<ItemGroup>
<ClCompile Include="format.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="player_natives.cpp" />
<ClCompile Include="pawn.cpp" />
<ClCompile Include="util_natives.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="api.hpp" />
<ClInclude Include="callbacks.hpp" />
<ClInclude Include="format.hpp" />
<ClInclude Include="main.hpp" />
<ClInclude Include="pawn.hpp" />
<ClInclude Include="natives.hpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\amxlib\amxlib.vcxproj">
Expand Down
10 changes: 8 additions & 2 deletions RagePawn/RagePawn.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<ClCompile Include="format.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="player_natives.cpp">
<Filter>API</Filter>
</ClCompile>
<ClCompile Include="util_natives.cpp">
<Filter>API</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pawn.hpp">
Expand All @@ -37,8 +43,8 @@
<ClInclude Include="callbacks.hpp">
<Filter>API</Filter>
</ClInclude>
<ClInclude Include="natives.hpp">
<Filter>API</Filter>
<ClInclude Include="api.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
16 changes: 0 additions & 16 deletions RagePawn/natives.hpp

This file was deleted.

12 changes: 7 additions & 5 deletions RagePawn/pawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
#pragma comment( lib, "winmm.lib") // amx_TimeInit(&amx);
#pragma comment( lib, "ws2_32.lib") // amx_DGramInit(&amx);

#include "natives.hpp"
#include "callbacks.hpp"

namespace fs = std::experimental::filesystem;

// Discontinued Open Source support

extern "C" {
int AMXEXPORT AMXAPI amx_ConsoleInit(AMX *amx);
int AMXEXPORT AMXAPI amx_ConsoleCleanup(AMX *amx);
Expand All @@ -38,6 +35,9 @@ extern "C" {
int AMXEXPORT AMXAPI amx_ArgsCleanup(AMX *amx);
}

int amx_playerInit(AMX *amx);
int amx_utilInit(AMX *amx);

Pawn::Pawn()
{
std::cout << "Initializing RagePawn.." << std::endl;
Expand Down Expand Up @@ -83,7 +83,9 @@ void Pawn::RunAMX(const std::string& path, const bool fs)
amx_ProcessInit(&amx);
amx_ArgsInit(&amx);

amx_Register(&amx, rage_Natives, -1);
amx_utilInit(&amx);
amx_playerInit(&amx);


//int count;
//amx_NumNatives(&amx, &count);
Expand Down Expand Up @@ -203,4 +205,4 @@ void Pawn::CallPublicEx(AMX *amx, const char *name, const char *fmt, ...)
va_end(args);

std::cout << "Finished callback..." << std::endl;
}
}
4 changes: 3 additions & 1 deletion RagePawn/pawn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typedef struct {

static std::vector<script> scripts;

class Pawn
class Pawn : public rage::IPlugin
{
public:
Pawn();
Expand All @@ -26,6 +26,8 @@ class Pawn
static int TerminateLoad(const std::string& filename);
static int Terminate(int err);
static void TerminateScript(AMX *amx);

rage::IEntity *GetEntity(rage::entityId_t id, rage::entity_t type) const;

private:
rage::IMultiplayer *m_mp;
Expand Down
27 changes: 27 additions & 0 deletions RagePawn/player_natives.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "main.hpp"
#include "api.hpp"

#define MAX_PLAYER_NAME 33

// native GetPlayerName(playerid, const name[])
// todo: different than on samp: native GetPlayerName(playerid, const name[], len)
static cell AMX_NATIVE_CALL n_GetPlayerName(AMX *amx, const cell *params)
{
HAS_PLAYER(player, (rage::entityId_t)params[1])
{
cell* addr = amx_Address(amx, params[2]);
amx_SetString(addr, player->GetName().c_str(), 0, 0, MAX_PLAYER_NAME);
}
return 0;
}

AMX_NATIVE_INFO player_Natives[] =
{
{ "GetPlayerName", n_GetPlayerName },
{ NULL, NULL }
};

int amx_playerInit(AMX *amx)
{
return amx_Register(amx, player_Natives, -1);
}
13 changes: 13 additions & 0 deletions RagePawn/util_natives.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "main.hpp"
#include "format.hpp"

AMX_NATIVE_INFO util_Natives[] =
{
{ "format", n_format },
{ NULL, NULL }
};

int amx_utilInit(AMX *amx)
{
return amx_Register(amx, util_Natives, -1);
}

0 comments on commit 8d6f6d2

Please sign in to comment.