2016-06-16 01:50:13 +01:00
|
|
|
require("global");
|
|
|
|
|
|
|
|
properties = {
|
|
|
|
permissions = 0,
|
2016-06-17 05:05:31 +01:00
|
|
|
parameters = "sssss",
|
2016-08-11 20:02:01 -04:00
|
|
|
description =
|
|
|
|
[[
|
|
|
|
Adds <item> <qty> to <location> for player or <targetname>.
|
|
|
|
!giveitem <item> <qty> |
|
|
|
|
!giveitem <item> <qty> <location> |
|
|
|
|
!giveitem <item> <qty> <location> <targetname> |
|
|
|
|
]],
|
2016-06-16 01:50:13 +01:00
|
|
|
}
|
|
|
|
|
2016-06-17 05:05:31 +01:00
|
|
|
function onTrigger(player, argc, item, qty, location, name, lastName)
|
2016-06-16 01:50:13 +01:00
|
|
|
local sender = "[giveitem] ";
|
2016-08-11 20:02:01 -04:00
|
|
|
local messageID = MESSAGE_TYPE_SYSTEM_ERROR;
|
2017-10-09 23:40:38 -04:00
|
|
|
local worldMaster = GetWorldMaster();
|
2016-08-11 20:02:01 -04:00
|
|
|
|
2016-06-17 05:05:31 +01:00
|
|
|
if name then
|
|
|
|
if lastName then
|
|
|
|
player = GetWorldManager():GetPCInWorld(name.." "..lastName) or nil;
|
|
|
|
else
|
|
|
|
player = GetWorldManager():GetPCInWorld(name) or nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-06-16 01:50:13 +01:00
|
|
|
if player then
|
|
|
|
item = tonumber(item) or nil;
|
2017-10-09 23:40:38 -04:00
|
|
|
|
|
|
|
if not item then
|
|
|
|
player:SendMessage(messageID, sender, "Invalid parameter for item.");
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
2016-06-16 01:50:13 +01:00
|
|
|
qty = tonumber(qty) or 1;
|
|
|
|
|
2016-08-11 20:02:01 -04:00
|
|
|
if location then
|
2017-10-09 23:40:38 -04:00
|
|
|
location = _G[string.upper(location)];
|
2016-08-11 20:02:01 -04:00
|
|
|
|
|
|
|
if not location then
|
|
|
|
player:SendMessage(messageID, sender, "Unknown item location.");
|
|
|
|
return;
|
|
|
|
end;
|
|
|
|
else
|
|
|
|
location = INVENTORY_NORMAL;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2017-10-09 23:40:38 -04:00
|
|
|
local invCheck = player:getInventory(location):AddItem(item, qty, 1);
|
|
|
|
|
|
|
|
if (invCheck == INV_ERROR_FULL) then
|
|
|
|
-- Your inventory is full.
|
|
|
|
player:SendGameMessage(player, worldMaster, 60022, messageID);
|
|
|
|
elseif (invCheck == INV_ERROR_ALREADY_HAS_UNIQUE) then
|
|
|
|
-- You cannot have more than one <itemId> <quality> in your possession at any given time.
|
|
|
|
player:SendGameMessage(player, worldMaster, 40279, messageID, item, 1);
|
|
|
|
elseif (invCheck == INV_ERROR_SYSTEM_ERROR) then
|
|
|
|
player:SendMessage(MESSAGE_TYPE_SYSTEM, "", "[DEBUG] Server Error on adding item.");
|
|
|
|
elseif (invCheck == INV_ERROR_SUCCESS) then
|
|
|
|
message = string.format("Added item %s to location %s to %s", item, location, player:GetName());
|
|
|
|
player:SendMessage(MESSAGE_TYPE_SYSTEM, "", message);
|
|
|
|
player:SendGameMessage(player, worldMaster, 25246, messageID, item, qty);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 01:50:13 +01:00
|
|
|
end;
|