Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Script.playerInventoryMgr = "" --entity "Player Invent Mgr"
- Script.name = "ItemName" --string "Item name"
- Script.inventoryImagePath = "" --path "Inventory image" "Texture (*.tex):tex|Texture"
- Script.vwepfile=""--path "VWep" "Prefab (*pfb):pfb|Prefabs"
- --Script.vwep=nil--entity
- function Script:Start()
- if self.vwepfile~="" then
- local prefab = Prefab:Load(self.vwepfile)
- if prefab~=nil then
- if prefab.script~=nil then
- self.vwep = prefab.script
- else
- prefab:Release()
- end
- end
- end
- end
- function Script:Use(player)
- --Just double checking if we have the inventory manager.
- if self.playerInventoryMgr == nil then
- error("no inventory manager set")
- else
- self.playerInventoryMgr = self.playerInventoryMgr.script
- end
- --We create an item that is going to store some information
- item = {}
- --We then override that information with the properties we filled in the editor.
- item.name = self.name
- item.inventoryImagePath = self.inventoryImagePath
- --Whatever should happen when you use this item, the code for it goes in this function.
- item.UseInventoryItem =
- function()
- System:Print("You clicked on the item in the inventory: ")
- function Script:Use(player)
- if self.vwep then
- if type(player.AddWeapon)=="function" then
- if player.weapons~=nil then
- if player.weapons[self.index]==nil then
- player:AddWeapon(self.vwep)
- self.entity:Hide()
- end
- end
- end
- end
- end
- --We add the item to the inventory manager.
- self.playerInventoryMgr:AddItem(item.inventoryImagePath, item)
- self.entity:Release()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement