[Snippet] NoSaveGame

User avatar
nelmvn
Registered users
Registered users
Posts: 9
Joined: Mon Nov 19, 2018 5:44 pm
Reputation: 0
Location: Philippines
Contact:
Philippines

[Snippet] NoSaveGame

#1

Post by nelmvn » Wed Dec 05, 2018 10:31 am

No Save Game

It prevents to use Save Game function to all players.

Code: Select all

//! zinc
library NoSaveGame  /* v1.0.0.5
************************************************************************************
*
*    No Save Game
*        by nel
*
*       It prevents to use Save Game function to all players.
*
***********************************************************************************/


       requires

           optional SimError,         /* http://www.wc3c.net/showthread.php?t=101260 */
           optional RegisterGameEvent /* https://www.hiveworkshop.com/threads/snippet-registerevent-pack.250266/ */


/***********************************************************************************
*
*   SETTINGS
*
*/
{
    public {
        /*
        *    It's a content of the error message.
        */
        string  nsgErrMsg = "You are not allowed to use Save Game.";

        /*
        *    Toggleable Error Message.
        */
        boolean nsgDisplayErrMsg = true;

        /*
        *    Toggleable NoSaveGame.
        */
        boolean nsg = true;
    }

/*
***********************************************************************************/

    private {
        constant dialog DIALOG = DialogCreate();
        constant timer TIMER = CreateTimer();

        struct NoSaveGame [] { private static method onInit() {
            trigger Stop = CreateTrigger();

            static if( LIBRARY_RegisterGameEvent ) {
                RegisterGameEvent(EVENT_GAME_SAVE, function() {
                    player pl;

                    if( nsg ) {
                        pl = GetLocalPlayer();
                        
                        DialogDisplay(pl, DIALOG, true);
                        TimerStart(TIMER, 0, false, null);

                        static if( LIBRARY_SimError ) {
                            SimError(pl, nsgErrMsg);
                        } else {
                            DisplayTimedTextToPlayer(pl, 0.52, 0.96, 2.00, 
                                "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
                                "|cffffcc00" + nsgErrMsg + "|r" 
                            );
                        }

                        pl = null;
                    }
                });

                TriggerRegisterTimerExpireEvent(Stop, TIMER);
                TriggerAddCondition(Stop, Condition(function() -> boolean {
                    if( nsg ) { 
                        DialogDisplay(GetLocalPlayer(), DIALOG, false);
                    }

                    return false;
                }));

                Stop = null;
            } else {
                trigger Save = CreateTrigger();

                TriggerRegisterGameEvent(Save, EVENT_GAME_SAVE);
                TriggerAddCondition(Save, Condition(function() -> boolean {
                    player pl;

                    if( nsg ) {
                        pl = GetLocalPlayer();

                        DialogDisplay(pl, DIALOG, true);
                        TimerStart(TIMER, 0, false, null);

                        if( nsgDisplayErrMsg ) {
                            static if( LIBRARY_SimError ) {
                                SimError(pl, nsgErrMsg);
                            } else {
                                DisplayTimedTextToPlayer(pl, 0.52, 0.96, 2.00, 
                                    "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
                                    "|cffffcc00" + nsgErrMsg + "|r" 
                                );
                            }
                        }

                        pl = null;
                    }

                    return false;
                }));

                TriggerRegisterTimerExpireEvent(Stop, TIMER);
                TriggerAddCondition(Stop, Condition(function() -> boolean {
                    if( nsg ) { 
                        DialogDisplay(GetLocalPlayer(), DIALOG, false);
                    }

                    return false;
                }));

                Save = null;
                Stop = null;
            }
        }}
    }
}
//! endzinc
You do not have the required permissions to view the files attached to this post.

Return to “Systems”

×