Sample: GPS

From SkyCorp Global
Revision as of 01:21, 30 December 2017 by SkyCorp (talk | contribs) (Created page with "{{EntityModHeader}} == Entity Details == ''This entity is intended for example purposes to demonstrate an object that can check its location and the player's location. It co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Note - this entity is a modification for The Underworld. Visit the new Mods Portal for more mods, mods on the wiki are no longer maintained. You can put it in-game by visiting the Debug Mod Control Panel in the debug rooms and browse to this mod or copy/paste the JSON below into the program window.

Entity Details

This entity is intended for example purposes to demonstrate an object that can check its location and the player's location. It could also be useful for finding the RoomID of various in-game rooms.

Author: SkyCorp

Entity JSON Code

{
	"type": "ENTITY",
	"name":
	{
		"literalString": "GPS"
	},
	"description":
	{
		"programString": true
	},
	"isPickupable":
	{
		"literalBoolean": true
	},
	"luac": "G0x1YVEAAQQEBAgACQAAAEBHUFMubHVhAAAAAAAAAAAAAAACAgMAAAAkAAAABwAAAB4AgAABAAAABAwAAABkZXNjcmlwdGlvbgABAAAAAAAAAAEAAAAdAAAAAAAABisAAAAFQAAABoBAAByAgAAHAAAAAQABAEFAAQAVQAAAB8AAAAUAAABFgAEAF0AAABaAAoAFwAEABgBCAByAgAAGgEAAHICAAAcAAAAFwAAAQUACABVAAAAHwAAAFsAAgAXAAABBgAIAFUAAAAfAAAAFwAAAQcACAIUAAACGAEMBwUADAAUBAAAGgUMCHIGAAAbBQwIcgYAAQQEEABVAAQAHwAAABcAAAB4AAAEeAIAAEQAAAAQJAAAAbG9jYXRpb24ABAUAAAB0aGlzAAQMAAAAZ2V0TG9jYXRpb24ABBAAAABkZXNjcmlwdGlvblRleHQABDcAAABUaGUgR1BTIGJsaW5rcywgZGlzcGxheWluZyBibGFjayB0ZXh0IG9uIGEgbGltZSBncmVlbiAABA4AAABMQ0Qgc2NyZWVuOiAnAAQFAAAAbnVsbAAEBwAAAFBsYXllcgAEDAAAAGdldEluc3RhbmNlAAQZAAAASW4gcGxheWVyJ3MgaW52ZW50b3J5IEAgAAQQAAAASW4gdGhlIHdvcmxkIEAgAAQIAAAAUm9vbUlEIAAEBwAAAHJvb21JRAAEBwAAACwgTWFwIAAEBwAAAGdldE1hcAAECAAAAGdldE5hbWUABAIAAAAnAAAAAAArAAAABQAAAAUAAAAFAAAABQAAAAgAAAAJAAAACQAAAAkAAAAMAAAADAAAAAwAAAAMAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEQAAABEAAAARAAAAEQAAABEAAAATAAAAEwAAABMAAAATAAAAFwAAABcAAAAXAAAAFwAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABsAAAAbAAAAHQAAAAAAAAAAAAAAAwAAAB0AAAABAAAAHQAAAAAAAAAAAAAA"
}

LUA Source Code

function description()

   -- 'this' is a predefined keyword that refers to this entity (in this case, 
   -- the GPS)
   location = this.getLocation();

   -- All text will be added to 'descriptionText' string, and returned.
   descriptionText = "The GPS blinks, displaying black text on a lime green " ..
      "LCD screen: '";

   -- Check if GPS item is in inventory or in world
   if location == null then
      -- Item's Location is null, which means GPS is in player inventory.
      -- Because of this, this script must check player location instead of
      -- item location.
      location = Player.getInstance().getLocation();
      descriptionText = descriptionText .. "In player's inventory @ ";
   else
      descriptionText = descriptionText .. "In the world @ ";
   end

   -- Add RoomID & Map Name to description text
   descriptionText = descriptionText .. "RoomID " .. location.roomID ..
      ", Map " .. location.getMap().getName() .. "'";

   -- Return text to be displayed by game
   return descriptionText;

end