-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic things attributes modification talkaction (#3587)
- Loading branch information
1 parent
e1feac2
commit 89ef7b0
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function onSay(player, words, param) | ||
if not player:getGroup():getAccess() then | ||
return true | ||
end | ||
|
||
local position = player:getPosition() | ||
position:getNextPosition(player:getDirection()) | ||
|
||
local tile = Tile(position) | ||
if not tile then | ||
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is no tile in front of you.") | ||
return false | ||
end | ||
|
||
local thing = tile:getTopVisibleThing(player) | ||
if not thing then | ||
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is an empty tile in front of you.") | ||
return false | ||
end | ||
|
||
local separatorPos = param:find(',') | ||
if not separatorPos then | ||
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("Usage: %s attribute, value.", words)) | ||
return false | ||
end | ||
|
||
local attribute = string.trim(param:sub(0, separatorPos - 1)) | ||
local value = string.trim(param:sub(separatorPos + 1)) | ||
|
||
if thing:isItem() then | ||
local attributeId = Game.getItemAttributeByName(attribute) | ||
if attributeId == ITEM_ATTRIBUTE_NONE then | ||
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Invalid attribute name.") | ||
return false | ||
end | ||
|
||
if not thing:setAttribute(attribute, value) then | ||
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Could not set attribute.") | ||
return false | ||
end | ||
|
||
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("Attribute %s set to: %s", attribute, thing:getAttribute(attributeId))) | ||
position:sendMagicEffect(CONST_ME_MAGIC_GREEN) | ||
else | ||
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Thing in front of you is not supported.") | ||
return false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters