Data Realms Fan Forums
http://45.55.195.193/

Pi menu tutorial?
http://45.55.195.193/viewtopic.php?f=1&t=31953
Page 1 of 1

Author:  kaboomarang [ Tue Oct 16, 2012 12:10 am ]
Post subject:  Pi menu tutorial?

I've noticed there's a lack of a stickied explanation about how the Pi menu works,
someone who is well versed in LUA could probably decipher the various Pi menu scripts that are already in vanilla and work from there,
but the average player/aspiring new modder would probably be lost in this subject.

So, I was wondering if there was anyone who could tell me how a basic Pi menu script works, f.e. a button that switches between burst fire mode and automatic mode.

Edit: I have no experience in LUA coding and I've only dipped my toes into .ini , if that is any explanation on my coding skills.

Author:  Asklar [ Tue Oct 16, 2012 12:26 am ]
Post subject:  Re: Pi menu tutorial?

Let's look at the script of the Ronin Thumper which makes you change ammo (just one of the scripts, the other one is exactly the same one though it changes the magazine to another one).

Code:
function ThumperGrenadeLauncherImpact(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      local gun = ToHDFirearm(gun);
      local magSwitchName = "Magazine Ronin Thumper Grenade Launcher Impact";
      if gun.Magazine == nil or (gun.Magazine ~= nil and gun.Magazine.PresetName ~= magSwitchName) then
         gun:SetNextMagazineName(magSwitchName);
         gun:Reload();
      end
   end
end


First you are going to notice that the name of the function is one set by the modder, in this case one which is easy to remember and hard to confuse: function ThumperGrenadeLauncherImpact(actor).

Now, inside the brackets it says "actor", which is the argument needed for the function to work. "Actor" in this case is the unit who has this new pie slice in it's pie menu, for example, if this script is attached to a gun, the actor which is holding the gun is (actor).

The rest of the script is just common lua, there's nothing that makes it different from your everyday scripts. It simply uses actor as a reference to the actor you are going to be applying the script to. And if, for example, you wanted to do something to the actor's gun, you store the value actor.EquippedItem in a variable and change it from there.

In fact, Pie menu functions are simply lua functions that can be triggered with a pie menu and have "actor" as the only argument (citation needed).


Analyze a bit the script, it's simple, if you have doubts or need any explanation just ask.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/