New Lua Function: GetGroup(Spawn)

Discussions on development of both the EQ2Emulator LUA Script Engine and Script specifications

Moderator: Team Members

Post Reply
Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

New Lua Function: GetGroup(Spawn)

Post by Jabantiz » Sat Oct 06, 2012 9:52 pm

This will return a lua table (array) of group members for the given spawn. I have tested this on players but have not tested on NPC's though it should work for them as well.

The following spawn script will make the npc say the name of each group member, if there is no group the npc says nothing.

Code: Select all

function hailed(NPC, Spawn)
   FaceTarget(NPC, Spawn)
	for k,v in ipairs(GetGroup(Spawn)) do
		Say(NPC, GetName(v))
	end
end

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: New Lua Function: GetGroup(Spawn)

Post by John Adams » Sun Oct 07, 2012 11:20 am

Nice, arrays in LUA :)

Can we write our LUA to check the group exists first (local var = GetGroup(blah)) then branch with IFs so the same script can handle group reactions as well as solo?

Code: Select all

function hailed(NPC, Spawn)
   var = GetGroup(Spawn)

   if var ~= nil
      Say(NPC, "I do not speak to loners...")
   else
      FaceTarget(NPC, Spawn)
      for k,v in ipairs(var) do
         Say(NPC, GetName(v))
      end
   end
end
Not sure if LUA requires declaring vars as arrays vs regular, but thought I'd ask rather than wasting my only hour of Emu I have this week trying over and over, then googling my life away, getting pissed off at the bad spelling on the interwebs and going to take a nap :)

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: New Lua Function: GetGroup(Spawn)

Post by Jabantiz » Sun Oct 07, 2012 4:05 pm

I am new to lua tables, after googling for a while to figure out how to even get arrays to work they make it clear that lua does not have arrays it has tables and it seems far more complicated then a simple array is, although I have been working with arrays for years now so I am biased, I bring this up so if others google they know to search lua tables and not lua arrays.

That said I used your script and fixed a few errors and it works.

Code: Select all

   var = GetGroup(Spawn)

	if var == nil then
		Say(NPC, "I do not speak to loners...")
	else
		FaceTarget(NPC, Spawn)
		for k,v in ipairs(var) do
			Say(NPC, GetName(v))
		end
	end
I am still learning stuff about lua tables but for our needs I think this basic use is a good start.

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: New Lua Function: GetGroup(Spawn)

Post by Jabantiz » Sun Oct 07, 2012 5:15 pm

I tested this with a spawn group and can confirm that this does infact work with NPC's as well as Players.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests