Quantcast

Jump to content

» «
Photo

Newbie coding problems.

9 replies to this topic
TheGreg
  • TheGreg

    Check yourself before you Shrek yourself

  • Members
  • Joined: 17 Jun 2014
  • Italy

#1

Posted 18 June 2014 - 05:57 PM

Hey, i got into coding just two days ago and today i wanted to write my own little code. It's not anything fancy, it's just a very simple code that's supposed to toggle thermal vision when holding the backspace button. The problem is: when i start GTA, the code doesn't quite work how it's supposed to. Once i press the backspace button, the thermal vision effect stays on for quite some time, even though i'm not pressing it. Then the effect randomly goes away. I tried correcting the code, looking for errors, but i couldn't find any. Sometimes it would work, sometimes it would just crash the game or freeze it. So i thought that maybe you guys could tell me what i did wrong. Here's the code. 
 

 

{$CLEO .cs}  

:Shekels
03A4: name_thread "SHEKELS"
 
:Shekels_1
0001: wait 0 ms
if
0256: player$PLAYER_CHAR defined
004D: jump_if_false @Shekels_1
if
0AB0: key_pressed 8     
004D: jump_if_false @Shekels_1
08B2: toggle_thermal_vision 1
 
:Shekels_2
0001: wait 0 ms
if
0256: player$PLAYER_CHAR defined
004D: jump_if_false @Shekels_2
if
8AB0: not key_pressed 8
004D: jump_if_false @Shekels_1
08B2: toggle_thermal_vision 0  
004E: end_thread                

 


ZAZ
  • ZAZ

    Kernlochbohrer

  • Feroci
  • Joined: 10 Jan 2005
  • European-Union

#2

Posted 18 June 2014 - 07:00 PM

there's a mistake in your script
 
the Global Var: $PLAYER_CHAR must be separated from other charackters
 
your code line:
 
0256: player$PLAYER_CHAR defined
 
there must be space between the description "player" and the Global Var "$PLAYER_CHAR"
 
0256:   player $PLAYER_CHAR defined

then play around with wait codes, let the script wait for some seconds after the change
08B2: toggle_thermal_vision 1
wait 3000
and change the keypress check in 2.Loop
{$CLEO .cs}  
:Shekels
03A4: name_thread "SHEKELS"
 
:Shekels_1// 1. Loop
0001: wait 0 ms
if
0256: player $PLAYER_CHAR defined
004D: jump_if_false @Shekels_1
if
0AB0: key_pressed 8     
004D: jump_if_false @Shekels_1
08B2: toggle_thermal_vision 1

// play around with wait codes after the change
wait 3000
 
:Shekels_2// 2. Loop
0001: wait 0 ms
if
0256: player $PLAYER_CHAR defined
004D: jump_if_false @Shekels_2
if
0AB0: key_pressed 8// change it to normal keypress
004D: jump_if_false @Shekels_2// <-- let it jump to 2. Loop
08B2: toggle_thermal_vision 0  
004E: end_thread

In45do
  • In45do

    Newbz

  • Members
  • Joined: 15 Jan 2012
  • Indonesia

#3

Posted 19 June 2014 - 05:22 AM

Isn't it supposed to be 0A93: end_custom_thread instead of 004E: end_thread ?


TheGreg
  • TheGreg

    Check yourself before you Shrek yourself

  • Members
  • Joined: 17 Jun 2014
  • Italy

#4

Posted 19 June 2014 - 09:51 AM

Isn't it supposed to be 0A93: end_custom_thread instead of 004E: end_thread ?

Well, since i'm a newbie at coding, i'm not really able to tell the difference between them. I tried using both, but with the 0A93 opcode it would crash the game when i press the key. But then again, i think it's because of some error in the code that makes the game crash if i press the backspace button and any other button at the same time. I'm not really sure, i'll try to add a wait code to the script to see if it'll work.


In45do
  • In45do

    Newbz

  • Members
  • Joined: 15 Jan 2012
  • Indonesia

#5

Posted 19 June 2014 - 11:10 AM

I was thinking the same as you did. But I follow what ZAZ suggest on his tutorial guide. (GTA SA version) ;) :^:


TheGreg
  • TheGreg

    Check yourself before you Shrek yourself

  • Members
  • Joined: 17 Jun 2014
  • Italy

#6

Posted 19 June 2014 - 11:37 AM Edited by TheGreg, 19 June 2014 - 11:38 AM.

Alright, i did as Zaz said and changed the keypress code to a normal one (00E1), but when i start the game, the code doesn't work at all. By the way, is there any difference between the 0AB0 and the 00E1 opcodes? 

 

{$CLEO .cs}

:Shekels
03A4: name_thread "Shekels"
 
:Shekels_1
0001: wait 0 ms
if
0256: player $PLAYER_CHAR defined
004D: jump_if_false @Shekels_1
if
00E1: player 0 pressed_key 8
004D: jump_if_false @Shekels_1
08B2: enable_thermal_vision 1
wait 2000 ms
 
:Shekels_2
0001: wait 0 ms
if
0256: player $PLAYER_CHAR defined
004D: jump_if_false @Shekels_2
if
80E1: not player 0 pressed_key 8
004D: jump_if_false @Shekels_2
08B2: enable_thermal_vision 0
0A93: end_custom_thread

In45do
  • In45do

    Newbz

  • Members
  • Joined: 15 Jan 2012
  • Indonesia

#7

Posted 19 June 2014 - 11:57 AM

Known the difference here.


Ify24
  • Ify24

    0x00000000 --> invisible

  • Members
  • Joined: 17 Aug 2011

#8

Posted 19 June 2014 - 12:13 PM Edited by Silent, 19 June 2014 - 12:59 PM.

{$CLEO .cs}
thread "Shekels" 

:Shekels_11
wait 0 
if and
   Player.Defined($PLAYER_CHAR)
0AB0:   key_pressed 0x8
jf @Shekels_11 
08B2: enable_thermal_vision 1 
wait 1500 ms
:Shekels_46
wait 0 
if and
   Player.Defined($PLAYER_CHAR)
0AB0:   key_pressed 0x8
jf @Shekels_46 
08B2: enable_thermal_vision 0 
wait 1500 ms
jump @Shekels_11 

Here you go :)

Silent
  • Silent

    Moderating Cookie Monster

  • Feroci
  • Joined: 01 Feb 2010
  • Poland
  • Contribution Award [Mods]
    Best Script/Plugin 2014 [SilentPatch]
    Most Respected 2014
    Most Helpful [Mods] 2014
    Most Helpful [GTA] 2013
    Most Helpful [Mods] 2013
    Most Talented [Modding] 2013
    Best Map 2013 [ViceCityStories PC Edition]
    Best Vehicle 2013 [III Aircraft]
    Most Helpful [Mods] 2012
    Modder of the Year 2012

#9

Posted 19 June 2014 - 01:00 PM

^ I've been rude enough to edit the previous post, removing one useless thing from the script.

ZAZ
  • ZAZ

    Kernlochbohrer

  • Feroci
  • Joined: 10 Jan 2005
  • European-Union

#10

Posted 20 June 2014 - 02:32 AM

sorry, i didn't notice the wrong end_thread, 0A93: end_custom_thread is right.

Ify24 gave a propper script and changed end_thread with a jump back to script beginn
This is your next step: jump back to script beginn instead end_thread to let the script repeating instead ending

BTW. Ify24 recompiled the script with option "no opcodes"
this will change the opcode syntax into classes syntax
 

with opcode
0256: player $PLAYER_CHAR defined
as classes
Player.Defined($PLAYER_CHAR)

have a look to Sannybuilder options and also to Sannybuilder > Help > Coding > Classes

 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users