How to call a self made plugin from the Script tool

I'm wanting to know how to call a function in a self made plugin from the script tool in RPG Maker MV.

When I say "script tool" I'm referring to the "script" button on the bottom right of page 3.
You simply type the script call directly into the box. If you have a plugin with a global variable of some sorts in the plugin file. You can call it by typing the name of the namespace (if it has one). You can type more than just scripts in that box; it's mainly for typing plain JavaScript. If you provide the plugin in question, I could provide more details @bomblord.
Sure, I have a file in my plugins folder with this function in it.


function lineOfSight (sightLimit, eventIdentification){
//variable
var sight; //variable to know whether the player has been seen

//if they are in the same X position and within the sight limit check for obstacles
if($gamePlayer.x == $gameMap.event(eventIdentification).x && Math.abs(($gamePlayer.y - $gameMap.event(eventIdentification).y)) <= sightLimit){
//a slightly different script runs depending on whether or not the difference in position is positive or negative
if(($gamePlayer.y - $gameMap.event(eventIdentification).y) >= 0 ){
//loop through every position between the current event and the player and check for obstacles
for(y = $gamePlayer.y; y > $gameMap.event(eventIdentification).y; y--){
//if there is something in the way break the loop to prevent the false from being overwritten
if(!($gameMap.isPassable($gamePlayer.x, y))){
sight = false;
break;
}
//if nothing is in the way the player can be seen
else
sight = true;
}
}
//run if the position is negative
if(($gamePlayer.y - $gameMap.event(eventIdentification).y) < 0){
for(y = $gamePlayer.y; y < $gameMap.event(eventIdentification).y; y++){
if(!($gameMap.isPassable($gamePlayer.x, y))){
sight = false;
break;
}
else
sight = true;
}
}
}
//run if the player and event share the same Y position and are within the sight limit
//everything else is the same as above just swapped for the Y position
if($gamePlayer.y == $gameMap.event(eventIdentification).y && Math.abs(($gamePlayer.y - $gameMap.event(eventIdentification).y)) <= sightLimit){
if(($gamePlayer.x - $gameMap.event(eventIdentification).x) >= 0){
for(x = $gamePlayer.x; x > $gameMap.event(eventIdentification).x; x--){
if(!($gameMap.isPassable(x, $gamePlayer.y))){
sight = false;
break;
}
else
sight = true;
}
}
if(($gamePlayer.x - $gameMap.event(eventIdentification).x) < 0){
for(x = $gamePlayer.x; x < $gameMap.event(eventIdentification).x; x++){
if(!($gameMap.isPassable(x, $gamePlayer.y))){
sight = false;
break;
}
else
sight = true;
}
}
}
//if after everything the player can be seen then throw event self switch A
if(sight == true)
$gameSelfSwitches.setValue([this._mapId, eventIdentification, 'A'], true);
}



I want to call that function (file name is lineOfSight.js)
Okay, so that's the whole file?
In that case, you should be able to call the function with :


lineOfSight(param1, param2)



Whatever parameters you need for it to work, but you're going to need some boilerplate code in order for that to work in MV.


You should be able to activate it by going to PluginManager in the editor. If you can't, then you need to add this line to the top of the file.


var params = PluginManager.parameters("lineOfSight");


This is so that the PluginManager can recognize the file. @bomblord


After that, lineOfSight should be available globally throughout the game.
Thanks after loading it into the plugin manager I was able to call the function and verified it was working.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-call-a-self-made-plugin-from-the-script-tool.69064/