Page 2 of 3

Re: LUA Script WIKI

Posted: Fri Mar 27, 2009 5:36 pm
by John Adams
Also, in the GetAgi example... the reason I did not put the word "spawn" in the Syntax, was because "Spawn" is not required. It can be GetAgi(EatMyAss), as long as it's the first var... correct? That whole Player vs Spawn vs Entity or the 20 other ways we've been doing it ;)

Re: LUA Script WIKI

Posted: Fri Mar 27, 2009 5:48 pm
by Scatman
Hehe yep. Spawn is in there because I think that's the actual type. It's a reference to a spawn. Both NPC and Player are of type Spawn. But param works for me, it's less confusing.

Re: LUA Script WIKI

Posted: Fri Mar 27, 2009 5:53 pm
by John Adams
Well ok... this is one thing that has always confused the shit out of me about our "params". Sometimes, players are "Spawn". Sometimes they are "Player". What's right?


Scat, can you look over this paragraph, and tell me if I am full of shit? This is how I understand it, but I am not convinced I am right. ;)
LUA Parameter Basics
EQ2Emulator LUA Functions normally have parameters - that is, some value required to be passed from the World to the Script or vice-versa. An example of this is the function hailed(NPC, Spawn). Note that there are 2 parameters for function hailed(). What the parameter names are is up to you, as long as there are the proper number of parameters in the () parens.


Example: Here, the NPC says Hello to the player.

Code: Select all

 function hailed(MyNPC, MyPlayer)
   Say(MyNPC, "Hello Player!")
 end
Example: Here, the Player says Hello to the NPC.

Code: Select all

 function hailed(MyNPC, MyPlayer)
   Say(MyPlayer, "Hello NPC!")
 end
Current standards we have adopted are to use NPC as the value for the NPCs parameters, and depending on the type of script, Spawn or Player for the Players parameters.

Nearly all other parameter values are dynamic - that is, they can be any valid variable name you choose. But when coding scripts for the Official EQ2Emulator Project, be sure to follow our guidelines or your scripts will get rejected.
I just added this to the LUA Functions page.

Re: LUA Script WIKI

Posted: Fri Mar 27, 2009 6:00 pm
by Scatman
That's fine as long as we explain what MyPlayer can be (which we do).

If the parameter accepts a spawn type, then a player type, an npc type, object, or groundspawn type can be used.
If a player type is specified as the parameter, then only a player type can be specified, not an npc, or object, etc..

The hierarchy is:

Code: Select all

                    Spawn
              /       |       \
      Entity   Object    GroundSpawn
     /      \
Player    NPC

Re: LUA Script WIKI

Posted: Fri Mar 27, 2009 6:03 pm
by John Adams
Right, ok. The point I am trying to clarify though is, the "variable name" doesn't matter.

Does it HAVE to be "NPC, Spawn"? or is it just a matter of, if ABCDEF is the first var, then it's got an NPC reference in it... does that make sense?

function hailed(ABCDEF)


the same as


function hailed(NPC)

Re: LUA Script WIKI

Posted: Fri Mar 27, 2009 6:09 pm
by LethalEncounter
John Adams wrote:Right, ok. The point I am trying to clarify though is, the "variable name" doesn't matter.

Does it HAVE to be "NPC, Spawn"? or is it just a matter of, if ABCDEF is the first var, then it's got an NPC reference in it... does that make sense?

function hailed(ABCDEF)


the same as


function hailed(NPC)
Yup, both of those functions are the same. The names can be whatever you want, but I suggest you leave them as NPC because it is less confusing if you name the variable the same as what it points to. All of the NPC, Player, and Spawn lua references really point to a Spawn object in the code. Depending on the function, you must pass the right type of Spawn reference to it otherwise the function is ignored. IE You can't call GetQuestStep with a Spawn reference that really points to an NPC.

Re: LUA Script WIKI

Posted: Fri Mar 27, 2009 6:11 pm
by Scatman
The variable name does not matter GetAgi(EatMyAss) works just like GetAgi(Spawn). Sorry, I've been up since 3:30 am, I think I need to rest =|

Re: LUA Script WIKI

Posted: Fri Mar 27, 2009 6:18 pm
by John Adams
Hehe, ok - thanks both of you for the clarification. I felt I understood that well enough, but wanted to make sure before starting any documentation.

As for the scripts for our "official" content, we will use exactly what LE recommends for optimum clarity. Just wanted to make sure others know how flexible it is.

Thanks again!

Re: LUA Script WIKI

Posted: Wed Apr 01, 2009 3:44 pm
by John Adams
Scat, last thing about this - cuz you know I love beating a dead horse.

After staring at the LUA Functions list for a week, I think you might have a point on showing more than just the name of the function on the index list. While it may get cluttered looking (I hate word-wrapping Tables of Contents :P) it might be an even quicker lookup of the function if we show the possible params right up front.

Take a look at some of the functions I modified in the LUA Functions index page. Tell me if you think that will get too cluttered with crap, unreadable.

Re: LUA Script WIKI

Posted: Wed Apr 01, 2009 3:49 pm
by Scatman
That's what I was thinking too. Once the user gets an idea of what the Spawn parameter is, for example, everytime they see it, they'll know what it is. So they can just keep that one page open instead of actually having to click each function individually to see the parameters. Once they click the function, it'll show extra information about the function.

Re: LUA Script WIKI

Posted: Wed Apr 01, 2009 3:50 pm
by John Adams
Ok, I updated some of them to get an idea of the clutter factor. :)

Also, see how LE provided us with (param_name (type))? I want to do that on our parameters list too, so scripters know what data types belong to what params. Make sense?

Re: LUA Script WIKI

Posted: Wed Apr 01, 2009 3:56 pm
by John Adams
Well alrighty then. I just remembered WHY I didn't put params on that front index lol...

Because Wiki formatting is stupid.

You put the link to a new page as [[Page | Page description]] so Page becomes the TITLE of the Wiki page up top, all in bold and pretty looking.

If we did SetMountColor(Spawn, horse_color_red (int), horse_color_green (int), horse_color_blue (int), horse_color_saddle_red (int), horse_color_saddle_green (int), horse_color_saddle_blue (int)) to get the TITLE of the page to have the params too, our URL would be insane.

Short sample: index.php?title=LUA:GetAgi%28param%29&action=edit

Gah! Why can't one thing be easy? So Scat... you tell me lol... Starting to build super-aggro for the fookin Wiki.

Re: LUA Script WIKI

Posted: Wed Apr 01, 2009 4:03 pm
by Scatman
LOL, couldn't we just put the params in the Page Description part and leave the page part as SetMount or something? That would make the URL short but show the params ? I'm a wiki noobie!

Re: LUA Script WIKI

Posted: Wed Apr 01, 2009 4:06 pm
by Scatman
Ya how you have it now looks good. URL = GetAgi and the description is GetAgi(param)

Re: LUA Script WIKI

Posted: Wed Apr 01, 2009 4:07 pm
by John Adams
When you get a moment, come check out the LUA Functions. I am doing that right now. I guess it'll be ok... but the individual function page titles look weird with no params.