Hello,Today i will explain what GOSUB means
GOSUB , wiki:
ok so here is a simple script:
now to add the GOSUB thing we change the script to this way:
NOW gosub code is this:
first of all we add "GOSUB [member=42621]Sub[/member]" in the main script (the label START) , capitals letters don't effect the code.
since GTA read from up to down , first label will be read is ":START" and after it ended it will jump again at start because we added " jump @START" in the end
so ":sub" won't be read unless it got called in the main flow of label "START"
1)so sub is like normal label , start with " : " followed by letters or numbers
2)then we add wait 0 , this is not needed , many scripters don't add wait 0 , but i prefer to add it to avoid further lags ..etc
3) now we added our code that will run when the flow in the main loop reach the gosub [member=42621]Sub[/member] code
4) we always end the subs with return
PS: subs don't get end with "jump @" and not contain"jf @"
instead it always end with "RETURN"
subs are really easy , but you can understand better if you reviewed the codes and how you call the sub and go to it then run the codes under it then return back to where you called the sub and continue the script
subs are usually used for calculating things and/or checking things then back to the main script , so subs are VERY VERY useful in many ways
here is a SCRIPT that will save then teleport you to the saved position
try to understand it , if you can't or stuck at some point please comment so i can explain it for you
here you go:
what i gave you now in codes is a very little thing that subs cover .
because subs can be used in millions ways ...
thanks for following my tutorials.
if i helped you please hit the thanks button and the little heart(rep.) under my name so you can make me more trusted for users so they can reach me easily.
GOSUB , wiki:
GOSUB is a command in many versions of the BASIC computer programming language. A GOSUB statement jumps to a line elsewhere in the program. That line and the following lines up to a RETURN are used as a simple kind of a subroutine without (sometimes with) parameters or local variables.
ok so here is a simple script:
Code:
{$CLEO}
0000: NOP
:START
wait 0
if and
056D: actor $PLAYER_ACTOR defined //check if actor is defined else jump to START to loop again
key_down 49 //if key 1 pressed run the code below , else jump @start again to loop
jf @START
02AB: set_actor $PLAYER_ACTOR immunities BP 1 FP 1 EP 1 CP 1 MP 1 //this will get you full immunitie (god mode)
0AD1: show_formatted_text_highpriority "GOD MODE ACTIVATED " time 2000 0x0AD1
jump @START
now to add the GOSUB thing we change the script to this way:
Code:
{$CLEO}
0000: NOP
:START
wait 0
if and
056D: actor $PLAYER_ACTOR defined //check if actor is defined else jump to START to loop again
key_down 49 //if key 1 pressed run the code below , else jump @start again to loop
jf @START
gosub @set_godmode_on
0AD1: show_formatted_text_highpriority "GOD MODE ACTIVATED " time 2000 0x0AD1
jump @START
:set_godmode_on // i will explain this below
wait 0 //this is optional , some people don't add wait , but i prefer to add it
02AB: set_actor PLAYER_ACTOR immunities BP 1 FP 1 EP 1 CP 1 MP 1 //this will get you full immunitie (god mode)
return //this will return to the loop flow in label START
NOW gosub code is this:
Code:
gosub [member=42621]Sub[/member] //this should be add in the main script (in our case it is :START)
:sub // i will explain this below
wait 0 //this is optional , some people don't add wait , but i prefer to add it
02AB: set_actor PLAYER_ACTOR immunities BP 1 FP 1 EP 1 CP 1 MP 1 //this will get you full immunitie (god mode)
return //this will return to the loop flow in label START
first of all we add "GOSUB [member=42621]Sub[/member]" in the main script (the label START) , capitals letters don't effect the code.
since GTA read from up to down , first label will be read is ":START" and after it ended it will jump again at start because we added " jump @START" in the end
so ":sub" won't be read unless it got called in the main flow of label "START"
1)so sub is like normal label , start with " : " followed by letters or numbers
2)then we add wait 0 , this is not needed , many scripters don't add wait 0 , but i prefer to add it to avoid further lags ..etc
3) now we added our code that will run when the flow in the main loop reach the gosub [member=42621]Sub[/member] code
4) we always end the subs with return
PS: subs don't get end with "jump @" and not contain"jf @"
instead it always end with "RETURN"
subs are really easy , but you can understand better if you reviewed the codes and how you call the sub and go to it then run the codes under it then return back to where you called the sub and continue the script
subs are usually used for calculating things and/or checking things then back to the main script , so subs are VERY VERY useful in many ways
here is a SCRIPT that will save then teleport you to the saved position
try to understand it , if you can't or stuck at some point please comment so i can explain it for you
here you go:
Code:
{$CLEO}
0000: NOP
:FIRST
wait 0
if and
056D: actor $PLAYER_ACTOR defined
0AB0: key_pressed 50 //2
jf @FIRST
gosub @store_actor_position //this will call the sub
0AD1: show_formatted_text_highpriority "Your Position SAVED." time 2000 0x0AD1
jump @SECOND
// in case you ask in the first step we didn't add jf @SECOND , becouse second will put the actor at the coords we got from "FIRST" label
//so we can put actor in 1@ 2@ 3@ if we jumped to the second label becouse it is not defined , so we have to run through label "FIRST"
//to store the position , else it will put the actor at 0.0 0.0 0.0 becouse 1@ 2@ 3@ is not defined
:SECOND
wait 0
if
0AB0: key_pressed 51 //3
then
gosub [member=31703]teleport[/member]
0AD1: show_formatted_text_highpriority "You Back to your Position." time 2000 0x0AD1
end
jump @FIRST
:store_actor_position //our sub
wait 0
00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@
return
:TELEPORT
wait 0
00A1: put_actor $PLAYER_ACTOR at 1@ 2@ 3@
return
what i gave you now in codes is a very little thing that subs cover .
because subs can be used in millions ways ...
thanks for following my tutorials.
if i helped you please hit the thanks button and the little heart(rep.) under my name so you can make me more trusted for users so they can reach me easily.