Custom Console Commands (Mission Script Dynamic) - reyandme/kam_remake GitHub Wiki
Those commands could be invoked from the game chat and that will trigger declared script procedure invokation.
Let's take a look on script example:
{$COMMAND showmsg:ShowMessageToPlayerCmd}
procedure ShowMessageToPlayerCmd(aHandID: Integer; aPlayerId: Integer; aMsg: String);
begin
Actions.ShowMsg(aPlayerId, aMsg);
end;
Then in the game when player type into the chat f.e.
/showmsg 1 'Hello friend'
message 'Hello friend' will be shown to player with HandId = 1
First we declare command with {$COMMAND showmsg:ShowMessageToPlayersCmd}, where showmsg
is command name and ShowMessageToPlayersCmd
is script procedure to invoke when get that command from player.
ShowMessageToPlayersCmd
procedure must have from 1 to 5 parameters, where first parameter type should be always Integer
, its reserved for HandId of the player, who invoked the command.
The remaining parameters must be one of the following types: Integer, String, Single or Boolean
.
Let's take a look on command invokation from game chat window:
/showmsg 1 'Hello friend'
First is forward slash /
, then command name showmsg
and then list of parameters separated by spaces. For string parameters you can use single quotes for messages with spaces inside them. And if you want to place single quote inside that string, then need to escape it with backslash \'
. For Single type parameters use '.' as decimal separator. Boolean could used as 'true' or 'false'.
One more example with all allowed parameters types
{$COMMAND setequiprate:SetEquipRateCmd}
procedure SetEquipRateCmd(aHandID: Integer; aAIPlayerId: Integer; aStrParam: String; aBoolParam: Boolean; aEquipModifier: Single);
var
EquipRate: Integer;
begin
A.ShowMsg(-1, aStrParam); //Show message to all players
if (aHandID = 0) and aBoolParam
and States.PlayerIsAI(aAIPlayerId)
and U.InRangeS(aEquipModifier, 0.5, 1.5) then
begin
EquipRate := States.AIEquipRate(aHandID, 0); //Get AI EquipRate
Actions.AIEquipRate(aAIPlayerId, 0, Round(EquipRate*aEquipModifier)); //Update Equip modifier of AI player from console
end;
end;
Then command invokation could be
/setequiprate 2 'Let\'s make game more difficult!' true 1.5
Then AI player 2 equip rate for leather will increase in 1.5 times.