|
GOSUB
选译/ kwanz
GOSUB is a command similar to jump and else_jump, but with the added feature of returning back to the part of code where it is executed. Any code between the label and the return command will be executed, and then go back to the normal thread.
GOSUB类似jump和else_jump,但另外带有返回调用位置的功能.在跳转标签和return命令之间的语句会被执行,然后返回.
注意体会return命令的用法
This command is one that I use all the time. It is very convenient and it has a lot of uses. I will give you a few examples how you can use this command efficiently.
You can use GOSUB to check conditions:
例 条件判断- :Begin
- wait 0
- if
- Player.Defined(0)
- jf @Begin
- if and
- 00F3: actor $PLAYER_ACTOR near_actor 15@ radius 20.0 20.0 0 on_foot
- gosub @MoreConditions
- jf @Begin
- wait 250
- jump @Begin
-
- :MoreConditions
- if and
- 0AB0: key_pressed 0x73
- 044B: actor $PLAYER_ACTOR on_foot
- 0457: player $PLAYER_CHAR aiming_at_actor 15@ // If the player is satisfies all these conditions, then continue through script
- 0491: actor $PLAYER_ACTOR has_weapon 46
- 0597: actor $PLAYER_ACTOR crouching
- jf @return_False
- 0485: return_true // This is essential, makes the following condition that the gosub is in (above in main loop) alway return true to satisfy it's part only,
- jump @Return // not the actor near actor part
-
- :return_False
- 059A: return_false // Same as return_true, but opposite; makes the following condition return false
-
- :Return
- return // This is needed after using return_true/false, this makes this thread return back to main loop thread and check if return true/false
复制代码 You can use GOSUB to load Models:
例 加载模型语句段- :Begin
- wait 0
- if
- Player.Defined(0)
- jf @Begin
- 26@ = #LAPD1 // Store an ID/Model to 26@
- gosub @LoadModel
- Actor.StorePos($PLAYER_ACTOR, 3@, 4@, 5@)
- 1@ = Actor.Create(6, 26@, 3@, 4@, 5@) // Creates the actor with the model that is stored in 26@; 2nd parameter 6 is pedtype, which is pedtype for cop
- Actor.RemoveReferences(1@)
- wait 250
- jump @Begin
-
- :LoadModel
- Model.Load(26@) // Loads whatever model is stored in 26@
- wait 0 // Always make sure a wait command is present when looping a condition
- if
- Model.Available(26@) // This loop will repeat until the model is available to use, then will return to normal thread
- jf @LoadModel
- return // Returns back to the normal thread
复制代码 You can use GOSUB to organize your code.
例 程序执行流程组织- :Begin
- wait 0
- if
- Player.Defined(0)
- jf @Begin
- Actor.StorePos($PLAYER_ACTOR, 3@, 4@, 5@)
- 1@ = Actor.Create(4, #MALE01, 3@, 4@, 5@) // #MALE01 never needs to be loaded because it always is loaded
- gosub @SetActorActions
- 0618: assign_actor 1@ to_AS_pack 15@
- 2@ = Actor.Create(4, #MALE01, 3@, 4@, 5@) // #MALE01 never needs to be loaded because it always is loaded
- gosub @SetActorActions
- 0618: assign_actor 2@ to_AS_pack 15@
- 061B: remove_references_to_AS_pack 15@
- Actor.RemoveReferences(1@)
- Actor.RemoveReferences(2@)
- wait 250
- jump @Begin
- :SetActorActions
- 0615: define_AS_pack_begin 15@
- 05D9: AS_actor -1 run_to_actor $PLAYER_ACTOR timelimit -1 stop_within_radius 6.0
- 05C2: AS_actor -1 show_the_finger
- 0616: define_AS_pack_end 15@
- 0643: set_AS_pack 15@ loop 1
- return // Returns back to the normal thread
复制代码 Below is my Ghost Lanterns code. GOSUB was very useful in keeping the code organized and easy to work with. Without GOSUB, my code will be super long and will be hard to troubleshoot. You will see how many times i used the GOSUB command and how it helped in redundant things. The "intro" for this mod was added last, so you will see in the beginning after defining the actor it jumps to the first GOSUB @NONAME_2975, performs the intro, then back to @NONAME_29 to continue the normal thread.
恰当使用GOSUB可以优化代码的结构,让各种判断\排除\处理更加清晰
下面是我的鬼灯笼CLEO源代码- // This file was decompiled using sascm.ini published by Seemann (http://sannybuilder.com/files/SASCM.rar) on 13.10.2007
- {$VERSION 3.1.0027}
- {$CLEO .cs}
- //-------------MAIN---------------
- 0000: NOP
- :NONAME_2
- wait 0
- if
- Player.Defined($PLAYER_ACTOR)
- jf @NONAME_2
- gosub @NONAME_2975
- :NONAME_29
- wait 0
- if
- 0ADC: test_cheat "ONI"
- jf @NONAME_58
- jump @NONAME_374
- :NONAME_58
- wait 0
- if
- 00E1: player 0 pressed_key 6
- jf @NONAME_409
- wait 0
- if and
- $ACTIVE_INTERIOR == 0
- 044B: actor $PLAYER_ACTOR on_foot
- jf @NONAME_374
- gosub @NONAME_439
- if
- 06FF: any_ped_near_actor $PLAYER_ACTOR in_range 12.0
- jf @NONAME_335
- gosub @NONAME_2613
- :NONAME_141
- wait 0
- if
- Player.Defined($PLAYER_ACTOR)
- jf @NONAME_141
- if
- not Actor.Driving($PLAYER_ACTOR)
- jf @NONAME_374
- Actor.SetImmunities($PLAYER_ACTOR, 1, 1, 1, 1, 1)
- Actor.StorePos($PLAYER_ACTOR, 1@, 2@, 3@)
- if
- 0AE1: 0@ = random_actor_near_point 1@ 2@ 3@ in_radius 12.0 find_next 0 pass_deads 1 //IF and SET
- jf @NONAME_409
- :NONAME_240
- wait 0
- if and
- $ACTIVE_INTERIOR == 0
- 044B: actor $PLAYER_ACTOR on_foot
- jf @NONAME_374
- gosub @NONAME_2613
- gosub @NONAME_1526
- 0326: 6@ = create_actor 0@ fire
- Actor.RemoveReferences(0@)
- gosub @NONAME_2613
- wait 0
- 8AE1: not 0@ = random_actor_near_point 1@ 2@ 3@ in_radius 12.0 find_next 1 pass_deads 1 //IF and SET
- jf @NONAME_240
- :NONAME_335
- wait 0
- if
- 86FF: not any_ped_near_actor $PLAYER_ACTOR in_range 12.0
- jf @NONAME_141
- gosub @NONAME_2613
- jump @NONAME_29
- :NONAME_374
- 0ACA: show_text_box "CREATED BY SIXACE"
- gosub @NONAME_2613
- jump @NONAME_2
- :NONAME_409
- wait 0
- if
- 80E1: not player 0 pressed_key 6
- jf @NONAME_58
- 0986: unknown_fires_stuff
- jump @NONAME_29
- :NONAME_439
- 0669: 7@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 1.0 0.0 0.0 flag 1
- 064C: make_particle 7@ visible
- 0669: 8@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -1.0 0.0 0.0 flag 1
- 064C: make_particle 8@ visible
- 0669: 9@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 1.0 0.0 0.7 flag 1
- 064C: make_particle 9@ visible
- 0669: 10@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 1.0 0.0 -0.7 flag 1
- 064C: make_particle 10@ visible
- 0669: 11@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -1.0 0.0 0.7 flag 1
- 064C: make_particle 11@ visible
- 0669: 12@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -1.0 0.0 -0.7 flag 1
- 064C: make_particle 12@ visible
- 0669: 13@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.7 0.7 0.0 flag 1
- 064C: make_particle 13@ visible
- 0669: 14@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.7 -0.7 0.0 flag 1
- 064C: make_particle 14@ visible
- 0669: 15@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.7 0.7 0.7 flag 1
- 064C: make_particle 15@ visible
- 0669: 16@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.7 0.7 -0.7 flag 1
- 064C: make_particle 16@ visible
- 0669: 17@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.7 -0.7 -0.7 flag 1
- 064C: make_particle 17@ visible
- 0669: 18@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.7 -0.7 0.7 flag 1
- 064C: make_particle 18@ visible
- 0669: 19@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -0.7 -0.7 0.0 flag 1
- 064C: make_particle 19@ visible
- 0669: 20@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -0.7 0.7 0.0 flag 1
- 064C: make_particle 20@ visible
- 0669: 21@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -0.7 -0.7 -0.7 flag 1
- 064C: make_particle 21@ visible
- 0669: 22@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -0.7 -0.7 0.7 flag 1
- 064C: make_particle 22@ visible
- 0669: 23@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -0.7 0.7 -0.7 flag 1
- 064C: make_particle 23@ visible
- 0669: 24@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset -0.7 0.7 0.7 flag 1
- 064C: make_particle 24@ visible
- 0669: 25@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.0 1.0 0.0 flag 1
- 064C: make_particle 25@ visible
- 0669: 26@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.0 -1.0 0.0 flag 1
- 064C: make_particle 26@ visible
- 0669: 27@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.0 1.0 0.7 flag 1
- 064C: make_particle 27@ visible
- 0669: 28@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.0 1.0 -0.7 flag 1
- 064C: make_particle 28@ visible
- 0669: 29@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.0 -1.0 0.7 flag 1
- 064C: make_particle 29@ visible
- 0669: 30@ = attach_particle "MOLOTOV_FLAME" to_actor $PLAYER_ACTOR with_offset 0.0 -1.0 -0.7 flag 1
- 064C: make_particle 30@ visible
- wait 500
- return
- :NONAME_1526
- 0669: 7@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 1.0 0.0 0.0 flag 1
- 064C: make_particle 7@ visible
- 0669: 8@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -1.0 0.0 0.0 flag 1
- 064C: make_particle 8@ visible
- 0669: 9@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 1.0 0.0 0.7 flag 1
- 064C: make_particle 9@ visible
- 0669: 10@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 1.0 0.0 -0.7 flag 1
- 064C: make_particle 10@ visible
- 0669: 11@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -1.0 0.0 0.7 flag 1
- 064C: make_particle 11@ visible
- 0669: 12@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -1.0 0.0 -0.7 flag 1
- 064C: make_particle 12@ visible
- 0669: 13@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.7 0.7 0.0 flag 1
- 064C: make_particle 13@ visible
- 0669: 14@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.7 -0.7 0.0 flag 1
- 064C: make_particle 14@ visible
- 0669: 15@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.7 0.7 0.7 flag 1
- 064C: make_particle 15@ visible
- 0669: 16@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.7 0.7 -0.7 flag 1
- 064C: make_particle 16@ visible
- 0669: 17@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.7 -0.7 -0.7 flag 1
- 064C: make_particle 17@ visible
- 0669: 18@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.7 -0.7 0.7 flag 1
- 064C: make_particle 18@ visible
- 0669: 19@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -0.7 -0.7 0.0 flag 1
- 064C: make_particle 19@ visible
- 0669: 20@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -0.7 0.7 0.0 flag 1
- 064C: make_particle 20@ visible
- 0669: 21@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -0.7 -0.7 -0.7 flag 1
- 064C: make_particle 21@ visible
- 0669: 22@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -0.7 -0.7 0.7 flag 1
- 064C: make_particle 22@ visible
- 0669: 23@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -0.7 0.7 -0.7 flag 1
- 064C: make_particle 23@ visible
- 0669: 24@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset -0.7 0.7 0.7 flag 1
- 064C: make_particle 24@ visible
- 0669: 25@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.0 1.0 0.0 flag 1
- 064C: make_particle 25@ visible
- 0669: 26@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.0 -1.0 0.0 flag 1
- 064C: make_particle 26@ visible
- 0669: 27@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.0 1.0 0.7 flag 1
- 064C: make_particle 27@ visible
- 0669: 28@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.0 1.0 -0.7 flag 1
- 064C: make_particle 28@ visible
- 0669: 29@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.0 -1.0 0.7 flag 1
- 064C: make_particle 29@ visible
- 0669: 30@ = attach_particle "MOLOTOV_FLAME" to_actor 0@ with_offset 0.0 -1.0 -0.7 flag 1
- 064C: make_particle 30@ visible
- wait 800
- return
- :NONAME_2613
- 064E: stop_particle 7@
- 064E: stop_particle 8@
- 064E: stop_particle 9@
- 064E: stop_particle 10@
- 064E: stop_particle 11@
- 064E: stop_particle 12@
- 064E: stop_particle 13@
- 064E: stop_particle 14@
- 064E: stop_particle 15@
- 064E: stop_particle 16@
- 064E: stop_particle 17@
- 064E: stop_particle 18@
- 064E: stop_particle 19@
- 064E: stop_particle 20@
- 064E: stop_particle 21@
- 064E: stop_particle 22@
- 064E: stop_particle 23@
- 064E: stop_particle 24@
- 064E: stop_particle 25@
- 064E: stop_particle 26@
- 064E: stop_particle 27@
- 064E: stop_particle 28@
- 064E: stop_particle 29@
- 064E: stop_particle 30@
- 0650: destroy_particle 7@
- 0650: destroy_particle 8@
- 0650: destroy_particle 9@
- 0650: destroy_particle 10@
- 0650: destroy_particle 11@
- 0650: destroy_particle 12@
- 0650: destroy_particle 13@
- 0650: destroy_particle 14@
- 0650: destroy_particle 15@
- 0650: destroy_particle 16@
- 0650: destroy_particle 17@
- 0650: destroy_particle 18@
- 0650: destroy_particle 19@
- 0650: destroy_particle 20@
- 0650: destroy_particle 21@
- 0650: destroy_particle 22@
- 0650: destroy_particle 23@
- 0650: destroy_particle 24@
- 0650: destroy_particle 25@
- 0650: destroy_particle 26@
- 0650: destroy_particle 27@
- 0650: destroy_particle 28@
- 0650: destroy_particle 29@
- 0650: destroy_particle 30@
- 064F: remove_references_to_particle 7@
- 064F: remove_references_to_particle 8@
- 064F: remove_references_to_particle 9@
- 064F: remove_references_to_particle 10@
- 064F: remove_references_to_particle 11@
- 064F: remove_references_to_particle 12@
- 064F: remove_references_to_particle 13@
- 064F: remove_references_to_particle 14@
- 064F: remove_references_to_particle 15@
- 064F: remove_references_to_particle 16@
- 064F: remove_references_to_particle 17@
- 064F: remove_references_to_particle 18@
- 064F: remove_references_to_particle 19@
- 064F: remove_references_to_particle 20@
- 064F: remove_references_to_particle 21@
- 064F: remove_references_to_particle 22@
- 064F: remove_references_to_particle 23@
- 064F: remove_references_to_particle 24@
- 064F: remove_references_to_particle 25@
- 064F: remove_references_to_particle 26@
- 064F: remove_references_to_particle 27@
- 064F: remove_references_to_particle 28@
- 064F: remove_references_to_particle 29@
- 064F: remove_references_to_particle 30@
- return
- :NONAME_2975
- wait 0
- if and
- 0ADC: test_cheat "ONI"
- Player.Defined($PLAYER_CHAR)
- jf @NONAME_2
- 04ED: load_animation "KACI"
- Audiostream.Load(1@, "CLEO\MP3\ONIDOUROU.MP3")
- 038B: load_requested_models
- 0489: set_actor $PLAYER_ACTOR muted 1
- Actor.LockInCurrentPosition($PLAYER_ACTOR) = True
- 0605: actor $PLAYER_ACTOR perform_animation_sequence "THRW_BARL_THRW" IFP_file "AIRPORT" 4.0 loop 0 1 1 1 time -1 // versionA
- wait 300
- Audiostream.PerformAction(1@, PLAY)
- 066A: 2@ = attach_particle "FIRE_BIKE" to_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 flag 1
- 0883: attach_particle 2@ to_actor $PLAYER_ACTOR mode 0
- 064C: make_particle 2@ visible
- wait 2500
- Audiostream.PerformAction(1@, STOP)
- 04C4: store_coords_to 3@ 4@ 5@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
- 0948: create_explosion_at 3@ 4@ 5@ type 6 camera_shake 2.5
- 0650: destroy_particle 2@
- 064F: remove_references_to_particle 2@
- gosub @NONAME_439
- 0489: set_actor $PLAYER_ACTOR muted 0
- 0687: clear_actor $PLAYER_ACTOR task
- 04EF: release_animation "KACI"
- Camera.Restore
- Audiostream.Release(1@)
- Actor.LockInCurrentPosition($PLAYER_ACTOR) = False
- wait 2000
- gosub @NONAME_2613
- return
复制代码 |
评分
-
查看全部评分
|