about script

Content and general development discussion, including quest scripts and server code. TMW Classic is a project comprising the Legacy tmwAthena server & the designated improved engine server based on evolHercules.


Forum rules

This forum houses many years of development, tracing back to some of the earliest posts that exist on the board.

Its current use is for the continued development of the server and game it has always served: TMW Classic.

Post Reply
jimao888
Peon
Peon
Posts: 15
Joined: 09 Sep 2007, 15:53

about script

Post by jimao888 »

I herad that, the sctipc of npc talk of twmsrv is joined to the map logic; I don't know is it true;
if it is true, t want to aks, why not create a script system base NPC system;
User avatar
Jaxad0127
Manasource
Manasource
Posts: 4209
Joined: 01 Nov 2007, 17:35
Location: Internet

Re: about script

Post by Jaxad0127 »

jimao888 wrote:I herad that, the sctipc of npc talk of twmsrv is joined to the map logic; I don't know is it true;
if it is true, t want to aks, why not create a script system base NPC system;
NPCs are script based. What you were reading says that the scripts can be put in the map files itself, or in separate files.
Image
jimao888
Peon
Peon
Posts: 15
Joined: 09 Sep 2007, 15:53

Re: about script

Post by jimao888 »

--------------
-- Map code --
--------------
atinit(function()
create_npc(108, 50 * 32 + 16, 19 * 32 + 16, npc1_talk, nil)
create_npc(110, 51 * 32 + 16, 25 * 32 + 16, npc4_talk, nil)
create_npc(100, 40 * 32 + 16, 18 * 32 + 16, npc5_talk, npc_walker)
create_npc(110, 58 * 32 + 16, 15 * 32 + 16, npc6_talk, nil)
create_npc(100, 50 * 32 + 16, 20 * 32 + 16, npc_tweakster_talk, npc_walker)
end)
--This is the NPC #1 function
--
function npc1_talk(npc, ch)
do_message(npc, ch, "Hello! I am testing .")
do_message(npc, ch, "This message is just here for testing connections.")
do_message(npc, ch, "What do you want?")
local v = do_choice(npc, ch, "Guns! Lots of guns!",
"A Christmas party!",
"To buy.",
"To sell.",
"To make a donation.")
......
( :oops: sorry to reference some one work)


I read some of the Lua script; It seems All the sctipt abut npc Is in the same script of the map area,
so What should I do if move one Npc to another map; or creat tow same Npc in to tow diffent map;
User avatar
Crush
TMW Adviser
TMW Adviser
Posts: 8046
Joined: 25 Aug 2005, 16:08
Location: Germany

Re: about script

Post by Crush »

Jimao, your posts are really hard to read. I had to read them a couple of times before I understood what you want and I am still not sure if I understood you correctly. It would make it easier for all of us when you would read your posts and correct typing errors before submitting them.

Regarding your question: LUA allows to declare functions in different lua files. When you would have an NPC which is supposed to be included in a lot of different maps, let's take a potion salesman for example, you would put its talk and walk functions into a separate lua file. Let's call it potionseller.lua. Then you put the line "dofile (potionseller.lua)" at the top of the script of the map you want to put it on. Then you can assign the script functions defined in potionseller.lua to the NPCs created in the atinit function.

Instead of dofile it would also be possible to use the module system of LUA, but I am not that familiar with this so I don't know if it would be a better or a worse way to export commonly used NPC scripts into external files.
  • former Manasource Programmer
  • former TMW Pixel artist
  • NOT a game master

Please do not send me any inquiries regarding player accounts on TMW.


You might have heard a certain rumor about me. This rumor is completely false. You might also have heard the other rumor about me. This rumor is 100% accurate.
User avatar
leeor_net
Novice
Novice
Posts: 180
Joined: 03 Feb 2008, 09:17
Location: Ohio, USA
Contact:

Re: about script

Post by leeor_net »

The Lua scripts also make it possible to include very complex scripts in maps without needing to have the code embedded within the map itself.

Perhaps:

Code: Select all

--------------
-- Map code --
--------------
is what is confusing you. I'm not sure exactly what that means but it could just mean the code that places NPC's into the maps.

Regardless, NPC code is all in Lua. The Lua code could be embedded directly in a map file like this:

Code: Select all

<object name="Elijah the Nomad" type="NPC" x="592" y="2192" width="0" height="0">
	<properties>
		<property name="SCRIPT">
			function npc_handler(npc, ch)
				do_message(npc, ch, "If I only had a tent...")
			end
		</property>
		<property name="NPC_ID">
			128
		</property>
	</properties>
</object>
Or it could refer to an external file containing the Lua code like this:

Code: Select all

<object name="Kalder NPC's" type="SCRIPT" x="0" y="0" width="0" height="0">
	<properties>
		<property name="FILENAME">/npc/kalder.lua</property>
	</properties>
</object>
It's a matter of practicality and perference. In the first case with the script embedded directly in the map, it makes much more sense to have it there. Creating a seperate file to create one NPC that says exactly one line is silly. On the other hand, the second example defines a Lua script file that contains code for a number of NPC's (about 10) some with very complex logic so it makes much more sense to leave it in an external file for easy editing.
- Leeor

"Oh, no thanks. I ate a boulder on the way in." - Shrek
jimao888
Peon
Peon
Posts: 15
Joined: 09 Sep 2007, 15:53

Re: about script

Post by jimao888 »

First, I'm sorry about my english, And Thanks a lot; I seems to understand.
Post Reply