chat_command_points 1.1.0

Added the givepoints command that allows player to give some of their points to another player (basically transfer points)
This commit is contained in:
Resxt
2023-10-09 18:49:58 +02:00
parent 9677af1641
commit 54c2c70b30
2 changed files with 44 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ Init()
CreateCommand(level.chat_commands["ports"], "setpoints", "function", ::SetPointsCommand, 3);
CreateCommand(level.chat_commands["ports"], "addpoints", "function", ::AddPointsCommand, 3);
CreateCommand(level.chat_commands["ports"], "takepoints", "function", ::TakePointsCommand, 3);
CreateCommand(level.chat_commands["ports"], "givepoints", "function", ::GivePointsCommand, 2, [], array("pay", "transferpoints"));
}
@@ -56,6 +57,21 @@ TakePointsCommand(args)
}
}
GivePointsCommand(args)
{
if (args.size < 2)
{
return NotEnoughArgsError(2);
}
error = GivePoints(args[0], args[1]);
if (IsDefined(error))
{
return error;
}
}
/* Logic section */
@@ -94,4 +110,29 @@ TakePlayerPoints(playerName, points)
}
player.score -= int(points);
}
GivePoints(playerName, points)
{
player = FindPlayerByName(playerName);
if (!IsDefined(player))
{
return PlayerDoesNotExistError(playerName);
}
if (int(points) <= 0)
{
return;
}
if (int(self.score) >= int(points))
{
self.score -= int(points);
player.score += int(points);
}
else
{
return NotEnoughPointsError();
}
}