require
Split your scripts into modules
Creating a module
cs2.js
var entityStride = 112;
function getHealth(player)
{
return entity.getHealth(player);
}
module.exports =
{
// non existing funcs
localPlayer: function () { return entity.getLocalPlayer(); },
// existing funcs
health: getHealth,
stride: entityStride
};Requiring a module
main.js
✅ When to use a module
Bad for
Small scripts without many lines
Scripts with only one main feature; such as triggerbot
Best for
Large scripts with many functions and extending a lot of functionality
Scripts with many features possibly not even related to eachother
Creating your own API/Library within the Javascript Engine for self usage or sharing
🧠 Summary
⚠️Security
Require scripts are also limited by the "Script access" option in the GUI
Internal C# checkage that the require script cannot be loaded from outside of the scripts folder App data
⛓️Scope isolation
Variables defined in require file do not leak into global scope
💾Cache
Keep function and variable states consistent globally
Read and compile require file once
Last updated
Was this helpful?