Page 259 of 391

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 16, 2018 4:08 pm
by Pompidom
I believe I got this from an old asset pack from bongo. If you go back a few pages in this topic, you will find the link where I was asking about shadow removers. I will be available tonight for further help. As i have to go now somewhere and can't reply.

edit: viewtopic.php?f=22&t=9320&hilit=bongobeat+assets

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 16, 2018 4:34 pm
by billb52
Hi All
I have found a 'defineObject' for a re-useable lock:

defineObject{
name = "re-usable_lock",
components = {
{
class = "Model",
model = "assets/models/env/wall_lock.fbx",
offset = vec(0, 1.375, 0),
staticShadow = true,
},
{
class = "Clickable",
offset = vec(0, 1.375, 0),
size = vec(0.4, 0.4, 0.4),
--debugDraw = true,
},
{
class = "Lock",
onActivate = function(self)
self:enable()
sound = "key_lock",
end
},
},
placement = "wall",
editorIcon = 20,
}
but when I put it in my objects.lua I get an error: mod_assets/scripts/object.lua:27: unexpected symbol near 'end'
Is there something wrong with the code? any help pls.

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 16, 2018 5:37 pm
by maneus
Your script have to show like this:
defineObject{
name = "reusable_lock",
components = {
{
class = "Model",
model = "assets/models/env/wall_lock.fbx",
offset = vec(0, 1.375, 0),
staticShadow = true,
},
{
class = "Clickable",
offset = vec(0, 1.375, 0),
size = vec(0.4, 0.4, 0.4),
--debugDraw = true,
},
{
class = "Lock",
sound = "key_lock",
onActivate = function(self)
self:enable()

end
},
},
placement = "wall",
editorIcon = 20,
}
Don´t use a "minus" in your names. It will crash the editor (like it did in my place).
Then you have to replace the line "sound = "key_lock",". Set it direct after "class = "Lock",".
That should be all.

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 16, 2018 8:47 pm
by Isaac
KhrougH wrote: Tue Oct 16, 2018 3:40 pm i would like to use this thing with different locks, so i prefer a script into the map instead making other 10 different defineObject.
and with my script i don't have to set the offset for every lock. the routine identify itself.
It's a time-saver to do it as definitions; they don't need scripted adjustment.

Alternatively, you can change the visual appearance of any lock by assigning it a different lock model via script.

Code: Select all

side_door_lock_1.model:setModel("assets/models/env/wall_lock_ornament.fbx")
side_door_lock_2.model:setModel("assets/models/env/wall_lock_golden.fbx")
side_door_lock_3.model:setModel("assets/models/env/wall_lock_gear.fbx")

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 16, 2018 9:24 pm
by billb52
Hi maneus thx for your speedy reply, all OK now

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 16, 2018 11:33 pm
by KhrougH
Isaac wrote: Tue Oct 16, 2018 8:47 pm
KhrougH wrote: Tue Oct 16, 2018 3:40 pm i would like to use this thing with different locks, so i prefer a script into the map instead making other 10 different defineObject.
and with my script i don't have to set the offset for every lock. the routine identify itself.
It's a time-saver to do it as definitions; they don't need scripted adjustment.

Alternatively, you can change the visual appearance of any lock by assigning it a different lock model via script.

Code: Select all

side_door_lock_1.model:setModel("assets/models/env/wall_lock_ornament.fbx")
side_door_lock_2.model:setModel("assets/models/env/wall_lock_golden.fbx")
side_door_lock_3.model:setModel("assets/models/env/wall_lock_gear.fbx")
:o

Oh, my gosh...
I have so much to learn!!!
:oops:

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 16, 2018 11:44 pm
by KhrougH
Isaac wrote: Tue Oct 16, 2018 8:47 pm Alternatively, you can change the visual appearance of any lock by assigning it a different lock model via script.

Code: Select all

side_door_lock_1.model:setModel("assets/models/env/wall_lock_ornament.fbx")
side_door_lock_2.model:setModel("assets/models/env/wall_lock_golden.fbx")
side_door_lock_3.model:setModel("assets/models/env/wall_lock_gear.fbx")
Ok, it sounds good but than i could also randomize the lock's model but than i need to recognize it for using the correct key.
Or changing models also change the usable key?

Re: Ask a simple question, get a simple answer

Posted: Wed Oct 17, 2018 2:05 am
by Isaac
Every object has a name (usually different from its ID). The ID can be anything, but is commonly either a number, or the name with a number appended to it. To identify an object, you inspect its ID, and possibly its name. The script that your locks are connected to receives a reference to the lock (as its first argument) when gets called. You can use this variable name while in the function to access the lock's name, id, and any of its other properties; you can assign changes to the object through this.
__________

If you tell us exactly what behavior it is that you need, then the member suggestions for how to achieve it can be given with an understanding of the effect that you want—and choose the most suitable methods for it.
__________

The way to adjust the locks is to use a script with a table in it that contains matched pairs of model, and key. That way each lock can be set with an appearance, and its proper key.
  • side_door_lock_1.model:setModel("assets/models/env/wall_lock_ornament.fbx")
  • side_door_lock_1.model:setOpenedBy("ornate_key")
For that matter, the table can additionally contain what it should open, and the lock be given a connection to the specified object.
  • side_door_lock_1.lock:addConnector("onActivate", "dungeon_iron_door_14", "open" )
The lock_table could either be three values, per every lock, or a table of tables where each one has the three values needed to style the lock.

{"wall_lock_ornament", "ornate_key", "dungeon_iron_door_14"}

Re: Ask a simple question, get a simple answer

Posted: Wed Oct 17, 2018 2:45 am
by KhrougH
Isaac wrote: Wed Oct 17, 2018 2:05 am If you tell us exactly what behavior it is that you need, then the member suggestions for how to achieve it can be given with an understanding of the effect that you want—and choose the most suitable methods for it.
you're right i'll try to be as clear as possible:

so let's say i'm setting up a town. some doors are locked.
lock is on a side and doors are clickable:disable()
i did this with a cycle, pretty easy:
SpoilerShow

Code: Select all

LOK = 100
for i = 1, LOK do
	local DL = findEntity("doorlock_"..i)
	local OD = findEntity("openingDoor_"..i)
	if (DL or OD) == nil then
		break
	else
		DL.model:setOffset(vec(-1.15,1.2,-0.01))
		DL.clickable:setOffset(vec(-1.15,1.2,-0.01))
		OD.clickable:disable()
	end
end
so of corse "doorlock_"..i are locks and "openingDoors_"..i are doors. LOK is a resonable number just because doesn't matter how many cycles we set , it will stop when "findEntity" is equal to "nil". i don't have to explain, you know better than me what this script does :D

even if you gave me several suggestion i'm still on this one because i can use it with all the locks and all the doors unless they are right named. so FOR THE MOMENT i can say is the best solution for my possibilities.

now. the next question is:
every lock is linked to a function that don't open the door, make just the door clickable:enable() .
SpoilerShow

Code: Select all

function serratura1()
	openingDoor_1.clickable:enable()
end

function serratura2()
	openingDoor_2.clickable:enable()
end

function serratura3()
	openingDoor_3.clickable:enable()
end

function serratura4()
	openingDoor_4.clickable:enable()
end

function serratura5()
	openingDoor_5.clickable:enable()
end

function serratura6()
	openingDoor_6.clickable:enable()
end

function serratura7()
	openingDoor_7.clickable:enable()
end
so after using the key you still have to push the door. and is fine. i like it.
I only would like to know how to make it "shorter" like for the "offsett"ing and "clickable:disable"ing.
so i can connect every lock just to one function and the function detects which lock i unlocked and open the relative door.

maybe a cycle with lock.go.id . it could identify the lock ... i was thinking about the alcove opening door with a specified object
SpoilerShow

Code: Select all

function skelAlc(surface, item)
	for v,i in surface:contents() do
		if i.go.name == item then return true
		end
	end
end

function skelOpenDoor()

	if skelAlc(alcoveSkel.surface, "figure_skeleton") then
		secretwall.door:open()
	else
		secretwall.door:close()
	end
end	
i'm asking in this way because i think i can use also in other situations. to know a script about how to identify an object on the map could be really helpful. but if you think a table could be the best solution for this situation i just follow your suggestion :) ... your = Isaac , because is the one who's answering , but is a question open to everyone, of corse.
thanks for your patience, guys

Re: Ask a simple question, get a simple answer

Posted: Wed Oct 17, 2018 8:38 am
by Isaac
KhrougH wrote: Wed Oct 17, 2018 2:45 am i did this with a cycle, pretty easy:
SpoilerShow

Code: Select all

LOK = 100
for i = 1, LOK do
	local DL = findEntity("doorlock_"..i)
	local OD = findEntity("openingDoor_"..i)
	if (DL or OD) == nil then
		break
	else
		DL.model:setOffset(vec(-1.15,1.2,-0.01))
		DL.clickable:setOffset(vec(-1.15,1.2,-0.01))
		OD.clickable:disable()
	end
end
There is a built in iterator for this. ;)

Code: Select all

for level = 1, Dungeon:getMaxLevels() do
	for obj in Dungeon.getMap(level):allEntities() do 
		if not obj.chest then
			if obj.lock or obj.door then

				print('Name:', obj.name, "ID:", obj.id, "Level:",obj.level)

			end	
		end
	end
end	
*Also... KhrougH, there is a better and more up-to-date scripting reference than the one featured on this site; (thanks to JKos and minmay).
https://github.com/JKos/log2doc/wiki

** In the above (spoilered) condition: if (DL or OD) == nil then break ...end, it only breaks if DL and OD are both nil at the same time—and not when just one of them is nil. That's a crash if it ever finds one but not both.