2018-10-25 09:14:39 -04:00
|
|
|
#include common_scripts\utility;
|
2018-04-28 01:22:18 -04:00
|
|
|
#include maps\mp\_utility;
|
|
|
|
#include maps\mp\gametypes\_hud_util;
|
2018-10-25 09:14:39 -04:00
|
|
|
#include maps\mp\gametypes\_playerlogic;
|
2018-04-28 01:22:18 -04:00
|
|
|
|
|
|
|
init()
|
|
|
|
{
|
2019-08-12 20:04:25 -04:00
|
|
|
/*
|
2018-10-25 09:14:39 -04:00
|
|
|
SetDvarIfUninitialized("sv_team_balance_assignments", "");
|
|
|
|
SetDvarIfUninitialized("sv_iw4madmin_serverid", 0);
|
|
|
|
SetDvarIfUninitialized("sv_iw4madmin_apiurl", "http://127.0.0.1:1624/api/gsc/");
|
|
|
|
level.apiUrl = GetDvar("sv_iw4madmin_apiurl");
|
2019-08-12 20:04:25 -04:00
|
|
|
level thread WaitForCommand();
|
2018-10-25 09:14:39 -04:00
|
|
|
level thread onPlayerConnect();
|
|
|
|
level thread onPlayerDisconnect();
|
2019-08-12 20:04:25 -04:00
|
|
|
*/
|
2018-10-25 09:14:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
onPlayerConnect()
|
|
|
|
{
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
level waittill( "connected", player );
|
|
|
|
player thread onJoinedTeam();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPlayerDisconnect()
|
|
|
|
{
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
level waittill( "disconnected", player );
|
|
|
|
logPrint("player disconnected\n");
|
|
|
|
level.players[0] SetTeamBalanceAssignments(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onJoinedTeam()
|
|
|
|
{
|
|
|
|
self endon("disconnect");
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
self waittill( "joined_team" );
|
|
|
|
self SetTeamBalanceAssignments(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetTeamBalanceAssignments(isDisconnect)
|
|
|
|
{
|
|
|
|
assignments = GetDvar("sv_team_balance_assignments");
|
|
|
|
dc = "";
|
|
|
|
if (isDisconnect)
|
|
|
|
{
|
|
|
|
dc = "&isDisconnect=true";
|
|
|
|
}
|
|
|
|
url = level.apiUrl + "GetTeamAssignments/" + self.guid + "/?teams=" + assignments + dc + "&serverId=" + GetDvar("sv_iw4madmin_serverid");
|
|
|
|
newAssignments = GetHttpString(url);
|
|
|
|
SetDvar("sv_team_balance_assignments", newAssignments.data);
|
|
|
|
|
|
|
|
if (newAssignments.success)
|
|
|
|
{
|
|
|
|
BalanceTeams(strtok(newAssignments.data, ","));
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
WaitForCommand()
|
|
|
|
{
|
|
|
|
for(;;)
|
|
|
|
{
|
2018-09-02 22:25:09 -04:00
|
|
|
commandInfo = strtok(getDvar("sv_iw4madmin_command"), ";");
|
|
|
|
command = commandInfo[0];
|
|
|
|
commandArgs = strtok(commandInfo[1], ",");
|
2018-05-28 21:30:31 -04:00
|
|
|
|
2018-04-28 01:22:18 -04:00
|
|
|
switch(command)
|
|
|
|
{
|
|
|
|
case "balance":
|
2018-05-28 21:30:31 -04:00
|
|
|
BalanceTeams(commandArgs);
|
2018-04-28 01:22:18 -04:00
|
|
|
break;
|
2018-09-02 22:25:09 -04:00
|
|
|
case "alert":
|
|
|
|
//clientId alertType sound message
|
|
|
|
SendAlert(commandArgs[0], commandArgs[1], commandArgs[2], commandArgs[3]);
|
|
|
|
break;
|
2018-04-28 01:22:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setDvar("sv_iw4madmin_command", "");
|
|
|
|
wait(1);
|
|
|
|
}
|
2018-05-28 21:30:31 -04:00
|
|
|
}
|
|
|
|
|
2018-09-02 22:25:09 -04:00
|
|
|
SendAlert(clientId, alertType, sound, message)
|
|
|
|
{
|
2018-10-25 09:14:39 -04:00
|
|
|
client = getPlayerFromClientNum(clientId);
|
2018-09-02 22:25:09 -04:00
|
|
|
|
|
|
|
client thread playLeaderDialogOnPlayer(sound, client.team);
|
|
|
|
client playLocalSound(sound);
|
|
|
|
client iPrintLnBold("^1" + alertType + ": ^3" + message);
|
|
|
|
}
|
|
|
|
|
2018-10-25 09:14:39 -04:00
|
|
|
GetHttpString(url)
|
|
|
|
{
|
|
|
|
response = spawnStruct();
|
|
|
|
response.success = false;
|
|
|
|
response.data = undefined;
|
|
|
|
|
|
|
|
logPrint("Making request to " + url + "\n");
|
|
|
|
request = httpGet(url);
|
|
|
|
request waittill("done", success, data);
|
|
|
|
|
|
|
|
if(success != 0){
|
|
|
|
logPrint("Request succeeded\n");
|
|
|
|
response.success = true;
|
|
|
|
response.data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logPrint("Request failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2018-05-28 21:30:31 -04:00
|
|
|
BalanceTeams(commandArgs)
|
|
|
|
{
|
2018-10-25 09:14:39 -04:00
|
|
|
if (level.teamBased)
|
2018-05-28 21:30:31 -04:00
|
|
|
{
|
2018-10-25 09:14:39 -04:00
|
|
|
printOnPlayers("^5Balancing Teams...");
|
2018-05-28 21:30:31 -04:00
|
|
|
|
|
|
|
for (i = 0; i < commandArgs.size; i+= 2)
|
|
|
|
{
|
2018-10-25 09:14:39 -04:00
|
|
|
teamNum = int(commandArgs[i+1]);
|
|
|
|
clientNum = int(commandArgs[i]);
|
|
|
|
|
|
|
|
//printOnPlayers("[" + teamNum + "," + clientNum + "]");
|
|
|
|
|
|
|
|
if (teamNum == 2)
|
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
newTeam = "allies";
|
2018-10-25 09:14:39 -04:00
|
|
|
}
|
2018-06-05 17:31:36 -04:00
|
|
|
else
|
2018-10-25 09:14:39 -04:00
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
newTeam = "axis";
|
2018-10-25 09:14:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
player = getPlayerFromClientNum(clientNum);
|
2018-05-28 21:30:31 -04:00
|
|
|
|
2018-10-25 09:14:39 -04:00
|
|
|
//if (!isPlayer(player))
|
|
|
|
// continue;
|
2018-06-05 17:31:36 -04:00
|
|
|
|
2018-05-28 21:30:31 -04:00
|
|
|
switch (newTeam)
|
|
|
|
{
|
|
|
|
case "axis":
|
2018-10-25 09:14:39 -04:00
|
|
|
if (player.team != "axis")
|
|
|
|
{
|
|
|
|
//printOnPlayers("moving " + player.name + " to axis");
|
|
|
|
player[[level.axis]]();
|
|
|
|
}
|
2018-05-28 21:30:31 -04:00
|
|
|
break;
|
|
|
|
case "allies":
|
2018-10-25 09:14:39 -04:00
|
|
|
if (player.team != "allies")
|
|
|
|
{
|
|
|
|
//printOnPlayers("moving " + player.name + " to allies");
|
|
|
|
player[[level.allies]]();
|
|
|
|
}
|
2018-05-28 21:30:31 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
}
|