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.