Skip to content

Commit

Permalink
Finished umsg
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed May 17, 2024
1 parent 9edddba commit 0681c35
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 12 deletions.
126 changes: 114 additions & 12 deletions source/library_umsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,108 @@

LUA_FUNCTION(umsg_Start)
{
const char* name = LUA->CheckString(1);
// second argument can be a player!
CRecipientFilter filter;
switch (LUA->GetType(2))
{
case GarrysMod::Lua::Type::RecipientFilter:
filter.CopyFrom(*RecipientFilter_Get(LUA, 2)->filter);
break;
default:
filter.AddAllPlayers();
break;
}
filter.MakeReliable();

UserMessageBegin(filter, name);
return 0;
}

LUA_FUNCTION(umsg_Short)
{
MessageWriteShort(LUA->CheckNumber(1));

return 0;
}

LUA_FUNCTION(umsg_PoolString)
{
MessageWriteWord(LUA->CheckNumber(1));

return 0;
}

LUA_FUNCTION(umsg_Long)
{
MessageWriteLong(LUA->CheckNumber(1));

return 0;
}

LUA_FUNCTION(umsg_Float)
{
MessageWriteFloat(LUA->CheckNumber(1));

return 0;
}

LUA_FUNCTION(umsg_Entity)
{
// ToDo

return 0;
}

LUA_FUNCTION(umsg_End)
{
MessageEnd();

return 0;
}

LUA_FUNCTION(umsg_Char)
{
MessageWriteChar(LUA->CheckNumber(1));

return 0;
}

LUA_FUNCTION(umsg_Bool)
{
MessageWriteBool(LUA->GetBool(1));

return 0;
}

LUA_FUNCTION(umsg_Angle)
{
LUA_Angle* ang = Angle_Get(LUA, 1);
MessageWriteAngles(QAngle(ang->x, ang->y, ang->z));

return 0;
}

LUA_FUNCTION(umsg_String)
{
MessageWriteString(LUA->CheckString(1));

return 0;
}

LUA_FUNCTION(umsg_Vector)
{
LUA_Vector* vec = Vector_Get(LUA, 1);
MessageWriteVec3Coord(Vector(vec->x, vec->y, vec->z));

return 0;
}

LUA_FUNCTION(umsg_VectorNormal)
{
LUA_Vector* vec = Vector_Get(LUA, 1);
MessageWriteVec3Normal(Vector(vec->x, vec->y, vec->z));

return 0;
}

Expand All @@ -10,18 +112,18 @@ void InitUmsg(GarrysMod::Lua::ILuaInterface* LUA)
LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
LUA->CreateTable();
Add_Func(LUA, umsg_Start, "Start");
Add_Func(LUA, umsg_Start, "Short");
Add_Func(LUA, umsg_Start, "PoolString");
Add_Func(LUA, umsg_Start, "Long");
Add_Func(LUA, umsg_Start, "Float");
Add_Func(LUA, umsg_Start, "Entity");
Add_Func(LUA, umsg_Start, "End");
Add_Func(LUA, umsg_Start, "Char");
Add_Func(LUA, umsg_Start, "Bool");
Add_Func(LUA, umsg_Start, "Angle");
Add_Func(LUA, umsg_Start, "String");
Add_Func(LUA, umsg_Start, "Vector");
Add_Func(LUA, umsg_Start, "VectorNormal");
Add_Func(LUA, umsg_Short, "Short");
Add_Func(LUA, umsg_PoolString, "PoolString");
Add_Func(LUA, umsg_Long, "Long");
Add_Func(LUA, umsg_Float, "Float");
//Add_Func(LUA, umsg_Entity, "Entity");
Add_Func(LUA, umsg_End, "End");
Add_Func(LUA, umsg_Char, "Char");
Add_Func(LUA, umsg_Bool, "Bool");
Add_Func(LUA, umsg_Angle, "Angle");
Add_Func(LUA, umsg_String, "String");
Add_Func(LUA, umsg_Vector, "Vector");
Add_Func(LUA, umsg_VectorNormal, "VectorNormal");

LUA->SetField(-2, "umsg");
LUA->Pop();
Expand Down
1 change: 1 addition & 0 deletions source/lua_ILuaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ void InitLuaLibraries(ILuaThread* thread)
InitGmodLib(LUA);
InitFileLib(LUA);
InitGame(LUA);
InitUmsg(LUA);
}

LUA_FUNCTION(ILuaInterface_InitLibraries)
Expand Down
1 change: 1 addition & 0 deletions source/lua_threaded.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "library_engine.h"
#include "library_hammer.h"
#include "library_timer.h"
#include "library_umsg.h"
#include "library_gmod.h"
#include "library_game.h"
#include "library_file.h"
Expand Down

0 comments on commit 0681c35

Please sign in to comment.