From 0681c357720990cede44e2d30c6621a23d6c3764 Mon Sep 17 00:00:00 2001 From: RaphaelIT7 Date: Fri, 17 May 2024 19:46:56 +0200 Subject: [PATCH] Finished umsg --- source/library_umsg.cpp | 126 +++++++++++++++++++++++++++++++---- source/lua_ILuaInterface.cpp | 1 + source/lua_threaded.h | 1 + 3 files changed, 116 insertions(+), 12 deletions(-) diff --git a/source/library_umsg.cpp b/source/library_umsg.cpp index 55f13e5..abca448 100644 --- a/source/library_umsg.cpp +++ b/source/library_umsg.cpp @@ -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; } @@ -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(); diff --git a/source/lua_ILuaInterface.cpp b/source/lua_ILuaInterface.cpp index e84202a..4e9b658 100644 --- a/source/lua_ILuaInterface.cpp +++ b/source/lua_ILuaInterface.cpp @@ -293,6 +293,7 @@ void InitLuaLibraries(ILuaThread* thread) InitGmodLib(LUA); InitFileLib(LUA); InitGame(LUA); + InitUmsg(LUA); } LUA_FUNCTION(ILuaInterface_InitLibraries) diff --git a/source/lua_threaded.h b/source/lua_threaded.h index 02969d7..0fb3a63 100644 --- a/source/lua_threaded.h +++ b/source/lua_threaded.h @@ -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"