Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 SmaugFUSS 1.9.2
Today, 3:17 am
By Quixadhal
AFKMud 2.2.0
Nov 21, 2014, 7:15 pm
By Samson
CIDR Range Banning
Nov 21, 2014, 2:01 pm
By Samson
Compiling Lop 1.44b, errors.
Nov 17, 2014, 1:12 pm
By Remcon
SmaugFUSS 1.9.1
Nov 15, 2014, 2:44 pm
By GatewaySysop
SmaugFUSS 1.9.2
Author: Various
Submitted by: Samson
AFKMud 2.2.0
Author: AFKMud Team
Submitted by: Samson
SmaugFUSS 1.9.1
Author: Various
Submitted by: Samson
AFKMud 2.1.6
Author: AFKMud Team
Submitted by: Samson
6D update
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Bing, Yahoo!

Members: 0
Guests: 4
Stats
Files
Topics
Posts
Members
Newest Member
455
3,647
19,036
568
Taenar
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » Lua in Smaug...again.
Forum Rules | Mark all | Recent Posts

Lua in Smaug...again.
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Sep 2, 2012, 9:25 am
Go to the top of the page
Go to the bottom of the page

Kasji
Apprentice
GroupMembers
Posts51
JoinedDec 23, 2007

I know this has been discussed. I've looked through various places. Nick Gammon has an implementation started. Apparently kiasyn did, but the link to his .tgz is no longer valid on his blog. For those of you who remember me, I did discuss this previously on IMC and whatever.

I want to implement Lua in the following ways:
  • room/mob/obj progs (should be easy enough)

  • various hooks (should be easy enough)

  • extending the command interpreter (where I am wondering)


I've recently found a nice MOO with some very cool gameplay, and this has inspired me to want to add support for commands being attached to rooms, mobs, and objects. I was wondering if anyone had any recommendations on how to go about doing this effectively?

SWFotE does have the "custom_prog" mudprog trigger, which lets you type in a psuedo-command that triggers the mudprog, but is this the best way to do it with a Lua implementation? Also, as a note, I was thinking of having two different command types for objects. One type can only be triggered if the object is in your inventory, the other can be triggered if the object is in the room.
       
Post is unread #2 Sep 3, 2012, 8:49 am
Go to the top of the page
Go to the bottom of the page

Kasji
Apprentice
GroupMembers
Posts51
JoinedDec 23, 2007

I think using one global Lua state might be fine, but my concern is this:

If I have a hook, let's just say "Enter_Room", the hook will call the Lua function "Enter_Room". What is the best way to get it to find the correct "Enter_Room" if I have several different ones for different rooms?

As an aside, I was also thinking about an OLC Lua state editor. Mainly for me. What do you think? An OLC editor for creating new Lua states and being able to assign descriptors to different Lua states? I thought this up for mainly being able to transfer myself to a different Lua state on the fly so I can code without affecting others.
       
* #3 Sep 3, 2012, 9:23 am
Go to the top of the page
Go to the bottom of the page

Kasji
Apprentice
GroupMembers
Posts51
JoinedDec 23, 2007

And I just thought again (amazing, huh? :P). Another good hook would be in mobile_update or whatever to phase out hardcoded spec_funs and replace them with scripted spec_funs.
       
Post is unread #4 Sep 3, 2012, 10:45 am
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts146
JoinedJun 9, 2009

Just off the top of my head, and from what little I remember from Nick's Lua example and the various discussions around it, you'd probably need to add a lua state object to all objects/rooms/characters in order for that to work. Then just check when a player enters a room or whatever if a) the target has a valid lua state and b) if it contains a handler for whatever action is being performed.
if room has a valid lua_state
   if the rooms lua_state has the on_enter handler
      call the handler and pass the player to it as an argument


Of course, if you had a global state object you could easily, or not, associate the specific handlers with specific entities using some sort of key/value system that is split apart by type. For example each handler is separated by room/object/char sections, then further by a unique identifier, vnums or player name as appropriate. Then you could do something along the lines of the following psuedocode for a player A entering room A
 if room A has an on_enter event handler in global_lua_state
   call that handler and pass it player A


Either way has its good and bad points. I'm also not really all that familiar with Lua in any way, or all that great of a programmer really, so take anything I say with a salt shaker.
My best suggestion would probably be to float this question over to Nick Gammon's forums as there's probably someone over there, Nick included, who may be able to give you much better advice.
       
Post is unread #5 Sep 16, 2012, 1:06 pm   Last edited Sep 16, 2012, 1:07 pm by Kasji
Go to the top of the page
Go to the bottom of the page

Kasji
Apprentice
GroupMembers
Posts51
JoinedDec 23, 2007

I've finished my basic Lua implementation. I am planning on releasing it now as is because I will be writing stuff that is relevant only to my MUD (eg. my custom combat system), and don't want to leave a bunch of stuff in that other people would need to take out. I just need to find a place I can upload the code to.

Here's an example lua script:
-- do_lua_test, function to test the lua implementation

function send(char, ...)
    send_to_char(char.id, table.concat {...} .. "\n\r")
   return
end -- send

function do_lua_test(ch, argument)
   if argument then
      send(ch, "&RYou typed: " .. argument)
   end
   send(ch, "&GYour name is " .. ch.name .. ", and you are a " .. ch.gender .. " " .. ch.race .. ".")
   och = get_char_world(ch, "tech")
   if och then
      send(ch, "&YWe found: " .. och.name)
   end
   ch:say("Testing")
   return
end -- do_lua_test


And here's the output:
Force:0/0  Align:0
[Hp:500/500] [Mv:1000/1000] (Align:0) 
lua_test Some args
You typed: Some args
Your name is Kasji, and you are a male Noghri.
We found: a skittish verpine tech
You say, "Testing"

Force:0/0  Align:0
[Hp:500/500] [Mv:1000/1000] (Align:0) [Hp:500/500] [Mv:1000/1000] (Align:0) 
       
Pages:<< prev 1 next >>