Skip to content

Commit d1114bd

Browse files
committed
documentation update
1 parent e067d3b commit d1114bd

2 files changed

Lines changed: 282 additions & 24 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Call of Duty 4 X Lua Plugin
1+
# Call of Duty 4 X Lua Plugin [![build](https://github.com/leiizko/cod4x_lua_plugin/actions/workflows/build.yml/badge.svg)](https://github.com/leiizko/cod4x_lua_plugin/actions/workflows/build.yml)
22
This plugin adds support for CoD4X plugins written in Lua, removing any need to compile it against CoD4X server enabling rapid development. It is best used to replace expensive gsc functions and to add additional functionality to game with persistent storage and http capability. Using libiconv it can also serve as server side localization option.
33

44
# Usage
@@ -12,9 +12,11 @@ lua_loadscript "path/script.lua"
1212
```
1313
Do not load more than 1 script via this command, use entry lua script to load any additional scripts.
1414

15-
Function documentation can be found [here](functiondoc.md).
15+
Function documentation can be found [here](functiondoc.md#function-reference).
1616
Event documentation can be found [here](LuaScripts/examples/events.lua)
1717

18+
As of version 0.5 plugin requires server version [b3b68dd](https://github.com/callofduty4x/CoD4x_Server/commit/b3b68dda2ede9c83c28192ac8973b9bb19265599) or later.
19+
1820
# Compiling
1921
To compile without libiconv enter directory and run make. To include libiconv enter directory and run make ICONV=TRUE.
2022
On Windows you need to compile the server first.

functiondoc.md

Lines changed: 278 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,50 @@ We do our best to keep it updated._
3636
- [Plugin_Scr_ExecThread](#plugin_scr_execthread-int-callbackhook-int-numparams-)
3737
- [Plugin_Scr_ExecEntThread](#plugin_scr_execentthread-gentity_t-ent-int-callbackhook-int-numparams-)
3838
5. [Utility functions](#utility-functions)
39-
- [Plugin_Printf](#plugin_printf-const-char-str)
40-
- [Plugin_DPrintf](#plugin_dprintf-const-char-str)
41-
- [Plugin_GetVersion](#plugin_getversion)
42-
- [Plugin_Milliseconds](#plugin_milliseconds)
43-
- [Plugin_Scr_Error](#plugin_scr_error-const-char-str)
44-
- [Plugin_Scr_ParamError](#plugin_scr_paramerror-int-paramnum-const-char-str)
45-
- [Plugin_Scr_ObjectError](#plugin_scr_objecterror-const-char-str)
46-
- [Plugin_Error](#plugin_error-int-code-const-char-str)
47-
- [Plugin_GetGentityForClientNum](#plugin_getgentityforclientnum-int-clientnum)
48-
- [Plugin_GetClientNumForGentity](#plugin_getclientnumforgentity-gentity_t-ent)
49-
- [Plugin_GetPlayerName](#plugin_getplayername-int-clientnum)
50-
- [Plugin_GetClientScoreboard](#plugin_getclientscoreboard-int-clientnum)
51-
- [Plugin_Scr_AllocString](#plugin_scr_allocstring-const-char-str)
52-
- [Plugin_SV_GetConfigstring](#plugin_sv_getconfigstring-int-index)
53-
- [Plugin_SV_SetConfigstring](#plugin_sv_setconfigstring-int-index-const-char-str)
54-
- [Plugin_DropClient](#plugin_dropclient-int-clientnum-const-char-reason)
55-
- [Plugin_BanClient](#plugin_banclient-int-clientnum-int-minutes-int-invokerid-const-char-reason)
39+
- [Plugin_Printf](#plugin_printf-const-char-str-)
40+
- [Plugin_DPrintf](#plugin_dprintf-const-char-str-)
41+
- [Plugin_GetVersion](#plugin_getversion-)
42+
- [Plugin_Milliseconds](#plugin_milliseconds-)
43+
- [Plugin_Scr_Error](#plugin_scr_error-const-char-str-)
44+
- [Plugin_Scr_ParamError](#plugin_scr_paramerror-int-paramnum-const-char-str-)
45+
- [Plugin_Scr_ObjectError](#plugin_scr_objecterror-const-char-str-)
46+
- [Plugin_Error](#plugin_error-int-code-const-char-str-)
47+
- [Plugin_GetGentityForClientNum](#plugin_getgentityforclientnum-int-clientnum-)
48+
- [Plugin_GetClientNumForGentity](#plugin_getclientnumforgentity-gentity_t-ent-)
49+
- [Plugin_GetPlayerName](#plugin_getplayername-int-clientnum-)
50+
- [Plugin_GetClientScoreboard](#plugin_getclientscoreboard-int-clientnum-)
51+
- [Plugin_Scr_AllocString](#plugin_scr_allocstring-const-char-str-)
52+
- [Plugin_SV_GetConfigstring](#plugin_sv_getconfigstring-int-index-)
53+
- [Plugin_SV_SetConfigstring](#plugin_sv_setconfigstring-int-index-const-char-str-)
54+
- [Plugin_DropClient](#plugin_dropclient-int-clientnum-const-char-reason-)
55+
- [Plugin_BanClient](#plugin_banclient-int-clientnum-int-minutes-int-invokerid-const-char-reason-)
5656
6. [Notify functions](#notify-functions)
57-
- [Plugin_Scr_NotifyLevel](#plugin_scr_notifylevel-int-stridx-int-paramnum)
58-
- [Plugin_Scr_Notify](#plugin_scr_notify-gentity_t-ent-int-stridx-int-paramnum)
57+
- [Plugin_Scr_NotifyLevel](#plugin_scr_notifylevel-int-stridx-int-paramnum-)
58+
- [Plugin_Scr_Notify](#plugin_scr_notify-gentity_t-ent-int-stridx-int-paramnum-)
5959
7. [ICONV functions](#iconv-functions)
60-
- [Plugin_iconv_open](#plugin_iconv_open-char-to-char-from)
61-
- [Plugin_iconv_close](#plugin_iconv_close-int-conversionIndex)
62-
- [Plugin_iconv](#plugin_iconv-int-conversionIndex-char-str)
60+
- [Plugin_iconv_open](#plugin_iconv_open-char-to-char-from-)
61+
- [Plugin_iconv_close](#plugin_iconv_close-int-conversionIndex-)
62+
- [Plugin_iconv](#plugin_iconv-int-conversionIndex-char-str-)
63+
8. [CVAR functions](#cvar-functions)
64+
- [Plugin_Cvar_RegisterString](#plugin_cvar_registerstring-char-varname-char-varvalue-int-flags-char-vardesc-)
65+
- [Plugin_Cvar_RegisterBool](#plugin_cvar_registerbool-char-varName-qboolean-varValue-int-flags-char-varDesc-)
66+
- [Plugin_Cvar_RegisterInt](#plugin_cvar_registerint-char-varName-int-value-int-minvalue-int-maxvalue-int-flags-char-varDesc-)
67+
- [Plugin_Cvar_RegisterFloat](#plugin_cvar_registerfloat-char-varName-float-value-float-minvalue-float-maxvalue-int-flags-char-varDesc-)
68+
- [Plugin_Cvar_SetString](#plugin_cvar_setstring-convar_t-cvar-char-value-)
69+
- [Plugin_Cvar_SetBool](#plugin_cvar_setbool-convar_t-cvar-qboolean-value-)
70+
- [Plugin_Cvar_SetInt](#plugin_cvar_setint-convar_t-cvar-int-value-)
71+
- [Plugin_Cvar_SetFloat](#plugin_cvar_setfloat-convar_t-cvar-float-value-)
72+
- [Plugin_Cvar_GetString](#plugin_cvar_getstring-convar_t-cvar-)
73+
- [Plugin_Cvar_GetBool](#plugin_cvar_getbool-convar_t-cvar-)
74+
- [Plugin_Cvar_GetInt](#plugin_cvar_getint-convar_t-cvar-)
75+
- [Plugin_Cvar_GetFloat](#plugin_cvar_getfloat-convar_t-cvar-)
76+
- [Plugin_Cvar_VariableStringBuffer](#plugin_cvar_variablestringbuffer-char-varname-)
77+
- [Plugin_Cvar_VariableValue](#plugin_cvar_variablevalue-char-varname-)
78+
- [Plugin_Cvar_VariableIntegerValue](#plugin_cvar_variableintegervalue-char-varname-)
79+
- [Plugin_Cvar_VariableBooleanValue](#plugin_cvar_variablebooleanvalue-char-varname-)
80+
- [Plugin_Cvar_Set](#plugin_cvar_set-char-varName-char-value-)
81+
9. [HTTP function](#http-function)
82+
- [Plugin_HTTP_makeRequest](#plugin_http_makerequest-char-url-char-data-char-callback-char-method-)
6383

6484
## Register functions
6585
These functions are used to add script functions or commands to gsc.
@@ -1133,3 +1153,239 @@ Does a conversion on str, specified with open conversion at conversionIndex.
11331153

11341154
An example can be found [here](LuaScripts/examples/localization.lua)
11351155

1156+
## CVAR functions
1157+
1158+
Functions used to manipulate cvars. Cvars need to be set in config file before loading lua plugin or the value will always be default.
1159+
1160+
#### Plugin_Cvar_RegisterString( char *varName, char *varValue, int flags, char *varDesc )
1161+
1162+
Registers a string Cvar, returns reference to registered cvar. Keep the reference saved properly at all times.
1163+
1164+
Usage example:
1165+
Lua:
1166+
```lua
1167+
idkey = Plugin_Cvar_RegisterString( "http_identkey", "", 0, "Key used to authenticate POST request" )
1168+
```
1169+
1170+
#### Plugin_Cvar_RegisterBool( char *varName, qboolean varValue, int flags, char *varDesc )
1171+
1172+
Registers a boolean cvar, returns reference to registered cvar. Keep the reference saved properly at all times.
1173+
1174+
Usage example:
1175+
Lua:
1176+
```lua
1177+
usehhtp = Plugin_Cvar_RegisterBool( "http_enabled", true, 0, "Enable http functionality" )
1178+
```
1179+
1180+
#### Plugin_Cvar_RegisterInt( char *varName, int value, int minvalue, int maxvalue, int flags, char *varDesc )
1181+
1182+
Registers an integer cvar, returns reference to registered cvar. Keep the reference saved properly at all times.
1183+
1184+
Usage example:
1185+
Lua:
1186+
```lua
1187+
numplayers = Plugin_Cvar_RegisterInt( "num_players", 24, 1, 64, 0, "Maximum number of players" )
1188+
```
1189+
1190+
#### Plugin_Cvar_RegisterFloat( char *varName, float value, float minvalue, float maxvalue, int flags, char *varDesc )
1191+
1192+
Registers a float cvar, returns reference to registered cvar. Keep the reference saved properly at all times.
1193+
1194+
Usage example:
1195+
Lua:
1196+
```lua
1197+
xpmulti = Plugin_Cvar_RegisterFloat( "xpmulti", 1.5, 0.1, 10, 0, "XP multiplier" )
1198+
```
1199+
1200+
#### Plugin_Cvar_SetString( CONVAR_T *cvar, char *value )
1201+
1202+
Sets boolean value to specified cvar. CONVAR_T* is the returned reference from register cvar command.
1203+
1204+
Usage example:
1205+
Lua:
1206+
```lua
1207+
idkey = Plugin_Cvar_RegisterString( "http_identkey", "", 0, "Key used to authenticate POST request" )
1208+
1209+
Plugin_Cvar_SetString( idkey, "123456789" )
1210+
```
1211+
1212+
#### Plugin_Cvar_SetBool( CONVAR_T *cvar, qboolean value )
1213+
1214+
Sets string value to specified cvar. CONVAR_T* is the returned reference from register cvar command.
1215+
1216+
Usage example:
1217+
Lua:
1218+
```lua
1219+
usehhtp = Plugin_Cvar_RegisterBool( "http_enabled", true, 0, "Enable http functionality" )
1220+
1221+
Plugin_Cvar_SetBool( usehttp, false )
1222+
```
1223+
1224+
#### Plugin_Cvar_SetInt( CONVAR_T *cvar, int value )
1225+
1226+
Sets integer value to specified cvar. CONVAR_T* is the returned reference from register cvar command.
1227+
1228+
Usage example:
1229+
Lua:
1230+
```lua
1231+
numplayers = Plugin_Cvar_RegisterInt( "num_players", 24, 1, 64, 0, "Maximum number of players" )
1232+
1233+
Plugin_Cvar_SetInt( numplayers, 48 )
1234+
```
1235+
1236+
#### Plugin_Cvar_SetFloat( CONVAR_T *cvar, float value )
1237+
1238+
Sets float value to specified cvar. CONVAR_T* is the returned reference from register cvar command.
1239+
1240+
Usage example:
1241+
Lua:
1242+
```lua
1243+
xpmulti = Plugin_Cvar_RegisterFloat( "xpmulti", 1.5, 0.1, 10, 0, "XP multiplier" )
1244+
1245+
Plugin_Cvar_SetFloat( xpmulti, 2.5 )
1246+
```
1247+
1248+
#### Plugin_Cvar_GetString( CONVAR_T *cvar )
1249+
1250+
Returns string value of specified cvar with CONVAR_T* reference. CONVAR_T* is the returned reference from register cvar command.
1251+
1252+
Usage example:
1253+
Lua:
1254+
```lua
1255+
idkey = Plugin_Cvar_RegisterString( "http_identkey", "", 0, "Key used to authenticate POST request" )
1256+
1257+
str = Plugin_Cvar_GetString( idkey )
1258+
```
1259+
1260+
#### Plugin_Cvar_GetBool( CONVAR_T *cvar )
1261+
1262+
Returns boolean value of specified cvar with CONVAR_T* reference. CONVAR_T* is the returned reference from register cvar command.
1263+
1264+
Usage example:
1265+
Lua:
1266+
```lua
1267+
usehhtp = Plugin_Cvar_RegisterBool( "http_enabled", true, 0, "Enable http functionality" )
1268+
1269+
bool = Plugin_Cvar_GetBool( usehttp )
1270+
```
1271+
1272+
#### Plugin_Cvar_GetInt( CONVAR_T *cvar )
1273+
1274+
Returns integer value of specified cvar with CONVAR_T* reference. CONVAR_T* is the returned reference from register cvar command.
1275+
1276+
Usage example:
1277+
Lua:
1278+
```lua
1279+
numplayers = Plugin_Cvar_RegisterInt( "num_players", 24, 1, 64, 0, "Maximum number of players" )
1280+
1281+
num = Plugin_Cvar_GetInt( numplayers )
1282+
```
1283+
1284+
#### Plugin_Cvar_GetFloat( CONVAR_T *cvar )
1285+
1286+
Returns float value of specified cvar with CONVAR_T* reference. CONVAR_T* is the returned reference from register cvar command.
1287+
1288+
Usage example:
1289+
Lua:
1290+
```lua
1291+
xpmulti = Plugin_Cvar_RegisterFloat( "xpmulti", 1.5, 0.1, 10, 0, "XP multiplier" )
1292+
1293+
num = Plugin_Cvar_GetFloat( xpmulti )
1294+
```
1295+
1296+
#### Plugin_Cvar_VariableStringBuffer( char *varName )
1297+
1298+
Returns string value of cvar with varName.
1299+
1300+
Usage example:
1301+
Lua:
1302+
```lua
1303+
str = Plugin_Cvar_VariableStringBuffer( "idkey" )
1304+
```
1305+
1306+
#### Plugin_Cvar_VariableValue( char *varName )
1307+
1308+
Returns float value of cvar with varName.
1309+
1310+
Usage example:
1311+
Lua:
1312+
```lua
1313+
num = Plugin_Cvar_VariableValue( "xpmulti" )
1314+
```
1315+
1316+
#### Plugin_Cvar_VariableIntegerValue( char *varName )
1317+
1318+
Returns integer value of cvar with varName.
1319+
1320+
Usage example:
1321+
Lua:
1322+
```lua
1323+
num = Plugin_Cvar_VariableIntegerValue( "numplayers" )
1324+
```
1325+
1326+
#### Plugin_Cvar_VariableBooleanValue( char *varName )
1327+
1328+
Returns boolean value of cvar with varName.
1329+
1330+
Usage example:
1331+
Lua:
1332+
```lua
1333+
bool = Plugin_Cvar_VariableBooleanValue( "http_enable" )
1334+
```
1335+
1336+
#### Plugin_Cvar_Set( char *varName, char *value )
1337+
1338+
Sets a cvar by name and by a string value which gets interpreted correctly depending on the cvar type.
1339+
1340+
Usage example:
1341+
Lua:
1342+
```lua
1343+
Plugin_Cvar_Set( "numplayers", "24" ) -- gets interpreted as int cvar
1344+
```
1345+
1346+
## HTTP function
1347+
1348+
Following function is used to make http requests. All backend logic is handled on C side.
1349+
1350+
#### Plugin_HTTP_makeRequest( char *url, char *data, char *callback, char *method )
1351+
1352+
Creates an async http request, returns true on created request and false if request could not be created. URL must point to endpoint API to handle the request and data must be JSON encoded. Callback is function name in Lua, method is optional parameter and will default to "POST" if left empty. If request is sucessfuly created, the result will be passed to lua callback function. Result is json encoded string on success and nil on fail.
1353+
If request could not be created or there was error from the webserver, you can use OnFrame event to schedule another try at a later time.
1354+
Maximum number of concurent open requests is 64.
1355+
1356+
1357+
Usage example:
1358+
Lua:
1359+
```lua
1360+
function foo( gentity )
1361+
1362+
url = "https://example.com/codapi.php"
1363+
data = "{ 'idkey':'12345', 'action':'whatever' }"
1364+
Plugin_HTTP_makeRequest( url, data, "cb" )
1365+
end
1366+
1367+
function cb ( result )
1368+
1369+
if result then
1370+
1371+
-- do something with result
1372+
-- client might disconnect in meanwhile so gentity might be invalid at this point
1373+
-- for extra safety work with client nums and keep track with events
1374+
1375+
-- call callback function in gsc
1376+
end
1377+
end
1378+
```
1379+
Gsc:
1380+
```c
1381+
init()
1382+
{
1383+
level waittill( "connected", player );
1384+
player foo( ::callback );
1385+
}
1386+
1387+
callback( arg1, arg2 )
1388+
{
1389+
// ...
1390+
}
1391+
```

0 commit comments

Comments
 (0)