View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:02 pm



Reply to topic  [ 2 posts ] 
 Pi menu tutorial? 
Author Message

Joined: Tue Jul 27, 2010 6:29 am
Posts: 38
Reply with quote
Post 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.


Tue Oct 16, 2012 12:10 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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.


Tue Oct 16, 2012 12:26 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.046s | 13 Queries | GZIP : Off ]