Plutonium-T6-Scripts/chat_commands/chat_command_give.gsc
Resxt 384b32f33a chat_command_give 1.0.1
Fixed weapon not given to the proper player in some scenarios

Fixed player not switching to the weapon automatically in some scenarios

Fixed multiple attachments not working
2023-06-16 20:00:20 +02:00

97 lines
1.9 KiB
Plaintext

#include scripts\chat_commands;
Init()
{
CreateCommand(level.chat_commands["ports"], "giveweapon", "function", ::GiveWeaponCommand, 2);
}
/* Command section */
GiveWeaponCommand(args)
{
if (args.size < 2)
{
return NotEnoughArgsError(2);
}
error = GivePlayerWeapon(args[0], args[1], args[2], true, true);
if (IsDefined(error))
{
return error;
}
}
/* Logic section */
GivePlayerWeapon(targetedPlayerName, weaponName, camoIndex, takeCurrentWeapon, playSwitchAnimation)
{
player = FindPlayerByName(targetedPlayerName);
if (!IsDefined(player))
{
return PlayerDoesNotExistError(targetedPlayerName);
}
weaponName = ToLower(weaponName);
weaponSplitted = StrTok(weaponName, "+");
weaponName = weaponSplitted[0];
attachments = "";
for (i = 1; i < weaponSplitted.size; i++)
{
if (i == 1)
{
attachments += weaponSplitted[i];
}
else
{
attachments += "+" + weaponSplitted[i];
}
}
if (IsMultiplayerMode())
{
if (GetSubStr(weaponName, weaponName.size - 3, weaponName.size) != "_mp")
{
weaponName += "_mp";
}
}
if (!IsValidWeapon(weaponName))
{
return WeaponDoesNotExistError(weaponName);
}
finalCamoIndex = 0;
if (IsDefined(camoIndex))
{
finalCamoIndex = int(camoIndex);
}
if (IsDefined(takeCurrentWeapon) && takeCurrentWeapon)
{
player TakeWeapon(player GetCurrentWeapon());
}
if (IsDefined(attachments))
{
weaponName = weaponName + "+" + attachments;
}
player GiveWeapon(weaponName, 0, finalCamoIndex);
if (IsDefined(playSwitchAnimation) && playSwitchAnimation)
{
player SwitchToWeapon(weaponName);
}
else
{
player SetSpawnWeapon(weaponName);
}
}