can i give items to a player using chat like this
?give (player name) (item quantity) (item)
the part of the item quantity dont need to be added on the script its just optional
can i give items to a player using chat like this
?give (player name) (item quantity) (item)
the part of the item quantity dont need to be added on the script its just optional
Yes, you can loop through all item types in the game to find an item type whose name matches the one specified in your command. Then, loop through all players in human players to find a player whose name matches the name specified. Finally, give the selected item type to the unit owned by the selected player.
Here is a script you could use.
{
"triggers": [
{
"type": "playerSendsChatMessage"
}
],
"actions": [
{
"type": "condition",
"conditions": [
{
"operandType": "boolean",
"operator": "=="
},
{
"function": "getPlayerName",
"entity": {
"function": "getTriggeringPlayer"
}
},
"kyle69"
],
"then": [
{
"type": "condition",
"conditions": [
{
"operandType": "boolean",
"operator": "=="
},
{
"function": "stringStartsWith",
"sourceString": {
"function": "getLastChatMessageSentByPlayer",
"player": {
"function": "getTriggeringPlayer"
}
},
"patternString": "/give "
},
true
],
"then": [
{
"type": "forAllItemTypes",
"itemTypeGroup": {
"function": "allItemTypesInGame"
},
"actions": [
{
"type": "condition",
"conditions": [
{
"operandType": "boolean",
"operator": "=="
},
{
"function": "stringEndsWith",
"sourceString": {
"function": "getLastChatMessageSentByPlayer",
"player": {
"function": "getTriggeringPlayer"
}
},
"patternString": {
"function": "getItemTypeName",
"itemType": {
"function": "selectedItemType"
}
}
},
true
],
"then": [
{
"type": "forAllPlayers",
"playerGroup": {
"function": "humanPlayers"
},
"actions": [
{
"type": "condition",
"conditions": [
{
"operandType": "boolean",
"operator": "=="
},
{
"function": "substringOf",
"string": {
"function": "getLastChatMessageSentByPlayer",
"player": {
"function": "getTriggeringPlayer"
}
},
"fromIndex": 8,
"toIndex": {
"function": "calculate",
"items": [
{
"operator": "-"
},
{
"function": "getLengthOfString",
"string": {
"function": "getLastChatMessageSentByPlayer",
"player": {
"function": "getTriggeringPlayer"
}
}
},
{
"function": "calculate",
"items": [
{
"operator": "+"
},
1,
{
"function": "getLengthOfString",
"string": {
"function": "getItemTypeName",
"itemType": {
"function": "selectedItemType"
}
}
}
]
}
]
}
},
{
"function": "getPlayerName",
"entity": {
"function": "selectedPlayer"
}
}
],
"then": [
{
"type": "forAllUnits",
"unitGroup": {
"function": "allUnitsOwnedByPlayer",
"player": {
"function": "selectedPlayer"
}
},
"actions": [
{
"type": "giveNewItemToUnit",
"itemType": {
"function": "selectedItemType"
},
"unit": {
"function": "selectedUnit"
}
}
]
},
{
"type": "break"
}
],
"else": []
}
]
},
{
"type": "break"
}
],
"else": []
}
]
}
],
"else": []
}
],
"else": []
}
],
"name": "/give <player> <item>"
}