• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Snippet] PreventSave

PreventSave - Disable Game Saving

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
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*       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
 
Last edited:
Level 9
Joined
Nov 28, 2008
Messages
704
Every map should have an option to use this, to prevent laming.

Thank you!

Edit: Wait... why are you setting a global variable to GetLocalPlayer()? I'm pretty sure that desyncs.

JASS:
library PreventSave initializer onInit

    globals
        boolean GameAllowSave = false
    endglobals

//====================================
// Do not edit below this line
//====================================

    globals
        private dialog D = DialogCreate()
        private timer T = CreateTimer()
    endglobals

    private function Exit takes nothing returns nothing
        call DialogDisplay(GetLocalPlayer(), D, false)
    endfunction

    private function StopSave takes nothing returns nothing
        if not GameAllowSave then
            call DialogDisplay(GetLocalPlayer(), D, true)
            call TimerStart(T, 0.00, false, function Exit)
        endif
    endfunction

    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterGameEvent(t, EVENT_GAME_SAVE)
        call TriggerAddAction(t, function StopSave)
    endfunction

endlibrary

Shouldnt it be like that?
 
Last edited by a moderator:
Level 17
Joined
Apr 27, 2008
Messages
2,455
I would suggest this :

JASS:
//==================================== // PreventSave
//====================================
//
//   This library allows you to enable or disable game saving. 
//   It works by showing a dialog instantly before a game is saved and this causes the dialog
//   to close. It does nothing visually to the game as far as I've noticed.
//
//   You can toggle allowing or disallowing saving by setting
//   GameAllowSave to true, or false.
//
//====================================
// Import Instructions
//====================================
//
//      Decide whether you want GUI or vJASS, then copy the trigger(s) over to your map.
//
//      This requires JassHelper which is included
//      in JassNewGenPack.
//
//====================================

library PreventSave initializer onInit
    
    globals
        boolean GameAllowSave = false
    endglobals
    
//====================================
// Do not edit below this line
//====================================
    
    globals
        private dialog D = DialogCreate()
        private timer T  = CreateTimer()
        private player p
    endglobals
    
    private function Exit takes nothing returns nothing
        call DialogDisplay(p, D, false)
    endfunction
    
    private function StopSave takes nothing returns nothing
        if not GameAllowSave then
            call DialogDisplay(p, D, true)
        endif
        call TimerStart(T, 0.00, false, function Exit)
    endfunction
    
    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterGameEvent(t, EVENT_GAME_SAVE)
        call TriggerAddAction(t, function StopSave)
        set p = GetLocalPlayer()
    endfunction

endlibrary
Yes it will be "less efficient" but without breaking backward compatibility you will allow to enable or not saving game for players.
Indeed, we will be able to play with GetLocalPlayer and the boolean.
If you have no clue of what i'm talking about, check this :
http://www.hiveworkshop.com/forums/jass-resources-412/snippet-localhelper-215108/

Btw, what happens if we have already a dialog displayed ?

 
I would suggest this :
Yes it will be "less efficient" but without breaking backward compatibility you will allow to enable or not saving game for players.
Indeed, we will be able to play with GetLocalPlayer and the boolean.
If you have no clue of what i'm talking about, check this :
http://www.hiveworkshop.com/forums/jass-resources-412/snippet-localhelper-215108/

Disabling/enabling saving for just one player still causes the game to be saved for everybody. At least it did in my (LAN) tests.
It also displays the message "You were disconnected" to the other players.

JASS:
scope example initializer onInit
    private function onInit takes nothing returns nothing
        if (GetLocalPlayer() == Player(0)) then
            set GameAllowSave = true
        endif
    endfunction
endscope

Btw, what happens if we have already a dialog displayed ?

The script still blocks the save.
 
I mean allow or not the player X to try to save.
It shouldn't cause a desync with my edit of your code, or it does ?
The timer starts for everybody, and displaying a dialog in a local block should be fine.

Yeah, with your edit it doesn't desync.
I was also confused because I saw the load file on both games, so I assumed it created the save file for all players but obviously it's just on my hard drive:p

I'll update the script in a bit, thanks.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
call TriggerAddCondition(t, function StopSave)
call TriggerAddCondition(t, Filter(function StopSave) )
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Filter() is optional in this case IIRC, it's a vJass feature : implicit boolexpr
It will add it automatically for the resulted jass code.

So now just to be sure,
if you use PreventSave(true) with player red, then when he will try to save the game, it will not be saved on each computer, regardless if you use PreventSave(false) for some other players ?
 
call TriggerAddCondition(t, function StopSave)
call TriggerAddCondition(t, Filter(function StopSave) )

Filter is not needed because the function is private, meaning it will only be passed to through Filter() once.

The point of creating a boolexpr like that is that it gets cached for re-use and this function will never be re-used.

So in this case it's just a wasted function call.

So now just to be sure,
if you use PreventSave(true) with player red, then when he will try to save the game, it will not be saved on each computer, regardless if you use PreventSave(false) for some other players ?

I can probably test this later, though I will need two computers because afaik this can't be tested locally, even on LAN since the save file is created on the HDD.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
If it doesn't work as intended, instead of editing the boolean in a local block you could use an other array one and GetTriggerPlayer() or something like that.
If a such native response event doesn't exit, then maybe we have a specific player event for that ?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
regarding the TriggerAddCondition, I think you should put the function into Filter block even if it is done implicitly, because if some newbie reads it, he may try to do the same thing later on, and be surprised why it wont work(if it wont get Conditioned implicitly), also Filter > Condition
 
If somebody could test over multiple computers that would help.

JASS:
/* 
If Player(1) saves, then it shows the "Saving..." dialog 
and a save file is created. No dialog pops up for Player(0).
*/

call PreventSave(Player(1), false)
call PreventSave(Player(0), true)
So it should be working however I'm testing on a single computer and the save file will always show up.
 
Top