Vice Underdogs

Scripting => Script Showroom => Topic started by: stormeus on January 07, 2012, 06:32:42 am

Title: [REL] Stormeus' Extensible Scripts
Post by: stormeus on January 07, 2012, 06:32:42 am
As usual, I got bored one night and came up with an interesting concept. Instead of having to edit various functions and files to add code you found or to write in a new, complex feature, you can hook and include files to add functionality.

Stormeus' Extensible Scripts (SES) has two types of "objects" (which is just stuff it can load):

Includes are useful for adding functions that can be used by any other hooks or includes. They should contain functions, such as getting the speed of a vehicle.

Hooks add functionality to an event, like onServerStart or onPlayerMove. Instead of having to manually edit these functions in whatever file they may be, you can hook them by adding a line to an XML file.

A typical SES XML file will look like this:
Code: (Configuration/SES.xml) [Select]
<ses>
    <hook>DemoHook</hook>
    <hook>BasicAnticheat</hook>
    <hook>JoinMessages</hook>

    <include>GetVehicleVelocity</include>
</ses>

Includes are regular Squirrel files. However, hook files are different. If a function named SES_Init() is found in a hook file, it will be called. You can then use different hooking functions, like hook_onServerStart( functionPointer ), to add functionality to a server. Not only that, but each hook function will return an ID which can be used to unhook later. For example:

Code: (Hooks/Demo.nut) [Select]
function myOnServerStart() { print( "good" ); }

function SES_Init()
{
    local hookID = hook_onServerStart( myOnServerStart );

    if( hooked_onServerStart( hookID ) )
        unhook_onServerStart( hookID );
}

Download
http://stormeus.vicelegends.com/ses.zip

(https://viceunderdogs.com/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FJ4Wuu.png&hash=ef30f7df591434efa80d855bca0898b5db68ab95)
Title: Re: [WIP] Stormeus' Extensible Scripts
Post by: Zeke on January 07, 2012, 07:29:20 am
Nice  ;)
Title: Re: [WIP] Stormeus' Extensible Scripts
Post by: Sephiroth on January 07, 2012, 10:25:37 am
This is an excellent concept.

If I get the privilege, I can't wait to see the finished product.


also when did you end up coming up with this?
Title: Re: [WIP] Stormeus' Extensible Scripts
Post by: Thijn on January 07, 2012, 11:02:44 am
I like the idea, but im not sure if im going to use it.
Title: Re: [WIP] Stormeus' Extensible Scripts
Post by: Charley on January 07, 2012, 11:02:54 am
Hmm, I'm not sure I fully understand the concept behind this, perhaps due to my lack of coding knowledge outside of squirrel. Could you give one or two more examples of practical uses?
Title: Re: [WIP] Stormeus' Extensible Scripts
Post by: stormeus on January 07, 2012, 04:34:53 pm
Its extensible nature makes it easier to add code snippets made by others, or to remove troublesome scripts. If a hook conflicts with another hook, comment one out in the configuration and reload the server.

It also allows for scripts to be easily interchangeable. You can break each separate feature into their own files, instead of having them all in one file with one function. For example: you script a PingCheck and StatsTracker module. Updating either one becomes easier; you only have to deal with one module instead of an entire onPlayerKill event.

The main goal is having a modular Squirrel script. (http://en.wikipedia.org/wiki/Modular_programming) Think dofile(), except you can have the same callback in a bunch of different functions without fucking up. ::)

Or better yet, think of it as a LEGO set: you can add and take out pieces whenever and wherever you want.

(Also, this was a fun experiment with custom exception handlers and function pointers.)
Title: Re: [WIP] Stormeus' Extensible Scripts
Post by: Charley on January 07, 2012, 07:38:20 pm
Got it, nice one. Good idea, though like Thijn I'm not sure I'll use it.
Title: Re: [WIP] Stormeus' Extensible Scripts
Post by: stormeus on January 07, 2012, 09:21:19 pm
Uploaded what I have. I'm pretty sure it's good to go. I might use this for myself in later scripts, and if anyone else decides to use it, great.

http://stormeus.vicelegends.com/ses.zip