Mr. Project DX

Discuss and unveil current Marathon projects.
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

To be completely honest, I really don't know what I am doing in Lua. I'll just put that out there, and hope that someone can point out at least the most serious flaws in what I have produced so far...

This is the test for my ideas I mentioned earlier. Aleph One doesn't even want to make it seem to work, so I figure there's a stupid mistake in here somewhere, I'm just not experienced or knowledgeable to see where it is.

Code: Select all

Triggers = {}


--Mnemonic Definitions
    --Scenery
        --Security Monitor (c22s12): Hinged Door
        SceneryTypes["security monitor"] = "hinged door"


--Init Routines
function Triggers.init()
    
    for p in Players() do
        p.overlays[0].text = "Hinged Door Test Active"
    end
    
    for s in Scenery() do
        if s.type == "hinged door" then
            s._is_door = true
            Set_Hinge(s)
        end
    end
    
end


--Idle Routines
function Triggers.idle()

    if Players[0].action_flags.action_trigger then
        Players.print("You just pressed the action key at something.")
        local o, x, y, z, polygon = Players[0]:find_target()
        if is_scenery(o) then
            Players.print("Ok, it's scenery.")
            Check_Object_Type(o)
        end    
    end
    
    for s in Scenery() do
        if s._is_door and s._is_moving then
            if s._direction == opening then
                if s.facing < s._objective_angle then
                    s.facing = s.facing + 1
                    local dx = s._hinge_x + (math.cos(math.rad(s.facing) * 0.25)
                    local dy = s._hinge_y + (math.sin(math.rad(s.facing) * 0.25)
                    s:position(dx, dy, s.z, s.polygon)
                else
                    s._is_moving = false
                end
            else
                if s.facing > s._objective_angle then
                    s.facing = s.facing - 1
                    local dx = s._hinge_x + (math.cos(math.rad(s.facing) * 0.25)
                    local dy = s._hinge_y + (math.sin(math.rad(s.facing) * 0.25)
                    s:position(dx, dy, s.z, s.polygon)
                else
                    s._is_moving = false
                end
            end
        end
    end

end

--This determines the x,y coordinates of where the door's hinge will be, depending on the door's starting position
function Set_Hinge(target)
    local hx = math.cos(math.rad(target.facing + 180) * 0.25
    local hy = math.sin(math.rad(target.facing + 180) * 0.25
    target._hinge_x = hx + target.x
    target._hinge_y = hy + target.y
end

--This makes sure that it's a door we're opening.
--For later use, this will also determine if it is any other kind of interactive scenery, such as a terminal.
function Check_Object_Type(target)
    if target.type == "hinged door" then
        Players.print("Ok, it's a hinged door. Let's open it.")
        Open_Door(target)
    end
end

--This toggles the door's status.
function Open_Door(target)
    if target._is_open then
        target._direction = closing
        target._objective_angle = target.facing - 90
        else
        target._direction = opening
        target._objective_angle = target.facing + 90
    end
    target._is_moving = true
end
Image
User avatar
treellama
Vidmaster
Posts: 6107
Joined: Jun 2nd '06, 02:05
Location: Pittsburgh
Contact:

Hmm, if you use pastebin for long scripts, you can have it do syntax highlighting, which helps a lot in readability.

My first suggestion is this line:

Code: Select all

SceneryTypes["security monitor"] = "hinged door"
Needs to be

Code: Select all

SceneryTypes["security monitor"].mnemonic = "hinged door"
The rest of the script might work a lot better once you actually get that mnemonic set.
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

Treellama wrote:Hmm, if you use pastebin for long scripts, you can have it do syntax highlighting, which helps a lot in readability.

My first suggestion is this line:

Code: Select all

SceneryTypes["security monitor"] = "hinged door"
Needs to be

Code: Select all

SceneryTypes["security monitor"].mnemonic = "hinged door"
The rest of the script might work a lot better once you actually get that mnemonic set.
Thanks. First time I've messed with mnemonics, so I guess I should have suspected that.

Here it is with the syntax highlighting:
http://pastebin.com/m55f72c16

Alright, so I fixed the mnemonic, but it still won't turn over. Is there anything else that pops out as utterly broken?
Last edited by Kurinn on Feb 19th '10, 20:00, edited 1 time in total.
Image
User avatar
treellama
Vidmaster
Posts: 6107
Joined: Jun 2nd '06, 02:05
Location: Pittsburgh
Contact:

I don't see anything off-hand. Which debug messages are getting printed?
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

Treellama wrote:I don't see anything off-hand. Which debug messages are getting printed?
There are no debug messages. The log file is blank.
Image
User avatar
treellama
Vidmaster
Posts: 6107
Joined: Jun 2nd '06, 02:05
Location: Pittsburgh
Contact:

Uh, so none of the Players.print statements triggers?
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

Treellama wrote:Uh, so none of the Players.print statements triggers?
Yeah, I put them in there to have quick feedback in testing this thing, but none of them work, even the action key one.

I moved the overlay setup into idle from init to be sure that wasn't the problem, and then I removed it altogether.
Image
User avatar
treellama
Vidmaster
Posts: 6107
Joined: Jun 2nd '06, 02:05
Location: Pittsburgh
Contact:

Code: Select all

[email protected] ~ $ luac kurinn.lua
luac: kurinn.lua:45: ')' expected (to close '(' at line 44) near 'local'
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

Treellama wrote:

Code: Select all

[email protected] ~ $ luac kurinn.lua
luac: kurinn.lua:45: ')' expected (to close '(' at line 44) near 'local'
Ugh, it was something stupid. Alright, I cleaned up all the parentheses... let's see what happens.

Okay, the script is working. Now I need to make it work *properly*.

Thank you very much, Treellama.


Update:

Okay, so it works, kind of. The door opens, but does not close. I fucked something up.

Update 2: Electric Boogaloo - I made a dumb mistake, I forgot to put something in quotations.

Here's how the lua script looks now, if anyone is curious:

http://kurinn.pastebin.com/m4d838918
Last edited by Kurinn on Feb 19th '10, 21:19, edited 1 time in total.
Image
User avatar
irons
Vidmaster
Posts: 2651
Joined: Mar 1st '06, 20:44
Location: (.Y.)
Contact:

Protip: any time you have a Lua script that appears to be doing nothing at all and you get no error messages on-screen, the problem is almost guaranteed to be in Triggers.init() or in global (outside of a function). From there, you can track it through idle; a lot of the time when something goes wrong in init, it ends up affecting idle (e.g. some table or variable was never created). The script dies before the game actually starts, and the errors don't show up because it's too early. This confusion held up one of my Lua projects for years. Treellama is working on some kind of solution for this because I own him.
Last edited by irons on Feb 19th '10, 21:13, edited 1 time in total.
underworld : simple fun netmaps // prahblum peack : simple rejected netmaps
azure dreams : simple horrible netmaps // v6.0!!!: thomas mann's greatest hits : simple simple netmaps
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

irons wrote:Protip: any time you have a Lua script that appears to be doing nothing at all and you get no error messages on-screen, the problem is almost guaranteed to be in Triggers.init() or in global (outside of a function). From there, you can track it through idle; a lot of the time when something goes wrong in init, it ends up affecting idle (e.g. some table or variable was never created). The script dies before the game actually starts, and the errors don't show up because it's too early. This confusion held up one of my Lua projects for years. Treellama is working on some kind of solution for this because I own him.
Yeah, I've begun to notice that pattern myself. It drives me nuts.

Update:

Alright, so now I've made things fairly solid in terms of getting the door to open and close reliably, without any movement out of bounds or troublesome errors. Now I need to implement all that distance-limit stuff for the find_target, etc.

With a .5 WU doorway, the radius of the door's solid body can only be around 60/1024 WU's if you want to get in and out of an open door without snagging too much. It's fairly transparent to projectiles, but I don't think that should be an issue, given that I don't expect to put these in places where there will be monsters, or too much projectile fire. Then again, I don't know many mass-produced metal-frame doors that would stop a large caliber bullet in it's tracks, so I'm not going to worry about it either way. Later on if I think about making the doors "destroyable" somehow, maybe it will be an issue.

But, for now we have finally got ourselves a swinging door that at least looks believable. I throw in some sound effects, and it will be nice.



Last edited by Kurinn on Feb 19th '10, 21:53, edited 1 time in total.
Image
User avatar
effigy
Mjolnir Mark IV
Posts: 673
Joined: Jan 5th '09, 13:55
Contact:

The door looks great, but I'm curious about how the handle gets to the other side after it's opened?
Thank the sun that went nova so that Earth could have iron and silicon.
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

effigy wrote:The door looks great, but I'm curious about how the handle gets to the other side after it's opened?
Yeah, that's just a mistake I made in mapping the texture for the object. Don't mind it.
I wasn't very concerned about how it looked when I just wanted to make a 3d door object to test with.
But, when I go ahead to make a demo for this, I'll do a nicer job.
Image
User avatar
Shadowbreaker
Vidmaster
Posts: 3436
Joined: Jan 22nd '06, 18:56
Contact:

My only problem with the door is that the texture sorta looks like a doorway to a cosmic wonderland or something :P
Last edited by Shadowbreaker on Feb 19th '10, 22:54, edited 1 time in total.
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

Shadowbreaker wrote:My only problem with the door is that the texture sorta looks like a doorway to a cosmic wonderland or something :P
So what you're saying is that you're so concerned by this that you personally want to go ahead and texture this door yourself?

Wow, thanks! I knew I could count on you. [MUp]


Edit:

I felt a little ashamed, so I tried to fix it, at the same time making the door itself a little thinner, and changing some other stuff so it will look properly hinged.



If anyone wants my amazingly crafted door object to play with, I'll put that up here with it's mml script.
Last edited by Kurinn on Feb 19th '10, 23:22, edited 1 time in total.
Image
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

Here is a package of all of the stuff you will need to try out the hinged doors:

[attachment=3603:Hinged_Door.zip]

Enjoy!


If anyone wants to come on board for this, even to just keep an eye on what I am doing, please PM me an email address and I'll add you to the shared folder on my dropbox.
Attachments
Hinged_Door.zip
(14.15 KiB) Downloaded 140 times
Last edited by Kurinn on Feb 20th '10, 00:15, edited 1 time in total.
Image
User avatar
goran
Vidmaster
Posts: 1468
Joined: Feb 2nd '06, 19:51
Contact:

The door is awesome. Moves really smoothly. Seems to let bullets fly through every now and then though.
Last edited by goran on Feb 20th '10, 02:07, edited 1 time in total.
User avatar
effigy
Mjolnir Mark IV
Posts: 673
Joined: Jan 5th '09, 13:55
Contact:

Kurinn wrote:Yeah, that's just a mistake I made in mapping the texture for the object. Don't mind it.
I wasn't very concerned about how it looked when I just wanted to make a 3d door object to test with.
But, when I go ahead to make a demo for this, I'll do a nicer job.
Just kidding, ofcourse.

Anyhow, the demo works well :)
Thank the sun that went nova so that Earth could have iron and silicon.
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

Goran wrote:The door is awesome. Moves really smoothly. Seems to let bullets fly through every now and then though.
Thank you.
I myself find it amazing how well you can make stuff move using Lua. I was half expecting to see something go wrong here, but it didn't.
I was thinking about even going so far as to simulate inertia or something like that, but it looks good enough as it is. Now I just want to hear some sound effects with it.
Unfortunately, since I migrated over to 10.6 when I got my new machine, I am not sure how to deal with sounds.

The bullets will fly through, mostly because the door's collision radius is only about .06 WU away from it's center.
1/8 is .125, so if you imagine a 1/8 WU thick pillar in the middle of the doorway, that's about what your bullets will be seeing.
I know it's not perfect, but aside from putting in invisible objects and making them move all at the same time, I'm not sure of a solution, let alone a simpler one.
I think it's best to assume that the bullets would go right through the door anyway, since this is a contemporary setting I am working to create.
We don't have any projectile impact decals, and all projectiles make one kind of impact display (well, two if you count going into liquids), so I figure that it's best to just leave some things to the imagination, and try to amuse the player with more obvious details.

But anyway, there is all kinds of time for everyone to play around with the door and try to improve it.
effigy wrote:Just kidding, ofcourse.

Anyhow, the demo works well :)
Thank you. I'm glad that it at least works, but to hear that it works well is something which makes me smile.
Image
User avatar
Vladtepes
Cyborg
Posts: 96
Joined: Jan 4th '09, 10:57
Location: Nantes, France
Contact:

Not sure how find_target is linked to the scenery width, but using two sceneries (one for the closed door and one for the open door) that would be the same except for the width parameter (open door close to zero, closed door with the actual width) would pretty much do the trick without blocking the player. Switch the closed door to open door scenery once the door is opening and switch back once it is closed.
irons wrote:QUOTE(irons @ Dec 18 2009, 12:47 AM) LEAVE ME ALONE STOP HURTING MY FEELINGS
Image
User avatar
goran
Vidmaster
Posts: 1468
Joined: Feb 2nd '06, 19:51
Contact:

If you change the bullet impact effect to a black dot, animate it with 3-5 frames, and set the ticks per frame to 30-60 ticks, you get the effect of temporary bullet holes.
Last edited by goran on Feb 20th '10, 11:29, edited 1 time in total.
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

VladTepes wrote:Not sure how find_target is linked to the scenery width, but using two sceneries (one for the closed door and one for the open door) that would be the same except for the width parameter (open door close to zero, closed door with the actual width) would pretty much do the trick without blocking the player. Switch the closed door to open door scenery once the door is opening and switch back once it is closed.
find_target doesn't "see" the 3d object, it only "sees" the cylindrical shape that the engine uses for collision detection.
Scenery Element: <scenery>
This kind of element specifies various features of scenery objects, including size and solidity. Each individual type of scenery object is specified with a <object> child element, which has these attributes:

* index: which one of the scenery-object types (mandatory)
* flags: various features; get this value by adding the numerical values corresponding to the desired features:
o 1 (hex 0001) Solid (can't pass through it)
o 2 (hex 0002) Unused
o 4 (hex 0004) Destroyable
* radius: horizontal dimension in internal units, for doing collision detection.
* height: vertical dimension like above; if negative, then object's extent downward from reference point (good for ceiling objects).
* destruction: effect to make when destroyed (-1 is none).
As for your idea, yes, it could work. It's a little more like the older idea where I had 3 pieces of scenery, except I'd be switching the type of the one perhaps? In that case, I'd have to destroy and recreate the door as a different type every time it reaches it's next standing state, because scenery.type is read-only. Or I could just use the old idea with 3 scenery objects, one of the invisible two being wider than the other in terms of collision.

For now I think that what I've got is elegant enough that it makes less sense to go crazy trying to figure out a more complicated way to make it look "good".
Someone could tear out their hair because of this, but as for MPDX, it's not the point. I knew from the start that I couldn't make this "perfect", but in any scenario where little hacks or clever workarounds are implemented, it's always a matter of balance. At some point you just aren't going to receive any real benefit from making the effects so much more polished, because then the story and the actual gameplay seem to be left aside to rot. With proper placement, the player isn't going to think, "Aww, I can shoot through these things, and they don't seem to be so realistic! This sucks!"... instead, the player will say "Oh, a swinging door! I wonder what's behind the next one?"

I'm not saying that I'm going to give up on this, but for now I think I'll leave it up to everyone else to try to improve upon the mechanics of the door itself if they want.
My next step is to integrate some detection of range to target, and maybe work out a way to make these doors lockable, blow-up-able, etc.
Goran wrote: If you change the bullet impact effect to a black dot, animate it with 3-5 frames, and set the ticks per frame to 30-60 ticks, you get the effect of temporary bullet holes.
Hmmm. I have to say that I like the idea. Is there a way to putting the black "bullethole" as a key frame and then looping that or something? I don't know much about messing with sequences.
Image
User avatar
goran
Vidmaster
Posts: 1468
Joined: Feb 2nd '06, 19:51
Contact:

If you want permanent holes, you uncheck "ends when animation loops" in the physics file. Although, I'd advise against it, since you might hit a limit of effects during gameplay.
User avatar
CryoS
Vidmaster
Posts: 1720
Joined: Jul 1st '07, 09:56
Location: The Dungeon
Contact:

still want those 3D models i made for you?
What are you, if not seven different shades of stupid?
Kurinn
Mjolnir Mark IV
Posts: 627
Joined: Jan 26th '09, 22:21
Contact:

CryoS wrote:still want those 3D models i made for you?
Of course! If you would like, please send me your email, and I'll bring you back onto the dropbox account.
Goran wrote:If you want permanent holes, you uncheck "ends when animation loops" in the physics file. Although, I'd advise against it, since you might hit a limit of effects during gameplay.
Ahh, yes I get it, but I can see how that would be a problem, too. Better to just leave things as simple as possible.
Last edited by Kurinn on Feb 21st '10, 01:51, edited 1 time in total.
Image
Post Reply