News: Welcome back to Bullworth! If you haven't already, you will need to reset your password..


Author Topic: Save Data In LUA Scripts  (Read 3961 times)

0 Members and 1 Guest are viewing this topic.

Offline DaBOSS54320

  • Hero Member
  • ****
  • Posts: 3,398
  • Gender: Female
    • View Profile
Save Data In LUA Scripts
« on: April 05, 2015, 03:15:11 AM »
Edit: I really suggest you don't use this, because it can mess up some things in your save file. If you do decide to use it be careful, as it replaces other data the game needs.

PlayerSetScriptSavedData(slot,value)
PlayerGetScriptSavedData(slot,value)

These are some interesting functions... they can save data that, if the game file is saved, should be able to be read by the script next time around. But sadly... it isn't for individual scripts, the slots used here are used by all scripts, and there are only about 200ish slots that will work (The first 200). Another problem is some are frequently changed by the game, some are unlockables, and changing the values could maybe have bad effects on the game. However as of now it's the only way that I know to save data in LUA that can be used in between game sessions. This could help people who have mods that need saving. Try the demo below to see it work. If you change a value of one of the slots then save the game and reload, it should stay the same.

Be careful using these though because of all the problems I mentioned above that may affect the player's save in bad ways.

STimeCycle.lur demo
Code: [Select]
function main()
  local s = 1
  local saveSlot = 1
  repeat
    if IsButtonPressed(0,0) then
  s = s - 1
  Wait(10)
elseif IsButtonPressed(1,0) then
  s = s + 1
  Wait(10)
end
if IsButtonPressed(3,0) then
  PlayerSetScriptSavedData(saveSlot,s)
end
    if IsButtonPressed(11,0) then
  saveSlot = saveSlot - 1
  Wait(60)
elseif IsButtonPressed(13,0) then
  saveSlot = saveSlot + 1
  Wait(60)
end
TextPrintString("SELECT: "..s.."\nSAVE SLOT "..saveSlot..": "..PlayerGetScriptSavedData(saveSlot),1,1)
TextPrintString("Press down to save\nWeapon buttons to change slot",1,2)
    Wait(0)
  until not Alive
end

F_AttendedClass = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  SetSkippedClass(false)
  PlayerSetPunishmentPoints(0)
end
 
F_MissedClass = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  SetSkippedClass(true)
  StatAddToInt(166)
end
 
F_AttendedCurfew = function()
  if not PedInConversation(gPlayer) and not MissionActive() then
    TextPrintString("You got home in time for curfew", 4)
  end
end
 
F_MissedCurfew = function()
  if not PedInConversation(gPlayer) and not MissionActive() then
    TextPrint("TM_TIRED5", 4, 2)
  end
end
 
F_StartClass = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  F_RingSchoolBell()
  local l_6_0 = PlayerGetPunishmentPoints() + GetSkippingPunishment()
end
 
F_EndClass = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  F_RingSchoolBell()
end
 
F_StartMorning = function()
  F_UpdateTimeCycle()
end
 
F_EndMorning = function()
  F_UpdateTimeCycle()
end
 
F_StartLunch = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    F_UpdateTimeCycle()
    return
  end
  F_UpdateTimeCycle()
end
 
F_EndLunch = function()
  F_UpdateTimeCycle()
end
 
F_StartAfternoon = function()
  F_UpdateTimeCycle()
end
 
F_EndAfternoon = function()
  F_UpdateTimeCycle()
end
 
F_StartEvening = function()
  F_UpdateTimeCycle()
end
 
F_EndEvening = function()
  F_UpdateTimeCycle()
end
 
F_StartCurfew_SlightlyTired = function()
  F_UpdateTimeCycle()
end
 
F_StartCurfew_Tired = function()
  F_UpdateTimeCycle()
end
 
F_StartCurfew_MoreTired = function()
  F_UpdateTimeCycle()
end
 
F_StartCurfew_TooTired = function()
  F_UpdateTimeCycle()
end
 
F_EndCurfew_TooTired = function()
  F_UpdateTimeCycle()
end
 
F_EndTired = function()
  F_UpdateTimeCycle()
end
 
F_Nothing = function()
end
 
F_ClassWarning = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  local l_23_0 = math.random(1, 2)
end
 
F_UpdateTimeCycle = function()
  if not IsMissionCompleated("1_B") then
    local l_24_0 = GetCurrentDay(false)
    if l_24_0 < 0 or l_24_0 > 2 then
      SetCurrentDay(0)
    end
  end
  F_UpdateCurfew()
end
 
F_UpdateCurfew = function()
  local l_25_0 = shared.gCurfewRules
  if not l_25_0 then
    l_25_0 = F_CurfewDefaultRules
  end
  l_25_0()
end
 
F_CurfewDefaultRules = function()
  local l_26_0 = ClockGet()
  if l_26_0 >= 23 or l_26_0 < 7 then
    shared.gCurfew = true
  else
    shared.gCurfew = false
  end
end
« Last Edit: June 04, 2015, 09:46:44 PM by DaBOSS54320 »

Offline Rambo7

  • "Awesomely Kick-Ass Troll"
  • Full Member
  • ***
  • Posts: 404
  • Gender: Male
  • #ZAMBess
    • View Profile
    • My ModDB Page
Re: Save Data In LUA Scripts
« Reply #1 on: May 23, 2015, 11:14:30 PM »
Boss, did you managed to make the save code work already?
Cause I remember reading Madman comment somewhere that saving in a mission mod is still impossible
So can this code be used for saving my game if I use the arcrace1.lur (a mission mod)?

Offline DaBOSS54320

  • Hero Member
  • ****
  • Posts: 3,398
  • Gender: Female
    • View Profile
Re: Save Data In LUA Scripts
« Reply #2 on: May 24, 2015, 01:40:52 AM »
Sort of... it just seems to save numbers in any one of the 200 slots.

Offline Rambo7

  • "Awesomely Kick-Ass Troll"
  • Full Member
  • ***
  • Posts: 404
  • Gender: Male
  • #ZAMBess
    • View Profile
    • My ModDB Page
Re: Save Data In LUA Scripts
« Reply #3 on: May 24, 2015, 01:57:50 AM »
What do you mean?
Isn't that bully just have 6 slot?
and can I load the game perfectly without the need to play the Arcade Game whenever I load it from the option screen?
« Last Edit: May 24, 2015, 02:00:58 AM by Rambo7 »