maxdamage99
14th January 2019, 05:11
if it will be useful to someone, I will try to formulate a description for callbacks in libcod
PlayerCommand
Call before exec player command, arguments: self - client command executor, args - array of command
You can use it for make self chat-system, and stop execution command (client->server) or add custom.
clientCommand() - exec command (if you change args array - command no changed, args array - only for read!)
https://killtube.org/showthread.php?1201-Extension-Player-Command-Control-(includes-CHAT-Control-for-Builtin-B3!)&p=8005#post8005
CodeCallback_PlayerCommand(args)
{
self endon("disconnect");
r = args[0];
if (!isDefined(r) || (!self.stats["logged"] && r != "mr") || r == "kill") //players can't suicide (!execute "kill")
return;
if (r == "score")
{
self clientCommand();
return self resetNextReliableTime();
}
self.pers["brokeSay"] = false;
if (r == "say" || r == "say_team")
{
text = joinChatText(args);
potential_text = skipSpaces(removeColors(text));
if (potential_text.size < 1 || !isDefined(args[1][0]) || args[1][0] == "\"")
return;
if (self isMuted())
self.pers["brokeSay"] = true;
self playerSay(text, args[0]);
if (args[1][0] == "!" && isDefined(args[1][1]))
{
pCommand = tolower(getSubStr(args[1], 1));
if (pCommand == "hi")
{
iprintlnbold(skipColors(self.name) + ": hi all!");
self iprintln("hi soldier ;)");
return;
}
}
}
self clientCommand();
}
joinChatText(args)
{
message = "";
for (i = 1; i < args.size; i++)
if (isDefined(args[i]))
{
if (i > 1)
message += " ";
if (isDefined(args[i]))
message += args[i];
}
return message;
}
playerSay(text, cmd)
{
//text = "daj mne broni pls";
switch (cmd)
{
case "say":
/* player say */
/* check muted etc.*/
break;
case "say_team":
/* say team */
/* some... */
break;
}
}
skipSpaces(string)
{
return /*string without " " (spaces)*/;
}
skipColors(string)
{
return /*string with only one ^7 (color)*/;
}
removeColors(string)
{
return /*string without ^123456 (all colors)*/;
}
Userinfochanged
Call after changing clients base
may on/off renaming, control NULL or standart names.
clientUserInfoChanged() - accept clients base changing
https://killtube.org/showthread.php?2952-Prevent-duplicated-names&highlight=info+changed
https://killtube.org/showthread.php?2103-renaming&highlight=info+changed
CodeCallback_UserInfoChanged(num)
{
//get_userinfo(key) - getting value of key
//set_userinfo(key, value) - set value for key
oldname = self.name;
newname = self get_userinfo("name");
if (oldname != newname && level.renameType != "allow") //broke all renames
return setName(oldname);
if (oldname != newname && self scripts\_player::isEmptyName(newname)) //isEmptyName return false if size < 5; Unnamed Player; Unknown Soldier
return setName(oldname);
self clientuserinfochanged();
}
setName(name) //maybe useless :)
{
self.name = name;
self set_userinfo(name);
}
Vid_restart
call after client reload video settings
Some client data may lose after reload, can repeat here.
CodeCallback_VidRestart(num)
{
// :)
}
FireGrenade
call after grenade throw
Anti team killer, or custom functions for nades
only inform callback, but grenade entity can delete; self - grenade owner; name - weapon name (grenade)
CodeCallback_FireGrenade(grenade, name) //from voron00
{
self endon("disconnect");
team = self.pers["team"];
//iprintlnbold(grenade getcooktime());
//iprintlnbold(self getcooktime());
/* show leftime before grenade explode */
if (name == "bignade_mp")
self thread scripts\_customNades::bigBoom(grenade); //with getcooktime, and grenade.origin - some magic....
while(isDefined(grenade))
if(isDefined(self) && isDefined(grenade) && team != self.pers["team"])
grenade delete();
else
wait 0.05;
}
MeleeButton | UseButton | AttackButton
meleebuttonPressed() | useButtonPressed() | fireButtonPressed()
better way to track clicks versus cyclical checks "while(!player usebuttonPressed()) wait .1;"
CodeCallback_MeleeButton()
{
if (!self.Running)
self thread scripts\_sprint::gogogogo();
}
CodeCallback_AttackButton()
{
iprintlnbold(self.name + "pew pew pew");
}
CodeCallback_UseButton()
{
if (self thread scripts\_killstreak::check("artillery"))
return;
if (self thread scripts\_killstreak::check("napalm"))
return;
if (self thread scripts\_killstreak::check("mortar"))
return;
}
RemoteCommands
call before exec rcon commands
you may broke changed rcon_password, killserver etc.
doRcon(from, pointerMSG); - exec rcon comand; arguments: from - ip : port executor, command = "*** rcon <rcon_password> status" | "*** rcon FWLRj3a4n5teaTTW clientkick 14"; pointerMSG - dont touch me pls
WARNING: between call and doRcon time <= ~4.5 secs (rcon command have lifetime (maybe or may not))
https://killtube.org/showthread.php?3153-callback-RCON
ClientSpam (test callback)
for RateLimiter
If some "people" want to spam your server (Rcon, status, info) - you can block him, but... if you have more insidious punishment for him, you can send data in callback :mad:
https://killtube.org/showthread.php?3090-Cod2-Ban-through-command&p=17456#post17456
Dprintf (test callback)
all developer printfs move in callback
you can sort and filter all data in "developer > 0"
codecallback_Dprintf(string)
{
if (isSubStr(string, "useless developer spam"))
return;
printf("%\n", string);
}
I could not describe some callbacks properly, if someone has a more correct description or code examples - write
possible mistakes in sentences
I will be grateful if administrators can help and correct the wording text from the point of view of the English language
PlayerCommand
Call before exec player command, arguments: self - client command executor, args - array of command
You can use it for make self chat-system, and stop execution command (client->server) or add custom.
clientCommand() - exec command (if you change args array - command no changed, args array - only for read!)
https://killtube.org/showthread.php?1201-Extension-Player-Command-Control-(includes-CHAT-Control-for-Builtin-B3!)&p=8005#post8005
CodeCallback_PlayerCommand(args)
{
self endon("disconnect");
r = args[0];
if (!isDefined(r) || (!self.stats["logged"] && r != "mr") || r == "kill") //players can't suicide (!execute "kill")
return;
if (r == "score")
{
self clientCommand();
return self resetNextReliableTime();
}
self.pers["brokeSay"] = false;
if (r == "say" || r == "say_team")
{
text = joinChatText(args);
potential_text = skipSpaces(removeColors(text));
if (potential_text.size < 1 || !isDefined(args[1][0]) || args[1][0] == "\"")
return;
if (self isMuted())
self.pers["brokeSay"] = true;
self playerSay(text, args[0]);
if (args[1][0] == "!" && isDefined(args[1][1]))
{
pCommand = tolower(getSubStr(args[1], 1));
if (pCommand == "hi")
{
iprintlnbold(skipColors(self.name) + ": hi all!");
self iprintln("hi soldier ;)");
return;
}
}
}
self clientCommand();
}
joinChatText(args)
{
message = "";
for (i = 1; i < args.size; i++)
if (isDefined(args[i]))
{
if (i > 1)
message += " ";
if (isDefined(args[i]))
message += args[i];
}
return message;
}
playerSay(text, cmd)
{
//text = "daj mne broni pls";
switch (cmd)
{
case "say":
/* player say */
/* check muted etc.*/
break;
case "say_team":
/* say team */
/* some... */
break;
}
}
skipSpaces(string)
{
return /*string without " " (spaces)*/;
}
skipColors(string)
{
return /*string with only one ^7 (color)*/;
}
removeColors(string)
{
return /*string without ^123456 (all colors)*/;
}
Userinfochanged
Call after changing clients base
may on/off renaming, control NULL or standart names.
clientUserInfoChanged() - accept clients base changing
https://killtube.org/showthread.php?2952-Prevent-duplicated-names&highlight=info+changed
https://killtube.org/showthread.php?2103-renaming&highlight=info+changed
CodeCallback_UserInfoChanged(num)
{
//get_userinfo(key) - getting value of key
//set_userinfo(key, value) - set value for key
oldname = self.name;
newname = self get_userinfo("name");
if (oldname != newname && level.renameType != "allow") //broke all renames
return setName(oldname);
if (oldname != newname && self scripts\_player::isEmptyName(newname)) //isEmptyName return false if size < 5; Unnamed Player; Unknown Soldier
return setName(oldname);
self clientuserinfochanged();
}
setName(name) //maybe useless :)
{
self.name = name;
self set_userinfo(name);
}
Vid_restart
call after client reload video settings
Some client data may lose after reload, can repeat here.
CodeCallback_VidRestart(num)
{
// :)
}
FireGrenade
call after grenade throw
Anti team killer, or custom functions for nades
only inform callback, but grenade entity can delete; self - grenade owner; name - weapon name (grenade)
CodeCallback_FireGrenade(grenade, name) //from voron00
{
self endon("disconnect");
team = self.pers["team"];
//iprintlnbold(grenade getcooktime());
//iprintlnbold(self getcooktime());
/* show leftime before grenade explode */
if (name == "bignade_mp")
self thread scripts\_customNades::bigBoom(grenade); //with getcooktime, and grenade.origin - some magic....
while(isDefined(grenade))
if(isDefined(self) && isDefined(grenade) && team != self.pers["team"])
grenade delete();
else
wait 0.05;
}
MeleeButton | UseButton | AttackButton
meleebuttonPressed() | useButtonPressed() | fireButtonPressed()
better way to track clicks versus cyclical checks "while(!player usebuttonPressed()) wait .1;"
CodeCallback_MeleeButton()
{
if (!self.Running)
self thread scripts\_sprint::gogogogo();
}
CodeCallback_AttackButton()
{
iprintlnbold(self.name + "pew pew pew");
}
CodeCallback_UseButton()
{
if (self thread scripts\_killstreak::check("artillery"))
return;
if (self thread scripts\_killstreak::check("napalm"))
return;
if (self thread scripts\_killstreak::check("mortar"))
return;
}
RemoteCommands
call before exec rcon commands
you may broke changed rcon_password, killserver etc.
doRcon(from, pointerMSG); - exec rcon comand; arguments: from - ip : port executor, command = "*** rcon <rcon_password> status" | "*** rcon FWLRj3a4n5teaTTW clientkick 14"; pointerMSG - dont touch me pls
WARNING: between call and doRcon time <= ~4.5 secs (rcon command have lifetime (maybe or may not))
https://killtube.org/showthread.php?3153-callback-RCON
ClientSpam (test callback)
for RateLimiter
If some "people" want to spam your server (Rcon, status, info) - you can block him, but... if you have more insidious punishment for him, you can send data in callback :mad:
https://killtube.org/showthread.php?3090-Cod2-Ban-through-command&p=17456#post17456
Dprintf (test callback)
all developer printfs move in callback
you can sort and filter all data in "developer > 0"
codecallback_Dprintf(string)
{
if (isSubStr(string, "useless developer spam"))
return;
printf("%\n", string);
}
I could not describe some callbacks properly, if someone has a more correct description or code examples - write
possible mistakes in sentences
I will be grateful if administrators can help and correct the wording text from the point of view of the English language