Advertisement
Guest User

code

a guest
Mar 16th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. Script.playerInventoryMgr = "" --entity "Player Invent Mgr"
  2. Script.name = "ItemName" --string "Item name"
  3. Script.inventoryImagePath = "" --path "Inventory image" "Texture (*.tex):tex|Texture"
  4. Script.vwepfile=""--path "VWep" "Prefab (*pfb):pfb|Prefabs"
  5. --Script.vwep=nil--entity
  6.  
  7. function Script:Start()
  8. if self.vwepfile~="" then
  9. local prefab = Prefab:Load(self.vwepfile)
  10. if prefab~=nil then
  11. if prefab.script~=nil then
  12. self.vwep = prefab.script
  13. else
  14. prefab:Release()
  15. end
  16. end
  17. end
  18. end
  19.  
  20.  
  21. function Script:Use(player)
  22. --Just double checking if we have the inventory manager.
  23. if self.playerInventoryMgr == nil then
  24. error("no inventory manager set")
  25. else
  26. self.playerInventoryMgr = self.playerInventoryMgr.script
  27. end
  28. --We create an item that is going to store some information
  29. item = {}
  30.  
  31. --We then override that information with the properties we filled in the editor.
  32. item.name = self.name
  33. item.inventoryImagePath = self.inventoryImagePath
  34.  
  35. --Whatever should happen when you use this item, the code for it goes in this function.
  36. item.UseInventoryItem =
  37. function()
  38. System:Print("You clicked on the item in the inventory: ")
  39. function Script:Use(player)
  40. if self.vwep then
  41. if type(player.AddWeapon)=="function" then
  42. if player.weapons~=nil then
  43. if player.weapons[self.index]==nil then
  44. player:AddWeapon(self.vwep)
  45. self.entity:Hide()
  46. end
  47. end
  48. end
  49. end
  50. end
  51.  
  52. --We add the item to the inventory manager.
  53. self.playerInventoryMgr:AddItem(item.inventoryImagePath, item)
  54.  
  55. self.entity:Release()
  56. end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement