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

PreloadGen

Status
Not open for further replies.
Level 9
Joined
Mar 26, 2017
Messages
376
I would like to save the amount of games and wins for players in my map. Something real simple.

Since I'm not a huge fan of making the players type I would like to make use of the PreloadGen function.
I would like to put a script into a file, that is able to be read at game start.

I am currently stuck on getting the syntax right to put the correct script in a file so that something like a small string is loaded for a user.

Code:
PreloadGenStart()
Preload("\" )\nBlzSetAbilityTooltip("1097690227", \""..XXX.."\", "1")\n//")
PreloadGenEnd("filename.pld")

Can someone help me here and point out where I made a mistake in the second line?

And if someone is aware, is it also possible to be able to import a string from file by entering it into a variable, instead of having to use BlzSetAbilityTooltip to import a string?
 
Level 9
Joined
Mar 26, 2017
Messages
376


This great resource is where I got this line of code from :p

If I read right, TriggerHappy loads several commands into the file to be able to split a very long string.
I guess that does mean that if he is forced to use a workaround like that, BlzSetAbilityTooltip is probably the only way to import a string into the game from a file.

Like the line that TriggerHappy uses to generate the script in the file:
Code:
call Preload("\" )\ncall BlzSetAbilityTooltip(" + I2S(.AbilityList[c]) + ", \"" + prefix + chunk + "\", " + I2S(lev) + ")\n//")

I think I might found out what I have done wrong, after looking closely at it again.
>The part Preload("\" )\nBlzSetAbilityTooltip("1097690227", \""..XXX.."\", "1")\n//")" should have been ".."1097690227".." or 1097690227.
>And Preload("\" )\nBlzSetAbilityTooltip("1097690227", \""..XXX.."\", "1")\n//")" should have been ".."1".." or 1.

Now it doesn't give a syntax error anymore :) Hopefully the method will work like in the FileIO resource.
 
Level 9
Joined
Mar 26, 2017
Messages
376
Hmm, I'm afraid I just cannot get it to work.

I did manage to generate a file with script, but it seems like PreloadGen automatically puts some JASS statements in there, even if I run in lua mode. So I believe there is no way to get this working in lua.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,555
edit: Found the code.

Lua:
--SaveAbil is a Global Variable = "A000"
--SaveFile is a Global Variable = A table containing "The File Name" like SaveFile[1] = "MyMapName"

function ExampleSave()
    --Preload Start
    local teststring1 = "test string one"
    local teststring2 = "test string two"
    local teststring3 = "test string three"
    local lvlstring = "0"
    local f = 1 --File #

    --Save File 1
    PreloadGenClear()
    PreloadGenStart()
    BlzSetAbilityTooltip(FourCC(SaveAbil), teststring1, 0)
    Preload("\")\ncall BlzSetAbilityTooltip('A000',\""..teststring1.."\","..lvlstring..")\nreturn//")
    PreloadGenEnd("Test\\"..SaveFile[f]..".txt")

    --Save File 2
    f = f + 1
    PreloadGenClear()
    PreloadGenStart()
    BlzSetAbilityTooltip(FourCC(SaveAbil), teststring2, 0)
    Preload("\")\ncall BlzSetAbilityTooltip('A000',\""..teststring2.."\","..lvlstring..")\nreturn//")
    PreloadGenEnd("Test\\"..SaveFile[f]..".txt")

    --Save File 3
    f = f + 1
    PreloadGenClear()
    PreloadGenStart()
    BlzSetAbilityTooltip(FourCC(SaveAbil), teststring3, 0)
    Preload("\")\ncall BlzSetAbilityTooltip('A000',\""..teststring3.."\","..lvlstring..")\nreturn//")
    PreloadGenEnd("Test\\"..SaveFile[f]..".txt")
end
Lua:
function ExampleLoad()
    --Preload Start
    local teststring = ""
    local lvlstring = "0"
    local f = 1 --File #

    --Load File 1
    Preloader("Test\\"..SaveFile[f]..".txt")
    teststring = BlzGetAbilityTooltip(FourCC(SaveAbil), lvlstring)
    print("teststring 1:", teststring)

    --Load File 2
    f = f + 1
    Preloader("Test\\"..SaveFile[f]..".txt")
    teststring = BlzGetAbilityTooltip(FourCC(SaveAbil), lvlstring)
    print("teststring 2:", teststring)

    --Load File 3
    f = f + 1
    Preloader("Test\\"..SaveFile[f]..".txt")
    teststring = BlzGetAbilityTooltip(FourCC(SaveAbil), lvlstring)
    print("teststring 3:", teststring)
end
That will create 3 Files named Test\"Your File Name".
You can then load them between games.

I don't really know where to go from here though. Like how to prevent players from editing the files, how to prevent desync online, etc...
 
Last edited:
Level 9
Joined
Mar 26, 2017
Messages
376
edit: Found the code.

I don't really know where to go from here though. Like how to prevent players from editing the files, how to prevent desync online, etc...

Amazing, it works perfectly :)
So apparently these JASS statements do fire correctly in lua mode after all.
Really happy you posted this, because I had already given up on it!

To prevent editing you might use encryption. To make it more difficult for people who know how to read a map script you might even obfuscate the encryption scripts.

There is some information on how you can encrypt in Pipedream's encryption system (bottom two triggers of this map)
Codeless Save and Load (Multiplayer) - v3.0.1
If I can produce some simple code for lua I will share it in this topic.


As for syncing, I believe syncing the loadstring is an absolute necessity.
Looking at TriggerHappy's host detection, I believe it can be done like this:

At gamestart:
Call BlzTriggerRegisterPlayerSyncEvent for every player.
Then for the action function that belongs to this trigger run:
GetTriggerPlayer
BlzGetTriggerSyncData

After loading file: Call BlzSendSyncData to send the loadstring.

I believe with these functions you end up with all loadstrings synced over all players, though I have yet to test this.
 
Last edited:
Call BlzSendSyncData to send the loadstring.
Call BlzTriggerRegisterPlayerSyncEvent for every player.
Then for the action function that belongs to this trigger run:
GetTriggerPlayer
BlzGetTriggerSyncData

I believe with these functions you end up with all loadstrings synced over all players, though I have yet to test this.
Yes, you're right. :)
 
Status
Not open for further replies.
Top