HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

PreventSave

11-06-2009, 04:39 PM#1
TriggerHappy
Collapse JASS:
library PreventSave initializer onInit
/***************************************************************
*
*   v1.0.1 by TriggerHappy
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*   This library allows you to enable or disable game saving. It works by showing 
*   a dialog instantly before a game is saved, causing the save to interrupt. There
*   are no known side effects.
*   _________________________________________________________________________
*   1. Installation
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*   Copy the script to your map and save it (requires JassHelper *or* JNGP)
*   _________________________________________________________________________
*   2. API
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*   This library provides one function
*
*       function SaveGameEnable takes boolean flag returns nothing
*       function IsSaveEnabled takes nothing returns boolean
*       function PreventSave takes player p, boolean flag returns nothing
*
***************************************************************/
    
    globals
        boolean GameAllowSave = false
    endglobals
    
    //====================================
    // Do not edit below this line
    //====================================
    
    globals
        private dialog Dialog = DialogCreate()
        private timer  Timer  = CreateTimer()
        private player LocalPlayer
    endglobals
    
    function SaveGameEnable takes boolean flag returns nothing
        set GameAllowSave = flag
    endfunction
    
    function IsSaveEnabled takes nothing returns boolean
        return GameAllowSave
    endfunction
    
    function PreventSave takes player p, boolean flag returns nothing
        if (p == LocalPlayer) then
            call SaveGameEnable(not flag)
        endif
    endfunction
    
    private function Exit takes nothing returns nothing
        call DialogDisplay(LocalPlayer, Dialog, false)
    endfunction
    
    private function StopSave takes nothing returns boolean
        if not IsSaveEnabled() then
            call DialogDisplay(LocalPlayer, Dialog, true)
        endif
        call TimerStart(Timer, 0.00, false, function Exit)
        return false
    endfunction
    
    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        set LocalPlayer = GetLocalPlayer()
        
        call TriggerRegisterGameEvent(t, EVENT_GAME_SAVE)
        call TriggerAddCondition(t, Filter(function StopSave))
    endfunction

endlibrary
11-06-2009, 10:32 PM#2
Rising_Dusk
Can you verify that this actually works? Testmap or something? Once you do that, this is actually a rather cool library.
11-06-2009, 10:40 PM#3
Earth-Fury
Quote:
Originally Posted by Rising_Dusk
Can you verify that this actually works? Testmap or something? Once you do that, this is actually a rather cool library.

I can confirm this works in single player, at least under very basic conditions. (I can't think of anything that should/would make this not work..)
11-06-2009, 10:40 PM#4
Rising_Dusk
Sweet, this resource is very cool then. Approved.
11-06-2009, 10:42 PM#5
TriggerHappy
I've tested online as well.
11-07-2009, 09:20 PM#6
ploks
Wouldn't it be nice to change whether or not saving is possible during runtime by calling a function?

For example if you want to allow saves when a hero is in a "safe area" but not when the hero is hunting in the woods?
11-07-2009, 09:33 PM#7
TriggerHappy
Quote:
Originally Posted by ploks
Wouldn't it be nice to change whether or not saving is possible during runtime by calling a function?

For example if you want to allow saves when a hero is in a "safe area" but not when the hero is hunting in the woods?

set GAME_ALLOW_SAVE = true.
11-07-2009, 10:27 PM#8
ploks
Quote:
Originally Posted by TriggerHappy187
set GAME_ALLOW_SAVE = true.


I'm stupid and need to improve my reading skills. Because of the capital letters I thought it was a constant. Sorry about that.
02-05-2010, 09:07 PM#9
TriggerHappy
Updated with some minor efficiency improvements.