Quantcast

Jump to content

» «
Photo

Writing variable value in a txt file

5 replies to this topic
Ify24
  • Ify24

    0x00000000 --> invisible

  • Members
  • Joined: 17 Aug 2011

#1

Posted 14 August 2014 - 06:13 PM

So I have a question, when I get players active interior and store it to 

a variable 5@, can I then write the value of a 5@ in a file somewhere like value.txt ?


Ify24
  • Ify24

    0x00000000 --> invisible

  • Members
  • Joined: 17 Aug 2011

#2

Posted 15 August 2014 - 05:28 PM Edited by Ify24, 15 August 2014 - 05:35 PM.

Okay I figured it out but now I have a problem, here is the code:

{$CLEO .cs}
thread "DRU"
0A95: enable_thread_saving

0A9A: $hFILE = openfile "CLEO\VARR.ini" mode "rt+" 
0AF0: 0@ = get_int_from_ini_file "CLEO\VARR.ini" section "Varr" key "int"

:Check_1
wait 0 ms
077E: get_active_interior_to $ACTIVE_INTERIOR
if
$ACTIVE_INTERIOR == 0
jf @Check_1

Model.Load(#WMYDRUG)
038B: load_requested_models

:Check_2
wait 0 ms
if
Model.Available(#WMYDRUG)
jf @Check_2

Actor.Create($DEALER, Dealer, #WMYDRUG, -490.372, 1504.965, 8.688)
Actor.Angle($DEALER) = 121.0

:Check_3
wait 0 ms
if
00F3:   actor $PLAYER_ACTOR near_actor $DEALER radius 1.8 1.8 sphere 0 on_foot
jf @Check_6
jump @NEAR_Truee

:Check_6
wait 0 ms
if
0AB0:   key_pressed 0x49
jf @Check_3
0ACE: show_formatted_text_box "You have %d g." 0@
jump @Check_3

:NEAR_Truee
Player.CanMove($PLAYER_CHAR, False)
0ACE: show_formatted_text_box "Would you like to buy some weed ? (Y or N?)" 0x0ACE

:Check_4
wait 0 ms
if
0AB0:   key_pressed 0x59
jf @Check_5
jump @BUY

:Check_5
wait 0 ms
if
0AB0:   key_pressed 0x4E
jf @Check_4
0ACE: show_formatted_text_box "Come back any time if you change your mind." 0x0ACE
Player.CanMove($PLAYER_CHAR, True)
wait 3500 ms
jump @Check_3

:BUY
Player.CanMove($PLAYER_CHAR, True)
0ACE: show_formatted_text_box "This is %.4X opcode" 0x0ACE
wait 3500 ms
0@ += 1
0AF1: write_int 0@ to_ini_file "CLEO\VARR.ini" section "Varr" key "int"
jump @Check_3

So everything worked pretty well until I saved my game.

Code changed int value in file and read it and gave outpout ingame everything great.

Then when I try to load my game it would crash, SA Limit Adjuster: GTA:SA Crashed, Last File Loaded:DRU.cs bla bla (Also I have GTA United 1.1 instaled but I think that doesn't have anything much to do with crashes)

 

So can somebody help me?

 

EDIT: Also, when I start a new game the script works pretty good, but then again if I save the game and then load it it crashes :/


Ify24
  • Ify24

    0x00000000 --> invisible

  • Members
  • Joined: 17 Aug 2011

#3

Posted 15 August 2014 - 06:01 PM

Oh I figured it out I don't need 0a95 opcode becouse I don't need to save variable value

becouse it reads it from a file but I thought that idk, nevermind xD


Ify24
  • Ify24

    0x00000000 --> invisible

  • Members
  • Joined: 17 Aug 2011

#4

Posted 15 August 2014 - 06:32 PM

Now I have a problem, I don't need to save my game but game will know how much g's but now

I can buy weed, not save my game, then load a game again, my money will return and the weed will stay,

can someone help me with this ?


Ify24
  • Ify24

    0x00000000 --> invisible

  • Members
  • Joined: 17 Aug 2011

#5

Posted 15 August 2014 - 08:19 PM Edited by Ify24, 15 August 2014 - 08:34 PM.

Sorry guys for5 posts in a row, but It doesn't work, I don't know what the f is going on, here is the script:

{$CLEO .cs}
thread "DRU"

:Check_1
wait 0 ms
077E: get_active_interior_to $ACTIVE_INTERIOR
if
$ACTIVE_INTERIOR == 0
then
jump @START
else
jump @Check_0
end

:Check_0
wait 0 ms
if
0AB0: key_pressed 0x49
then
0A9A: $hFILE = openfile "CLEO\VARR.ini" mode "rt+"
0AF0: 0@ = get_int_from_ini_file "CLEO\VARR.ini" section "Varr" key "int"
0ACE: show_formatted_text_box "You have %d g." 0@
0A9B: closefile $hFILE
wait 1000 ms
end
jump @Check_1

:START
Model.Load(#WMYDRUG)
038B: load_requested_models

:Check_2
wait 0 ms
if
Model.Available(#WMYDRUG)
jf @Check_2

Actor.Create($DEALER, Dealer, #WMYDRUG, -490.372, 1504.965, 8.688)
Actor.Angle($DEALER) = 121.0

:Check_3
wait 0 ms
if
00F3: actor $PLAYER_ACTOR near_actor $DEALER radius 1.8 1.8 sphere 0 on_foot
jf @Check_6
jump @NEAR_Truee

:Check_6
wait 0 ms
if
0AB0: key_pressed 0x49
jf @Check_3
0A9A: $hFILE = openfile "CLEO\VARR.ini" mode "rt+"
0AF0: 0@ = get_int_from_ini_file "CLEO\VARR.ini" section "Varr" key "int"
0ACE: show_formatted_text_box "You have %d g." 0@
0A9B: closefile $hFILE
wait 1000 ms
jump @Check_3

:NEAR_Truee
Player.CanMove($PLAYER_CHAR, False)
0ACE: show_formatted_text_box "Would you like to buy some weed, 20$ for a G?(Y or N?)" 0x0ACE

:Check_4
wait 0 ms
if
0AB0: key_pressed 0x59
jf @Check_5
jump @BUY

:Check_5
wait 0 ms
if
0AB0: key_pressed 0x4E
jf @Check_4
0ACE: show_formatted_text_box "Come back any time if you need the stuff." 0x0ACE
Player.CanMove($PLAYER_CHAR, True)
wait 3500 ms
jump @Check_3

:BUY
0ACE: show_formatted_text_box "Would you like some more (Y or N)?" 0x0ACE
0109: player $PLAYER_CHAR money += -20
0A9A: $hFILE = openfile "CLEO\VARR.ini" mode "rt+"
0@ += 1
0AF1: write_int 0@ to_ini_file "CLEO\VARR.ini" section "Varr" key "int"
0A9B: closefile $hFILE
wait 500 ms
jump @Check_4 

Everything works great but as I said when I save a game after buying some "weed" and then I try to load it game chrashes after loading screen

 

EDIT: Okay I now really figured it out, this script works very good on unmodded GTA:SA (With changed actor coords ofc) I can save my game after playing with script and then load it, tried it a few times all good, no problem.

But, for some reason it doesn't work well with GTA United 1.1, well it works but as I said a few times now, it chrashes when I play a game with a script, then save, and then load, the crash happens right after load screen appears and SA Limit Adjuster says that the problem is DRU.cs, but to unmodded GTA:SA, it really isn't, why is that so, I don't know. Hmmmm....


jayd00
  • jayd00

    Rat

  • Members
  • Joined: 24 May 2008

#6

Posted 19 August 2014 - 03:49 AM

uhm :/ test this;

{$CLEO}
thread "DRU"

:begin_code
repeat 
wait 0
until  0AB0: key_pressed 0x49

while true
077E: get_active_interior_to $ACTIVE_INTERIOR
if  $ACTIVE_INTERIOR == 0
then
    break   // goto @START
end

if  0AB0: key_pressed 0x49
then
    0AF0: 0@ = get_int_from_ini_file "CLEO\VARR.ini" section "Varr" key "int"
    0ACE: show_formatted_text_box "You have %d g." 0@
    wait 1000
end
 wait 0
end


:START
Model.Load(#WMYDRUG)
038B: load_requested_models
repeat
 wait 0
until Model.Available(#WMYDRUG)


Actor.Create($DEALER, Dealer, #WMYDRUG, -490.372, 1504.965, 8.688)
Actor.Angle($DEALER) = 121.0

:check_in_sphere
while true
if
00F3: actor $PLAYER_ACTOR near_actor $DEALER radius 1.8 1.8 sphere 0 on_foot
then
    break  // jump @NEAR_Truee
end

if
0AB0: key_pressed 0x49
then
    0AF0: 0@ = get_int_from_ini_file "CLEO\VARR.ini" section "Varr" key "int"
    0ACE: show_formatted_text_box "You have %d g." 0@
    wait 1000
end
 wait 0
end

:NEAR_Truee
Player.CanMove($PLAYER_CHAR, False)
0ACE: show_formatted_text_box "Would you like to buy some weed, 20$ for a G?(Y or N?)"

while true
if
0AB0: key_pressed 0x59
then 
    break // jump @BUY
end
if
0AB0: key_pressed 0x4E
then
    0ACE: show_formatted_text_box "Come back any time if you need the stuff."
    Player.CanMove($PLAYER_CHAR, True)
    wait 3500
    goto @check_in_sphere
end
 wait 0
end

:BUY
0109: player $PLAYER_CHAR money += -20
0AF0: 0@ = get_int_from_ini_file "CLEO\VARR.ini" section "Varr" key "int"     /// get value
0AB1: call_scm_func @IncreaseValue 1 actual_valuei 0@ updated_valuei 8@
0AF1: write_int 8@ to_ini_file "CLEO\VARR.ini" section "Varr" key "int"      ///  update value

while true
0ACE: show_formatted_text_box "Would you like some more (Y or N)?"
if  00E1:   player 0 pressed_key 11 // conversation - yes
then
    goto @NEAR_Truee
end
if  00E1:   player 0 pressed_key 10 // conversation - no
then
    0ACE: show_formatted_text_box "Come back any time if you need the stuff."
    Player.CanMove($PLAYER_CHAR, True)
    wait 1500
    break
end
 wait 0
end
goto @check_in_sphere

:IncreaseValue
var
0@: Integer
8@: Integer
end
8@ = 0@
8@ += 1  // Increase value
0AB2: ret 1 8@


/*
functions included;

0AB1: call_scm_func @IncreaseValue 1 actual_valuei 0@ updated_value 8@
0AB1: call_scm_func @DecreaseValue 1 actual_valuei 0@ updated_value 8@

:IncreaseValue
var
0@: Integer
8@: Integer
end
8@ = 0@
8@ += 1  // Increase value
0AB2: ret 1 8@

:DecreaseValue
var
0@: Integer
8@: Integer
end
8@ = 0@
8@ += -1  // Decrease value
0AB2: ret 1 8@

*/

should work

 

 

Not tested.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users