Page 1 of 1

re - usable lock?

Posted: Sun Jul 10, 2016 3:50 pm
by bongobeat
Hello,

is that possible to someone to script a lock / socket that can acccept multiple items (different items)?

Then, after an item is inserted, it reset the lock and the lock can be re used with the same item or another one.

(The idea is something similar to a floppy drive, where you put all disks in the device, in a lock in that case, to print journal log.)

I got the device, I got a basic lock, but ... I need a script, someone can help please?
SpoilerShow
Image

Re: re - usable lock?

Posted: Sun Jul 10, 2016 4:30 pm
by kelly1111
What kind of dungeon are you making?
very interrested in your project !

Re: re - usable lock?

Posted: Sun Jul 10, 2016 4:51 pm
by Isaac
What you do, is add an onAcceptItem() hook to your [socket] "lock". In the hook, you can detect the inserted item, and cause specific results.

If you are making a holo-tape /disk interface, then check for item.go.id for specific floppy disks, (via table), and use the id as a table key (variable name) for the contents of the disk. You can use the item.go.name to detect floppies, and refuse all other items; and more than one.

example:

Code: Select all

			onAcceptItem = function(self, item)
				print(item.go.name,item.go.id)
				local disks = { ["blueberry_pie_1"]= "This pie has specs of dirt on it!",
								["blueberry_pie_2"]= "This pie has been nibbled at already!",
								["blueberry_pie_3"]= "This pie is rotten!", }
				if disks[item.go.id] then
					hudPrint(disks[item.go.id])
				end				
								
				return item.go.name == "blueberry_pie" and self.go.socket:count() == 0
			end
		},
*Unless you are planning something else ~not apparent from your description.

**Updated example.

Of course, you could change it to play cutscenes, or audio files instead, or as well as hudPrint text messages.

Re: re - usable lock?

Posted: Sun Jul 10, 2016 7:09 pm
by minmay
To make a lock reusable just re-enable it in its onActivate hook.

Code: Select all

{
	class = "Lock",
	onActivate = function(self)
		self:enable()
	end,
},

Re: re - usable lock?

Posted: Sun Jul 10, 2016 7:21 pm
by Isaac
minmay wrote:To make a lock reusable just re-enable it in its onActivate hook.

Code: Select all

{
	class = "Lock",
	onActivate = function(self)
		self:enable()
	end,
},
There is that too. :mrgreen:
(And that one eats keys; and it needs to be self.go.lock:enable())

I suppose this could be used with a counter, to ask for disk1, disk2, and disk3, for instance.

Re: re - usable lock?

Posted: Mon Jul 11, 2016 10:11 am
by minmay
Isaac wrote:it needs to be self.go.lock:enable().
No it doesn't, what do you think self is in this hook?

Re: re - usable lock?

Posted: Mon Jul 11, 2016 11:18 am
by Isaac
minmay wrote:
Isaac wrote:it needs to be self.go.lock:enable().
No it doesn't, what do you think self is in this hook?
Well... When I tried it as [I mistakenly thought] you typed it (assuming by default that it was surely the correct way; as usual)... It did not work, and the game crashed... but when I added .go. it did work; and still does.. :?
So I posted it.

Image
SpoilerShow
*But only after I posted (as usual), did I see that I had misread what you typed, and that of course it works also.

Re: re - usable lock?

Posted: Sat Jul 16, 2016 4:55 pm
by bongobeat
thanks all for your answers, I'm gonna study this
kelly1111 wrote:What kind of dungeon are you making?
very interrested in your project !

Its a large world to explore, following a main story, with sci fi levels (for end levels).

Re: re - usable lock?

Posted: Mon Jul 18, 2016 7:21 pm
by bongobeat
Thanks to Isaac, here is a full script:

object:
SpoilerShow

Code: Select all

defineObject{
	name = "indus_wall_biodome_log_console_lock",
	components = {
		{
			class = "Socket",
			offset = vec(-0.005, .895, -0.1),
			rotation = vec(0, 18, 0),
		--	debugDraw = true,
        	onAcceptItem = function(self, item) 
	            local disks = {   ["disklog_1"]= {"Drakes have destroyed the Biodome Sector 1 with most repair droids in it!",
	            								  "Things are getting worse, where is our goddam fleet?","Colonel Rangson."},

	                              ["disklog_2"]= {"A long list of things to do, repairing console N29, Security Door 18 malfunction,",
	                              				  "Changing access codes to the command center and alpha center, current 97887,",
	                              				  "leak in the cooling system sector 5..."},
	                             
	                              ["disklog_3"] = {"This pie is rotten!"}, 
	                          }

		            if disks[item.go.id] then
		            playSound("ogre_rush_begin")	            
			            -- Place your own events here.|

			            			-- If you don't want the hudPrinted text, you can remove the hudPrint statements and loops.
									-- If you like, you could make each disklog_x value [in 'disks'] be a function() instead of a string;
									-- and call them like this:  
									--	 disks[item.go.id]()
									-- Each disklog inserted would call its own function in disks.	
									-- Example:
											--|-------------------------------------------------------------|-- 
													disks["disklog_3"] = function(self)
																			my_door.door:open()
																			for line = 1, 5 do hudPrint("") end --clears hud text
																			hudPrint("Security Door is "..iff(my_door.door:isOpening(),"","already ").."Unlocked!")
																		 end

													if item.go.id == "disklog_3" then
														disks[item.go.id]()
														return
													end
											--|-------------------------------------------------------------|--
									--
									--
							--hudPrint code		
			            	 for line = 1, 5 do hudPrint("") end
			            	 for line = 1, #disks[item.go.id] do
				                hudPrint(disks[item.go.id][line])
				             end   
									
			            -- ========================================|

		            end
	            return item.go.name == "disklog" and self.go.socket:count() == 0
	        end,
		},
	    {
	        class = "Clickable",
	        offset = vec(0, 1, 0),
	        size = vec(0.3, 0.3, 0.4),
	       -- debugDraw = true,
	    },
	    {
	        class = "Model",
	        model = "assets/models/env/wall_lock.fbx",
	        offset = vec(0, 1, 0),
	        staticShadow = true,
	        enabled = true,
	    },
		{
			class = "Occluder",
			model = "assets/models/env/dungeon_wall_01_occluder.fbx",
		}
	},
	replacesWall = false,
	placement = "wall",
	editorIcon = 8,
}
item to use (example):
SpoilerShow

Code: Select all

defineObject{
   name = "disklog",
   baseObject = "pellet_box",
   components = {
	   		{
			class = "Item",
			uiName = "Pellets",
			gfxIndex = 334,
			gfxIndexInHand = 335,
			stackable = false,
			multiple = 10,
			weight = 0.05,
			onInit = function(self) self.go.item:setUiName("Disk Log "..string.sub(self.go.id, -1)) end,
			},
		}
}
and an example dungeon: https://www.dropbox.com/s/z4pz87th6cug3 ... k.zip?dl=0

edit : I've modified the sound into a well known more versatile build-in sound 8-)

Re: re - usable lock?

Posted: Mon Jul 18, 2016 7:57 pm
by Isaac
In the script, playSound("lab_alarm"), should probably be commented out unless one has defined a sound by that name.

*One could also include two functions to play 'disk-insert & removal' sound effects, connecting them to the socket-'lock', and they would play when the disk was placed or pulled.

** This script is was meant as a display of options, with the custom disk-keyed function call being slipped in as an afterthought. It's meant more as a guide for writing your own [better] script, than to be used as-is;
though it works as-is. ;)

***Also The UiName setting script for the disklog item, was a quick convenience for the example project... It only supports 10 disks, and the 10th will be misnamed as disklog_0; and with subsequent disks repeating 1-9.