Skip to content

Commit 357e0e4

Browse files
committed
Updates
Add missing functions, support for lua modules toggling
1 parent 07a3dbd commit 357e0e4

File tree

6 files changed

+84
-10
lines changed

6 files changed

+84
-10
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ As the name suggests, this plugin provides a scripting API for VCMP in Lua (yay!
44
about the structure of the plugin (its quite easy!)
55

66
## Purpose of this project
7+
78
The purpose of this project is mainly that I love Lua, and I also love C++, therefore to keep my practice in C++ I decided to work on this plugin with one of my
89
favorite scripting languages (Lua).
910

1011
# The Lua config file
12+
1113
In your server directory you should place a **luaconfig.ini** file which will allow you to specify some settings the plugin can use. Some of these settings are
1214
optional while some (like specifying atleast 1 script file) is compulsory.
1315

1416
The file structure is as of right now very simple:
17+
1518
```ini
1619
[config]
1720
# Sets experimental mode ON (1) or OFF (0) | Intended for beta-testing and development only. Do not rely for stability
@@ -21,21 +24,32 @@ loglevel=0
2124
# Sets the log file. This log file will be used to create daily logs and it will log everything logged by Logger class, regardless of level
2225
logfile=DailyLogs.logs
2326

27+
[modules]
28+
# This is the modules section, here you can opt in to use external modules that the plugin provides. They can be listed and toggled by setting them to a boolean
29+
30+
#moduleName=[true/false]
31+
lanes=false
32+
2433
[scripts]
2534
# This is the scripts section, here you can specify all your script files that you want to run.
2635

36+
# script=path/to/file.lua
2737
script=lua/script.lua
2838
```
2939

3040
# Building the plugin
41+
3142
## Windows
43+
3244
To build on Windows, just download the repository and run the win-build.bat file in the premake folder. You should be getting a Visual Studio 2019 solution file
3345

3446
**NOTE: You can only build x64 of Lua plugin on Windows for now. Why? Cuz I'm too lazy to setup my environment to compile mariadb for x32 :D**
3547

3648
## Linux
49+
3750
To build on Linux:
38-
* Download/Clone the repository
39-
* Download premake and build it
40-
* Inside the repository, call premake: `path/to/premake5 gmake`
41-
* Now use `make` with your desired `config`: `make config=release` OR `make config=release32`
51+
52+
- Download/Clone the repository
53+
- Download premake and build it
54+
- Inside the repository, call premake: `path/to/premake5 gmake`
55+
- Now use `make` with your desired `config`: `make config=release` OR `make config=release32`

VCMP-LUA/Core.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sol::state Lua;
1212
static std::vector<std::string> s_ScriptFiles;
1313

1414
void reload_scripts();
15+
void LoadLuaModule(std::string);
1516

1617
int my_exception_handler(lua_State* L, sol::optional<const std::exception&> maybe_exception, sol::string_view description) {
1718
std::cout << "An exception occurred in a function ";
@@ -33,7 +34,7 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
3334
g_Calls = pluginCalls;
3435
g_Info = pluginInfo;
3536

36-
pluginInfo->pluginVersion = 0x2300;
37+
pluginInfo->pluginVersion = 0x2400;
3738
pluginInfo->apiMajorVersion = PLUGIN_API_MAJOR;
3839
pluginInfo->apiMinorVersion = PLUGIN_API_MINOR;
3940

@@ -61,9 +62,10 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
6162

6263
Lua.open_libraries();
6364

64-
Logger::Init(&Lua, spdlog::level::debug); // Set level to info to avoid debug messages or trace to get internal debug messages
65+
Logger::Init(&Lua, spdlog::level::info); // Set level to info to avoid debug messages or trace to get internal debug messages
66+
67+
//luaopen_lanes_embedded(Lua.lua_state(), NULL);
6568

66-
luaopen_lanes_embedded(Lua.lua_state(), NULL);
6769
//Lua.set_exception_handler(&my_exception_handler);
6870

6971
bool experimental_mode = false;
@@ -102,6 +104,17 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
102104
RegisterClasses(&Lua);
103105
RegisterVCMPCallbacks();
104106

107+
// Load Modules
108+
{
109+
std::list<CSimpleIniA::Entry> modules;
110+
if(conf.GetAllKeys("modules", modules) && modules.size() > 0) {
111+
for(const auto& module : modules)
112+
if(std::string(conf.GetValue("modules", module.pItem)) == "true")
113+
LoadLuaModule(module.pItem);
114+
}
115+
else spdlog::info("No lua modules defined");
116+
}
117+
105118
// Load Scripts
106119
{
107120
std::list<CSimpleIniA::Entry> scripts;
@@ -142,4 +155,25 @@ void reload_scripts()
142155

143156
// Re-trigger some crucial events which simulate a 'restart'
144157
EventManager::Trigger("onServerInit");
158+
}
159+
160+
enum LuaModules {
161+
Invalid = 0,
162+
Lanes
163+
};
164+
165+
static std::unordered_map<std::string, LuaModules> s_LuaModules = {
166+
{"lanes", LuaModules::Lanes}
167+
};
168+
169+
void LoadLuaModule(std::string name) {
170+
LuaModules module = s_LuaModules.find(name) != s_LuaModules.end() ? s_LuaModules[name] : LuaModules::Invalid;
171+
172+
spdlog::info("Loading Lua module: {}", name);
173+
174+
switch(module) {
175+
case Lanes:
176+
luaopen_lanes_embedded(Lua.lua_state(), NULL);
177+
break;
178+
}
145179
}

VCMP-LUA/vcmpWrap/Classes/Player.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ void Player::announce(const std::string& msg, sol::variadic_args args)
6969
g_Funcs->SendGameMessage(m_ID, type, msg.c_str());
7070
}
7171

72+
int32_t Player::getAlpha() const {
73+
return g_Funcs->GetPlayerAlpha(m_ID);
74+
}
75+
76+
void Player::setAlpha(int32_t alpha, uint32_t fadeTime) {
77+
g_Funcs->SetPlayerAlpha(m_ID, alpha, fadeTime);
78+
}
79+
7280
bool Player::getOption(vcmpPlayerOption option) const {
7381
return g_Funcs->GetPlayerOption(m_ID, option);
7482
}
@@ -519,6 +527,8 @@ void Player::Init(sol::state* L) {
519527
/*** METHODS ***/
520528
userdata["msg"] = &Player::msg;
521529
userdata["announce"] = &Player::announce;
530+
userdata["getAlpha"] = &Player::getAlpha;
531+
userdata["setAlpha"] = &Player::setAlpha;
522532
userdata["getOption"] = &Player::getOption;
523533
userdata["setOption"] = &Player::setOption;
524534
userdata["isPlayerStreamed"] = &Player::isPlayerStreamed;
@@ -553,6 +563,7 @@ void Player::Init(sol::state* L) {
553563
userdata.set("isSpawned", &Player::isSpawned);
554564
userdata.set("isTyping", &Player::isTyping);
555565
userdata.set("isCrouching", &Player::isCrouching);
566+
userdata.set("isAway", &Player::isAway);
556567
userdata.set("getPing", &Player::getPing);
557568
userdata.set("getFPS", &Player::getFPS);
558569
userdata.set("getModules", &Player::getModules);

VCMP-LUA/vcmpWrap/Classes/Player.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ class Player {
2828

2929
/*** METHODS ***/
3030
void msg(const std::string&, sol::variadic_args);
31-
void announce
32-
(const std::string&, sol::variadic_args);
31+
void announce(const std::string&, sol::variadic_args);
32+
int32_t getAlpha() const;
33+
void setAlpha(int32_t, uint32_t);
3334
bool getOption(vcmpPlayerOption) const;
3435
void setOption(vcmpPlayerOption, bool);
3536
bool isPlayerStreamed(Player*) const;

VCMP-LUA/vcmpWrap/Classes/Vehicle.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,24 @@ void Vehicle::setRadio(int32_t radioID) {
287287
g_Funcs->SetVehicleRadio(m_ID, radioID);
288288
}
289289

290-
uint32_t Vehicle::getDamage() const { return g_Funcs->GetVehicleDamageData(m_ID); }
290+
uint32_t Vehicle::getDamage() const {
291+
return g_Funcs->GetVehicleDamageData(m_ID);
292+
}
293+
294+
uint32_t Vehicle::getImmunity() const {
295+
return g_Funcs->GetVehicleImmunityFlags(m_ID);
296+
}
297+
291298
void Vehicle::setDamage(uint32_t data) {
292299
if (getDamage() == data)
293300
return;
294301
g_Funcs->SetVehicleDamageData(m_ID, data);
295302
}
296303

304+
void Vehicle::setImmunity(uint32_t flags) {
305+
g_Funcs->SetVehicleImmunityFlags(m_ID, flags);
306+
}
307+
297308
/*** COMMON PROPERTIES ***/
298309
sol::as_table_t<std::vector<float>> Vehicle::getPosition() const
299310
{
@@ -412,6 +423,7 @@ void Vehicle::Init(sol::state* L) {
412423
userdata["color"] = sol::property(&Vehicle::getColor, &Vehicle::setColor);
413424
userdata["radio"] = sol::property(&Vehicle::getRadio, &Vehicle::setRadio);
414425
userdata["damage"] = sol::property(&Vehicle::getDamage, &Vehicle::setDamage);
426+
userdata["immunity"] = sol::property(&Vehicle::getImmunity, &Vehicle::setImmunity);
415427

416428
/*** COMMON PROPERTIES AMONGST ENTITIES ***/
417429
userdata["data"] = &Vehicle::m_LuaData;

VCMP-LUA/vcmpWrap/Classes/Vehicle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Vehicle {
6565
uint32_t getIdleRespawnTime() const;
6666
uint32_t getLightsData() const;
6767
uint32_t getDamage() const;
68+
uint32_t getImmunity() const;
6869
float getHealth() const;
6970
sol::as_table_t<std::vector<float>> getSpawnPosition() const;
7071
sol::as_table_t<std::vector<float>> getSpawnRotation() const;
@@ -75,6 +76,7 @@ class Vehicle {
7576
void setIdleRespawnTime(uint32_t);
7677
void setLightsData(uint32_t);
7778
void setDamage(uint32_t);
79+
void setImmunity(uint32_t);
7880
void setHealth(float);
7981
void setSpawnPosition(sol::table);
8082
void setSpawnRotation(sol::table);

0 commit comments

Comments
 (0)