ArcEmu: [luabridge] Basics - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[luabridge] Basics

#1 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 23 April 2011 - 06:51 PM

The Basics of LuaBridge

1. Intro
Greetings everyone. As you are probably aware by now, the new lua engine LuaBridge has recently come onto Arcemu. It was decided by you that it is best to try and start to use LuaBridge so we can remain fully supported with Arcemu updates by Arcemu themselves. In this guide I will aim to teach you the basic fundamentals of writing a script for use in LuaBridge.

By default, Arcemu will compile using LuaBridge. But to make sure you are, In Visual C++ just go to Build -> Configuration Manager, and ensure 'luabridge' is ticked and 'LuaEngine' isn't.

2.0 "Multiple VMs"
LuaBridge runs on what is called "multiple virtual machines". Basically, each map has it's own mini "worker" rather than one huge "worker" like the old Lua Engine had. This is complete hokum to most users so I've prepared this little cartoon & dialogue to explain it!

(Note: This is a dramatic recreation of real events)

Old engine worker:
Posted Image

New engine workers:
Posted Image


Quote

Old engine: hmm... these scripts seem good. loaded some scripts. yea.
...
Map #1: HEY Lua Engine, some guy just attacked a boss, need the script now!
Old engine: coming right up...
Map #0: Lua Engine omg, someone just used a teleporter, need it's script please.
Old engine: right after im done with map 1 dude, he asked first
Map #0: :P
Map #1: You got my script yet Lua Engine!?
Old engine: STOP PRESSURING ME MAN
Map #42: YO IM AN INSTANCE NEED 12 BOSS SCRIPTS NOW!!!
Old engine: aww NOO
Map #1: :)
Map #0: :(


Quote

Papa LuaBridge: Hmm, these scripts seem good. Loading some scripts. Yea.
Papa LuaBridge: NOW GO MY MINIONS
LuaBridge Worker #0: Whee!
LuaBridge Worker #1: Whee!
LuaBridge Worker #571: Whee!
...
Map #0: HEY Lua Engine, some guy just attacked a boss, need the script now!
LuaBridge Worker #0: Here ya go.
Map #0: Woah that was fast! Thanks bro. /brofist
LuaBridge Worker #0: /brofist. I'm dedicated to YOU, brudda.
Map #1: LUA ENGINE HALP, someone used a teleporter, gimme the script man
LuaBridge Worker #1: Here ya go.
Map #1: :D
Map #42: YO IM AN INSTANCE NEED 12 BOSS SCRIPTS NOW!!!
LuaBridge Worker #42: Right here broseph!!
Map #42: YUM


2.1 The MAP header
So, as exquisitely demonstrated by the cartoon above, each map serves it's own set of scripts now. However, you have to say which map your script should load into. Thankfully this is very easy, using what's called the MAP header.

This header should be put at the top of your script:

--?!MAP=map_ID_here

*rest of script is below*


For example, for your script to load on map #0 (Eastern Kingdoms):

--?!MAP=0


But you may be wondering, "what map SHOULD my script load on?" Well, that depends on the script. For bosses, creatures, gossips and gameobjects - basically anything that is spawned - you should set the map to that object's map ID. This information is readily available through .gps.

In most cases, your scripts will only operate on one map, whether it be an instance, or whatever map your creature is spawned on. Sometimes, though, we want our script to work on multiple maps. For example, what if we script a creature, and spawn him in both Eastern Kingdoms and Kalimdor? Well, we can make our lua script load in both of those maps easily.

--?!MAP=0,1


You can add as many maps to the list as you like, separating them with a comma.

Note: For most users, this is all you'll need to worry about in terms of the MAP header, feel free to skip to section 3 if you like.

2.2 Loading on every map
Now, in a lot of cases, you won't need to do this, and you generally shouldn't. However, there are times when you need to load on every map. For example, say you register an OnChat server hook. Well, players can be on EVERY map when they chat, so we need to make our script load on all maps!

This is quite simple as well. If you want your script to load on every map, then you have to change your MAP header to this:

if (MapMgr == nil) then return; end


This does look quite different to our last header, but you don't need to understand why it works. You just need to know that replacing the header with this will make your script load on all maps.

[Spoiler: Why it works]
Without the --?!MAP header your script is by default loaded by all VMs. (Aka all maps). But in addition to the maps, it is loaded by the "papa" VM mentioned in the cartoon. The papa VM has no map and so we don't want our scripts to load on a mapless VM. The statement above will cancel your script when and only when the papa VM tries to load it.
[/spoiler]

2.3 Loading some stuff on all maps and some stuff on one map

The final part of our MAP segment, talking about the case where you have for example a Server hook and a creature script in one Lua file. You COULD put them in different script files, but here's how you do it from within one:

if (MapMgr == nil) then return; end --we use the 'all-map' header

--This function should work on all maps.
function OnChat(...)
   *code here*
end

if (MapMgr:GetMapID() == 0)
   --The code in here will only run for Map 0
   function BossOnSpawn(...)
      *code here*
   end
end

RegisterServerHook(16, OnChat)
--The RegisterCreatureEvent will only work for Map 0
if (MapMgr:GetMapID() == 0) then RegisterCreatureEvent(1337, 18, BossOnSpawn) end


3. LCF
LCF ("lua's convenient functions", but that's irrelevant) is a set of Lua scripts that were around before LuaBridge, and provided convenient functions to basically shorten the amount of lines you had to write. Since LuaBridge, in addition to providing more convenient functions, it also is used for backwards compatibility for old LHA scripts.

Every user of LuaBridge has no reason not to use LCF. You can find it in your \trunk\src\scripts\lua\0Misc folder, called "0LCF_Includes" (or here). Copy this folder into your "scripts" folder and you're using LCF.

LCF is still under construction, so don't forget to SVN Update the 0LCF_Includes folder every once in a while to get the latest updates.

4. Backwards compatibility
The way LuaBridge does things is a lot different to how LHA did things. As such, a lot of the commands you're used to may have had a name changed, or removed completely. Some may still work exactly the same. LCF's role is to make sure that, if you use a command's old name, it will still work as expected. However, LCF is not finished. Most of your old scripts will probably not work for now on LuaBridge.

A more detailed look at what is the same, what has changed, and what doesn't work anymore will be looked at in much greater detail in a later tutorial.

5. Outro
This guide should have given you a basic understanding of how LuaBridge works and taught you how to set up a script for use in LuaBridge. As programming is a very practical art, as usual the best way to learn is to actually do it. It might not be a bad idea to set up a simple 'print' script using LuaBridge to prove what you know.

More tutorials will be coming shortly including a major one on backwards compatibility. Good luck and thanks for reading :)

PS. I was not high when I made the cartoon
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
1

#2 User is offline   WAmadeus 

  • Cunning Code Composer
  • PipPipPip
  • Group: Developers
  • Posts: 287
  • Joined: 23-July 09
  • Gender:Male
  • Location:Brazil

Posted 23 April 2011 - 07:10 PM

Nice tutorial, hypersniper! Good job!
0

#3 User is offline   kazuma 

  • Member
  • Pip
  • Group: Members
  • Posts: 19
  • Joined: 19-April 11
  • Gender:Male
  • Server OS:Linux

Posted 24 April 2011 - 12:29 AM

Quote

3. LCF
LCF ("lua's convenient functions", but that's irrelevant) is a set of Lua scripts that were around before LuaBridge, and provided convenient functions to basically shorten the amount of lines you had to write. Since LuaBridge, in addition to providing more convenient functions, it also is used for backwards compatibility for old LHA scripts.

Every user of LuaBridge has no reason not to use LCF. You can find it in your \trunk\src\scripts\lua\0Misc folder, called "0LCF_Includes" (or here). Copy this folder into your "scripts" folder and you're using LCF.

LCF is still under construction, so don't forget to SVN Update the 0LCF_Includes folder every once in a while to get the latest updates.




When I copy the folder "0LCF_Includes" my folder "/server/bin/scripts/" the game crashes completely! Once connected to the game, I can not take any action to move my character. What could it come?
Sorry for my english
0

#4 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 24 April 2011 - 01:36 AM

View Postkazuma, on 24 April 2011 - 12:29 AM, said:

When I copy the folder "0LCF_Includes" my folder "/server/bin/scripts/" the game crashes completely! Once connected to the game, I can not take any action to move my character. What could it come?
Sorry for my english


I'm not sure, sorry. Try posting the crash information on the Trac so someone can fix it (there are instructions for how to do this on Trac and in the wiki)

WAmadeus said:

Nice tutorial, hypersniper! Good job!


Thanks :P
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
0

#5 User is offline   kazuma 

  • Member
  • Pip
  • Group: Members
  • Posts: 19
  • Joined: 19-April 11
  • Gender:Male
  • Server OS:Linux

Posted 24 April 2011 - 01:51 AM

View Posthypersniper, on 24 April 2011 - 01:36 AM, said:

I'm not sure, sorry. Try posting the crash information on the Trac so someone can fix it (there are instructions for how to do this on Trac and in the wiki)



I misspoke (sorry), the server does not crash (so I have no "logcrash" or even a bug report). Just once connected to the game I can not do anything, my character gets stuck, I can not move.
Posted Image
0

#6 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 24 April 2011 - 02:08 AM

I'm on Windows and LCF works fine for me :\

It is pretty unlikely that LCF would cause such a problem... I can't help you unfortuntely. :P
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
0

#7 User is offline   kazuma 

  • Member
  • Pip
  • Group: Members
  • Posts: 19
  • Joined: 19-April 11
  • Gender:Male
  • Server OS:Linux

Posted 24 April 2011 - 02:14 AM

It is pretty unlikely that LCF would cause such a problem...

It was on and some that just LCF, because if I delete I have no problem. Maybe it come from my compilation is not correct, but last week I have had no concrete answer to the subject. :P

I'll wait patiently for someone to help me, thank you anyway.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users