[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  Lua
. . -> [Subject]  Version 2 of the Lua interface released

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Version 2 of the Lua interface released
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1  2 

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Mon 10 Mar 2008 04:59 AM (UTC)  quote  ]

Amended on Mon 10 Mar 2008 05:00 AM (UTC) by Nick Gammon

Message
What I meant was, your main tasklist.lua file would just look like this:



all_tasks = {}

my_loader "academy_tasks"
my_loader "grove_tasks"
my_loader "academy_tasks"


Then you make a file "academy_tasks.lua" and put inside that all the rest of the existing tasklist.lua file. That is, like this:



all_tasks.academy1 = {
  -- task definition here
  }  -- end academy1 task
  
all_tasks.academy2 = {
  -- task definition here
  }  -- end academy2 task

all_tasks.academy3 = {
  -- task definition here
  }  -- end academy3 task
  
all_tasks.academy4 = {
  -- task definition here
  }  -- end academy4 task


-- and so on



Then you could make another file "grove_tasks.lua" and put all the tasks for that area in it.

For example, it might look like this:




all_tasks.grove1 = {
  -- task definition here
  }  -- end grove1 task
  
all_tasks.grove2 = {
  -- task definition here
  }  -- end academy2 task

all_tasks.grove3 = {
  -- task definition here
  }  -- end grove3 task
  
all_tasks.grove4 = {
  -- task definition here
  }  -- end grove4 task

-- and so on



The tasks still go into the all_tasks table so you don't make a different table per area. However you must name each task uniquely (eg. grove1, grove2 etc.)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Mon 10 Mar 2008 03:02 AM (UTC)  quote  ]

Amended on Mon 10 Mar 2008 03:04 AM (UTC) by Orik

Message
How exactly does this work?

Quote:
You can split it into subfiles. For example, in alltasks.lua, you could simply require the additional files like this:


all_tasks = {}
my_loader "darkhaven_tasks"
my_loader "grove_tasks"
my_loader "academy_tasks"



Do I create a new grove.lua file and then just put grove_tasks = {} in it? Or do I need to make a grove_tasks file? OR is this all in one big tasklist file?

Quote:

Since it's all Lua code, you can easily set up includes like you do in C, using 'require'. So you could have a master list that is just a list of includes, and you could create one file per area or something like that.


Where would I start with this? I'd like to have one lua file per area, but if that isn't the case then that's fine as well.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Mon 06 Aug 2007 07:37 AM (UTC)  quote  ]
Message
It turned out to be a bit more complicated than I thought because I hadn't allowed for purging from someone else's inventory. Here is what I had in mind for the subtask:


    {  -- subtask 1
     description = "Bread obtained",
     type = "give",
     item = 21021,
     count = 1,
     vnums = { 10399 },
     complete = function ()
       mud.destroy_item (10399, 10300, 21021)  -- get rid of the bread
     end -- complete function
     },  -- end subtask


Note that on completion (ie. I gave mob 10399 in room 10300 item 21021) I immediately destroy that item.

However to make that work I had to amend the function destroy_item like this:


/* remove an item from the character's top-level inventory */
static int L_destroy_item (lua_State *L)
{
  CHAR_DATA * ch = L_find_character (L); /* get character pointer */

  int iItem = 2;
  
  if (!ch)
    luaL_error (L, "Cannot find character/mob to destroy an item for.");
    
  /* if character was (vnum, boolean) then item is 3rd argument */
  if ((lua_type (L, 1) == LUA_TNUMBER || lua_type (L, 1) == LUA_TLIGHTUSERDATA)
     && (lua_type (L, 2) == LUA_TBOOLEAN || lua_type (L, 2) == LUA_TNUMBER))
    iItem++;
       
    
  OBJ_DATA * obj;
  
  int vnum = luaL_checkint (L, iItem);
  if ( vnum < 1 || vnum > MAX_VNUM )
    luaL_error (L, "Vnum %d is out of range 1 to %d", vnum, MAX_VNUM);
  
  int count = luaL_optint (L, iItem + 1, 1);

// rest is the same


This lets you specify the mob/room as well as the item number. You should probably make a different function, I think it will get confusing with all those vnums there (like, mob_destroy_item or something).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Darwin   USA  (125 posts)  [Biography] bio
Date Mon 06 Aug 2007 05:26 AM (UTC)  quote  ]
Message
I'm not sure how to work that. How do I track that item from the player to the mob and then have it purged from the mob's inventory?
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 02 Aug 2007 05:17 PM (UTC)  quote  ]
Message
You are right. Probably the thing to do is add a "complete" function to the subtask, to immediately purge the item.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Darwin   USA  (125 posts)  [Biography] bio
Date Thu 02 Aug 2007 04:02 PM (UTC)  quote  ]
Message
I've noticed something about the tasks which require you to "give" an item to a mob. The problem is that the item isn't purged from the mob. After a while, a mob's inventory may fill up and cause the player to not be able to finish the task. Also, since the items don't get purged, a player may end up killing the mob to obtain all the task items, but then would have to wait until the mob repopped in order to finish the task.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 18 Jul 2007 06:06 AM (UTC)  quote  ]
Message
For development, I have been editing the various Lua files using Crimson Editor (under Windows), using its "get from remote" and "save to remote" options (these invoke an inbuilt ftp client).

Thus you just hit "save" and it saves to the remote site.


Quote:

This tasklist file will be REALLY big once you start putting more tasks into it. Is that just how it goes or will there be better ways on down the line?


You can split it into subfiles. For example, in alltasks.lua, you could simply require the additional files like this:


all_tasks = {}
my_loader "darkhaven_tasks"
my_loader "grove_tasks"
my_loader "academy_tasks"


Then you can give each area to a builder to edit.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 18 Jul 2007 06:03 AM (UTC)  quote  ]
Message
Well, the tasks are something I wouldn't edit as a text file were I to edit them online. Well, it depends on what exactly you're doing and how hard the syntax is. Either way, in-MUD, it is not feasible to edit the whole file when you have more than, say, ~50 quests.

Since it's all Lua code, you can easily set up includes like you do in C, using 'require'. So you could have a master list that is just a list of includes, and you could create one file per area or something like that.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Wed 18 Jul 2007 03:55 AM (UTC)  quote  ]
Message
Yea, i've no problems with it. This tasklist file will be REALLY big once you start putting more tasks into it. Is that just how it goes or will there be better ways on down the line?
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 18 Jul 2007 03:50 AM (UTC)  quote  ]
Message
I plan on doing that for large chunks of it, yes. But to be honest, it's just as easy (if not easier) to load up your file in your shell (if you have shell access), so it might be better to get into that habit.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Wed 18 Jul 2007 03:40 AM (UTC)  quote  ]
Message
Is there plans to be able to create the code from inside a buffer in game? IE desc's and such? That'd be cool, but what we have now just is so much fun to play with. I know it's going to just get better.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 18 Jul 2007 03:17 AM (UTC)  quote  ]
Message
Welcome to the world of Lua. :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Gatewaysysop2   USA  (142 posts)  [Biography] bio
Date Wed 18 Jul 2007 03:16 AM (UTC)  quote  ]
Message
I must say it makes me somewhat giddy to be able to edit code and just log back in to see the effect. Fun stuff. ;-)

"The world of men is dreaming, it has gone mad in its sleep, and a snake is strangling it, but it can't wake up." -D.H. Lawrence
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Tue 17 Jul 2007 10:50 PM (UTC)  quote  ]

Amended on Tue 17 Jul 2007 10:53 PM (UTC) by Nick Gammon

Message
When testing with FUSS 1.8, I noticed a small bug.

In tasks.lua, find the function get_mob_name_and_room. If the mob is not in the world the function mud.mobinworld returns false, not a count, so you can't compare it to 1. Change the lines in bold to read as follows:



function get_mob_name_and_room (vnum)

  local minfo = mud.mob_info (vnum)
  if not minfo then
    return "no mob " .. vnum
  end -- doesn't exist

  local count = mud.mobinworld (vnum) or 0
  if count ~= 1 then
    return capitalize (minfo.short_descr)
  end
  
  local room = mud.room (vnum, true)  -- which room is it in?

  return capitalize (minfo.short_descr) .. " in " .. mud.room_name (room)
 
end -- get_mob_name_and_room


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Tue 17 Jul 2007 07:32 AM (UTC)  quote  ]

Amended on Tue 17 Jul 2007 07:34 AM (UTC) by Nick Gammon

Message
I started to wonder what would happen if you manually edited the player state file (eg. Nick.lua) and made a syntax error. The way I had the code written it would misleadingly report that the state file was not found. I would suggest changing the function 'reconnected' in startup.lua to read like this:


-- after player reconnects, load his/her state file
function reconnected (name)

  local f, err = loadfile (get_file_name ())
 
  if f then
    f ()  -- execute it
  else
    io.stderr:write (err .. "\n")
  end 
   
  for _, func in ipairs (handlers.reconnected) do
    func (name)  -- call each handler to let them know
  end -- for
 
end -- reconnected


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


9,371 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]