MV Help making a custom script call

Hello, everyone! I wanted to make a common event that checks lots of things like which actor was in which slot and if it had certain states, etc. This has proved really tiresome as I have to do it for all party slots (1 to 4) and with each equipment. Basically I wanted the common event to check

if switch X is off. If off, check if the actor in party slot 1 has certain state. If so, that actor will say something and a piece of equipment will be gained and automatically equipped to actor in slot 1. Then, switch X will be turn on.

How can I do all of that with a script call? Thanks a lot for reading.
Hmmm, like (change X, Y, Z and Hello!):

const actor = $gameParty.members()[0];
if (!$gameSwitches.value(X) && actor.isStateAffected(Y)) {
$gameMessage.setFaceImage(actor.faceName(), 0);
$gameMessage.setBackground(0);
$gameMessage.setPositionType(2);
$gameMessage.add('Hello!');
this.setWaitMode('message');
actor.changeEquipById(1, null);
actor.forceChangeEquip(0, $dataWeapons[Z]);
$gameSwitches.setValue(X, true);
}

Depending on what that switch controls, you might have to separate that show message from there, don't know.

EDIT: Oh and if you have a face file with lots of different dudes' faces, you'll have to codify that face index too.
Hmmm, like (change X, Y, Z and Hello!):

const actor = $gameParty.members()[0];
if (!$gameSwitches.value(X) && actor.isStateAffected(Y)) {
$gameMessage.setFaceImage(actor.faceName(), 0);
$gameMessage.setBackground(0);
$gameMessage.setPositionType(2);
$gameMessage.add('Hello!');
this.setWaitMode('message');
actor.changeEquipById(1, null);
actor.forceChangeEquip(0, $dataWeapons[Z]);
$gameSwitches.setValue(X, true);
}

Depending on what that switch controls, you might have to separate that show message from there, don't know.
Thanks a lot for the answer! I'll test it in a minute, but I wanted to know how can I make to force equip armor pieces instead of weapons. Must I replace "weapons" for "armors" in that code? Thanks again.
Yeah, it's like $dataArmors[Z]

changeEquip slots start at 1, forceChangeEquip slots start at 0
(instead of that forceChangeEquip, I guess you could just give the item with gainItem and then use just the changeEquip, but whatever)

Original thread: https://forums.rpgmakerweb.com/threads/help-making-a-custom-script-call.182060/