Page 1 of 1

New Lua Function: GetGroup(Spawn)

Posted: Sat Oct 06, 2012 9:52 pm
by Jabantiz
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

Re: New Lua Function: GetGroup(Spawn)

Posted: Sun Oct 07, 2012 11:20 am
by John Adams
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 :)

Re: New Lua Function: GetGroup(Spawn)

Posted: Sun Oct 07, 2012 4:05 pm
by Jabantiz
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.

Re: New Lua Function: GetGroup(Spawn)

Posted: Sun Oct 07, 2012 5:15 pm
by Jabantiz
I tested this with a spawn group and can confirm that this does infact work with NPC's as well as Players.