Skip to content

Instantly share code, notes, and snippets.

@8bitgentleman
Last active August 29, 2015 14:05
Show Gist options
  • Save 8bitgentleman/886fd907fa0cb90d3a91 to your computer and use it in GitHub Desktop.
Save 8bitgentleman/886fd907fa0cb90d3a91 to your computer and use it in GitHub Desktop.
hide/show npc talk items
--this is an example of what talk_items could look like in the npc's file
{ ['text']='flowers', freeze = true, affection = 5 },
--The first for loop looks for the "options” key in the root table of the talk_items. Inside this table we can look for all items in the table that have an affection attribute.
--If the affection attribute is lower than the player affection then we remove the item from the table.
function Menu:itemUpdate( npc, player)
--adds and removes items from the talk items based on affection level
local Player = require 'player'
local player = Player.factory()
local affection = player.affection[self.name] or 0
local props = require('npcs/' .. self.name)
for k,v,w in pairs(self.props.talk_items) do
if v["option"] then
for kk,vv,ww in pairs(v["option"]) do
if vv['affectionMin'] and vv['affectionMin'] <= affection then--and ww['affectionMax'] and ww['affectionMax'] >= affectionthen
table.remove(self.props.talk_items[k]["option"],kk)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment