• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Save Code to text file~

Status
Not open for further replies.
Level 3
Joined
Dec 22, 2009
Messages
39
Hello. I was just wondering it it's possible to save my save code to a text file (just like in GoH and TKOK) while using AceHart's GUI-friendly Save/Load System? If it's possible could somebody please explain as simple as possible? Unfortunately, I can't understand JASS, I tried but I really can't, but I'm really desperate in making my RPG Map. I am begging for help. Thank you.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Yeah, this is possible. I did the same thing for someone pretty recently (based on another Save/Load, but that doesn't really matter).

Link to that post.

I know you said you didn't understand JASS, but you'll have to deal with this for a short moment.
This is what the code looks like:
JASS:
function CreateTextFile takes nothing returns nothing
    local integer p = GetPlayerId(GetTriggerPlayer())+1
    local string heroName = GetUnitName(udg_Hero)
    local integer heroLevel = GetHeroLevel(udg_Hero)
    
    call PreloadGenClear()
    call PreloadGenStart()
    
    // The line below creates the log
    // Right now, this is:
    //      Hero: (hero name)
    //      Level: (hero level)
    //      Code: -load XXXX
    call Preload("\r\n\t\t\t\tHero: " + heroName + "\r\n\t\t\t\t" + "Level: " + I2S(heroLevel) + "\t\t\r\n\t\t\t\t" + "Code: -load " + udg_NPS_Password + "\r\n\n\t\t    ")
    
    // The line below creates the file at the specified location
    // Right now, this is:
    //      "Warcraft III\MapName\(hero name) - (hero level)"
    call PreloadGenEnd("MapName\\" + heroName + " - " + I2S(heroLevel) + ".txt")
endfunction
Yes, it's JASS, but you don't have to modify that much.
First thing you need to do, is place it in the map's header.
You have to change the variable "udg_NPS_Password" to ""udg_Code" (I believe AceHart uses that variable for the message).
The variable "Hero[X]" stores the hero for player X (so Hero[1] contains the hero for Player 1).
Once you understand that, you're good to go.

This is what the text-file like:
Code:
function PreloadFiles takes nothing returns nothing
	call Preload( "
		                Hero: Paladin
				Level: 105		
				Code: -load  GGGG GGg6 xPOw iV
		    " )
	call PreloadEnd( 0.0 )
endfunction

Now you still need to connect that function with the save-function.
To do this, you can just use this action:
  • Custom script: call CreateTextFile()
right after the save/load-system displays the message.
 
Level 3
Joined
Dec 22, 2009
Messages
39
Thank you so much! Im sorry if I posted in the wrong thread, I saw triggers and scripts so i thought this would by the right place. But, thank you so much, really.
 
Level 3
Joined
Dec 22, 2009
Messages
39
I have a problem, when the code gets saved in a text file, the color codes shows up in the text file too. How can i get rid of the color codes?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Ah right, the system I did it for didn't have that problem because it used 2 variables (1 with color codes, 1 without), AceHart's system doesn't do that.

The code can be changed to this, then:
JASS:
function CreateTextFile takes string saveCode returns nothing
    local integer p = GetPlayerId(GetTriggerPlayer())+1
    local string heroName = GetUnitName(udg_TempUnit)
    local integer heroLevel = GetHeroLevel(udg_TempUnit)
    
    call PreloadGenClear()
    call PreloadGenStart()
    
    // The line below creates the log
    // Right now, this is:
    //      Hero: (hero name)
    //      Level: (hero level)
    //      Code: -load XXXX
    call Preload("\r\n\t\t\t\tHero: " + heroName + "\r\n\t\t\t\t" + "Level: " + I2S(heroLevel) + "\t\t\r\n\t\t\t\t" + "Code: -load " + saveCode + "\r\n\n\t\t    ")
    
    // The line below creates the file at the specified location
    // Right now, this is:
    //      "Warcraft III\MapName\(hero name) - (hero level)"
    call PreloadGenEnd("MapName\\" + heroName + " - " + I2S(heroLevel) + ".txt")
endfunction
"saveCode" shouldn't be changed here.

What you need to do now, is create the text-file before any color gets added.
In case you have JNGP, you can press CTRL + F (while still in the map's header) and find "return c".
Right above that, paste call CreateTextFile(c).

If you don't have JNGP, "return c" is the last action of the function "SaveLoad_EncodeValues" (so that CreateTextFile-call should be the second to last action).
 
Level 3
Joined
Dec 22, 2009
Messages
39
I think I have followed exactly what you told me but, I get this error.
error.png
 
Level 3
Joined
Dec 22, 2009
Messages
39
Yeah, i thought it's okay because when I tried earlier (when it includes colour codes) it works. But, man, you're a life saver, i am really really really really thankful for this. I was starting to get depressed because of how limited are the things i can do.
 
Status
Not open for further replies.
Top