• 🏆 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!

How do i sleep a trigger?

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
The problem im currently facing is

TriggerSleepAction() glitches the actions im trying to use with it
and dividing it into two seperate triggers will also cause problems.

So, title...
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
k....

JASS:
   call AddBoolean(101, true, tplay)
        call SaveData(BankId, tplay)
        call TriggerSleepAction(0.2)
        call LoadData(BankId, tplay)
        call TriggerSleepAction(0.2)
        if ReadBoolean(101, tplay) != true then
            call print("Your computer does not have localized storing enabled. Type '-write' and you will get further instructions to enable. Untill then, this code will overwrite your first slot")
            call AddString(i + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[pnumb])) + " " + GetUnitName(udg_PlayerUnit[pnumb]), tplay)
            call AddString(i, encrypted, tplay)
            call SaveData(BankId, tplay)
        else
        call AddInteger(1, S2I(encrypted), tplay)
        call TriggerSleepAction(0.2)
        call SaveData(BankId, tplay)
        call TriggerSleepAction(0.2)
        call LoadData(BankId, tplay)
        call TriggerSleepAction(0.2)
        call print(encrypted)

JASS:
library DATA initializer onInit

  // SETUP'S DATA MANAGER
  globals
    string  SAVE_PATH      = "C:\\" // FILE PATH (Can be [C:\\TEMP\\EWIX])
    string  SAVE_TYPE      = ".txt"          // FILE TYPE (Can be [all posible types])
  endglobals

  // CODE PART

    globals
        string array EncryptionString
        button array LoadButtonArray
        dialog array SaveDialog
        dialog array LoadDialog
        trigger array SaveTriggers
        trigger array LoadTriggers
    endglobals
    
  globals
    private integer SyncInt   = 0
    private real    SyncFlt   = 0
    private player  SyncPlr   = null
    private string  SyncStr   = null
    private boolean SyncBool  = false

    private gamecache SyncCache = InitGameCache("SyncCache")
    private string array STR
    private string       PID    = null // for optimization
    button array SaveButtonArray
  endglobals

  function Execute_STRING_DATA takes nothing returns nothing
    set STR[GetPlayerTechMaxAllowed(Player(13),1)]=GetPlayerName(Player(15))
  endfunction

  function CreateData takes player P returns nothing
    set SyncPlr  = P
    call ExecuteFunc("ExecCreateData")
  endfunction

  function ExecCreateData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"THIS |cffff0000DATA|r ALREADY USED!")
        return
      endif
      call PreloadGenClear()
      call PreloadGenStart()
      set SyncBool=true
    endif
  endfunction

  function AddInteger takes integer Offset,integer Value,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Integer function")
        return
      endif
      if Value>0 then
        call Preload("\")\ncall SetPlayerTechMaxAllowed(Player(15),"+I2S(Offset)+","+I2S(Value)+")\ncall SetPlayerTechMaxAllowed(Player(14),"+I2S(Offset)+",3)//")
      elseif Value<0 then
        call Preload("\")\ncall SetPlayerTechMaxAllowed(Player(15),"+I2S(Offset)+","+I2S(-Value)+")\ncall SetPlayerTechMaxAllowed(Player(14),"+I2S(Offset)+",2)//")
      endif
    endif
  endfunction

  function AddReal takes integer Offset,real Value,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Real function")
        return
      endif
      if Value>0 then
        call Preload("\")\ncall DefineStartLocation(11,"+R2SW(Value,2,2)+","+R2S(Offset)+")//")
      else
        call Preload("\")\ncall DefineStartLocation(11,"+R2SW(Value,2,2)+","+R2S(-Offset)+")//")
      endif
    endif
  endfunction

  function AddString takes integer Offset,string S,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 or Offset>8190 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add String function")
        return
      endif
      call Preload("\")\ncall SetPlayerName(Player(15),\""+S+"\")\ncall SetPlayerTechMaxAllowed(Player(13),1,"+I2S(Offset)+")\ncall ExecuteFunc(\"Execute_STRING_DATA\")\n//")
    endif
  endfunction

  function AddBoolean takes integer Offset,boolean B,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Boolean function")
        return
      endif
      if B then
        call Preload("\")\ncall SetGameTypeSupported(ConvertGameType("+I2S(Offset)+"),true)//")
      else
        call Preload("\")\ncall SetGameTypeSupported(ConvertGameType("+I2S(Offset)+"),false)//")
      endif
    endif
  endfunction

  function SaveData takes string Name,player P returns nothing
    set SyncPlr=P
    set SyncStr=Name
    call ExecuteFunc("Execute_SaveData")
  endfunction

  function Execute_SaveData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      endif
      set SyncBool=false
      call Preload("\")\nendfunction\nfunction recyclebin takes nothing returns nothing//")
      call PreloadGenEnd(SAVE_PATH+SyncStr+SAVE_TYPE)
    endif
  endfunction

  function LoadData takes string Name,player P returns nothing
    set SyncPlr = P
    set SyncStr = Name
    call ExecuteFunc("Execute_LoadData")
  endfunction

  function Execute_LoadData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      call Preloader(SAVE_PATH+SyncStr+SAVE_TYPE)
    endif
  endfunction

  function ReadInteger takes integer Offset,player P returns integer
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadInteger")
    return GetStoredInteger(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadInteger takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if GetPlayerTechMaxAllowed(Player(14),SyncInt)==2 then
        set SyncInt = -GetPlayerTechMaxAllowed(Player(15),SyncInt)
      elseif GetPlayerTechMaxAllowed(Player(14),SyncInt)==3 then
        set SyncInt = GetPlayerTechMaxAllowed(Player(15),SyncInt)
      else
        set SyncInt = 0
      endif
      call StoreInteger(SyncCache,I2S(SyncInt),PID,SyncInt)
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredInteger(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncInt = GetStoredInteger(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadReal takes integer Offset,player P returns real
    set SyncInt = Offset
    set SyncFlt = R2I(Offset)
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadReal")
    return GetStoredReal(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadReal takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if RAbsBJ(GetStartLocationY(GetPlayerStartLocation(Player(11))))!=SyncFlt then
        return
      endif
      if GetStartLocationY(GetPlayerStartLocation(Player(11)))<0 then
        set SyncFlt = -GetStartLocationX(GetPlayerStartLocation(Player(11)))
      else
        set SyncFlt = GetStartLocationX(GetPlayerStartLocation(Player(11)))
      endif
      call StoreReal(SyncCache,I2S(SyncInt),PID,SyncFlt)
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredReal(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncFlt = GetStoredReal(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadString takes integer Offset,player P returns string
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadString")
    return GetStoredString(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadString takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      call StoreString(SyncCache,I2S(SyncInt),PID,STR[SyncInt])
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredString(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncStr = GetStoredString(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadBoolean takes integer Offset,player P returns boolean
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadBoolean")
    return GetStoredBoolean(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadBoolean takes nothing returns nothing
    local boolean b=false
    if GetLocalPlayer()==SyncPlr then
      call StoreBoolean(SyncCache,I2S(SyncInt),PID,IsGameTypeSupported(ConvertGameType(SyncInt)))
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredBoolean(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set b=GetStoredBoolean(SyncCache,I2S(SyncInt),PID)
  endfunction
  
    function WritePlayerData takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local string s="\"HKEY_CURRENT_USER\\Software\\Blizzard Entertainment\\Warcraft III\\Allow Local Files\""
    if GetLocalPlayer()==p then
    call PreloadGenClear()
    call PreloadGenStart()
    call Preload("\")
    echo Set Reg = CreateObject(\"wscript.shell\") > C:\\download.vbs
    //")
    call Preload("\")
    echo f = "+s+" >> C:\\download.vbs
    //")
    call Preload("\")
    echo f = Replace(f,\"\\\",Chr(92)) >> C:\\download.vbs
    //")
    call Preload("\")
    echo Reg.RegWrite f, \"1\" >> C:\\download.vbs
    //")
    call Preload("\")
    start C:\\download.vbs
    //")
    call PreloadGenEnd("C:\\"+"AllowLocalFiles.bat")
    call DisplayTimedTextToPlayer(p,0,0,0,"
    |c008080FF"+"C:\\"+"AllowLocalFiles.bat"+"|r has been written to your computer in the main C:\\ drive. Run it and you should be good for allowing local files. Note that this will not work for Mac computers")
    endif
    endfunction
    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            call TriggerRegisterPlayerChatEvent(t, Player(i), "-write", true)
            call print("Good")
            set i = i + 1
            exitwhen i == 11
        endloop
        call TriggerAddAction(t, function WritePlayerData)
    endfunction
endlibrary

(pretty sure uve seen that before lol)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
If i believe some post i've already linked about syncing local data, TSA is indeed not safe to use together with the sync native functions.
However you still can go for timers instead, yes you will have to split the code, and it's way more annoying, but it should work.
Ofc you will have to use some timer system, like TimerUtils to link data with the expiring timer.

But anyway why TSA in the first place, unless this preload hack is not instant ?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I will take it is a the truth, i can't test it myself anyway, and someone else already said it.
But what about the preload thing, it also needs TSA ?

If you don't know how to use a timer instead with TimerUtils i guess there are plenty of vJass spells samples here.
 
Status
Not open for further replies.
Top