Jump to content

[SA] Cleo. Problem with an if statement(?)


Nohet

Recommended Posts

I have a problem with this script. I don't know if it's a problem with an if statement. The script doesn't spawn any actors.

 

{$cleo .cs}

0000:

if and
    Player.Defined($PLAYER_CHAR)
    Player.Controllable($PLAYER_CHAR)
jf @label

model.load(#ballas1)
model.load(#AK47)
model.load(#SILENCED)
model.load(#TEC9)
model.load(#MP5LNG)

038B: load_requested_models

0ADF: add_dynamic_GXT_entry '_SPAWN1' your_text "Ballas Spawned!"
0ADF: add_dynamic_GXT_entry '_SPAWN2' your_text "Ballas with weapons spawned!"

:label
while true     
     wait 10000
     actor.RemoveReferences(4@)
     actor.DestroyInstantly(4@)
         
     actor.RemoveReferences(5@)
     actor.DestroyInstantly(5@)
         
     actor.RemoveReferences(6@)
     actor.DestroyInstantly(6@) 
                  
     actor.RemoveReferences(7@)
     actor.DestroyInstantly(7@)
                  
     actor.RemoveReferences(8@)
     actor.DestroyInstantly(8@)
     
     0099: $8224 = random_int_in_ranges_0_to_1
     
     if
        $8224 == 0
     then
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 1.0 2.0 -1.0
        4@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 2.0 2.0 -1.0
        5@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 3.0 2.0 -1.0
        6@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 4.0 2.0 -1.0
        7@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         
        Actor.GiveWeaponAndAmmo(4@, WeaponType.Ak47, 100) 
        Actor.GiveWeaponAndAmmo(5@, WeaponType.PistolSilenced, 100)  
        Actor.GiveWeaponAndAmmo(6@, WeaponType.Tec9, 100) 
        Actor.GiveWeaponAndAmmo(7@, WeaponType.Mp5, 100) 
         
        02E2: set_actor 4@ weapon_accuracy_to 5
        02E2: set_actor 5@ weapon_accuracy_to 5  
        02E2: set_actor 6@ weapon_accuracy_to 5
        02E2: set_actor 7@ weapon_accuracy_to 5

         
        00BA: show_text_styled GXT '_SPAWN2' time 2300 style 1  
         
        07A5: AS_actor 4@ attack_actor $PLAYER_ACTOR time 9999999999999
        07A5: AS_actor 5@ attack_actor $PLAYER_ACTOR time 9999999999999
         
        07A5: AS_actor 6@ attack_actor $PLAYER_ACTOR time 9999999999999
        07A5: AS_actor 7@ attack_actor $PLAYER_ACTOR time 9999999999999
    end
    if
        $8224 == 1
    then
                 04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 1.0 2.0 -1.0
         4@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 2.0 2.0 -1.0
         5@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 3.0 2.0 -1.0
         6@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 4.0 2.0 -1.0
         7@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 5.0 2.0 -1.0
         8@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
                  
         
         00BA: show_text_styled GXT '_SPAWN1' time 2300 style 1  
         
         07A5: AS_actor 4@ attack_actor $PLAYER_ACTOR time 9999999999999
         07A5: AS_actor 5@ attack_actor $PLAYER_ACTOR time 9999999999999
         
         07A5: AS_actor 6@ attack_actor $PLAYER_ACTOR time 9999999999999
         07A5: AS_actor 7@ attack_actor $PLAYER_ACTOR time 9999999999999
         
         07A5: AS_actor 8@ attack_actor $PLAYER_ACTOR time 9999999999999
  end   
     goto @label
end

Model.Destroy(#BALLAS1)  
Model.Destroy(#AK47)
Model.Destroy(#SILENCED)
Model.Destroy(#TEC9)
Model.Destroy(#MP5LNG)  

 

Edited by Nohet
Link to comment
Share on other sites

{$cleo .cs}

0000:
while true
if and
    Player.Defined($PLAYER_CHAR)
    Player.Controllable($PLAYER_CHAR)
jf  continue

model.load(#ballas1)
model.load(#AK47)
model.load(#SILENCED)
model.load(#TEC9)
model.load(#MP5LNG)

038B: load_requested_models

0ADF: add_dynamic_GXT_entry '_SPAWN1' your_text "Ballas Spawned!"
0ADF: add_dynamic_GXT_entry '_SPAWN2' your_text "Ballas with weapons spawned!"

:label
while true     
     wait 10000
     //why you use here ? waiting if so then dont use that 0099: $8224 = random_int_in_ranges_0_to_1 or 0209: 9@ = random_int_in_ranges 0 5 make no sense
     actor.RemoveReferences(4@)
     actor.DestroyInstantly(4@)
         
     actor.RemoveReferences(5@)
     actor.DestroyInstantly(5@)
         
     actor.RemoveReferences(6@)
     actor.DestroyInstantly(6@) 
                  
     actor.RemoveReferences(7@)
     actor.DestroyInstantly(7@)
                  
     actor.RemoveReferences(8@)
     actor.DestroyInstantly(8@)
//0209: 9@ = random_int_in_ranges 0 5  //idk why you use this but ok here the thing you selsect 0 to   then there is chance 2 more often ok if you choose 0 to 1 nd you looking for 0 its not going to happen
     
    // 0099: $8224 = random_int_in_ranges_0_to_1
     
    // if
     //   9@ == 2
     //then
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 1.0 2.0 -1.0
        4@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 2.0 2.0 -1.0
        5@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 3.0 2.0 -1.0
        6@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 4.0 2.0 -1.0
        7@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
{         
         
        Actor.GiveWeaponAndAmmo(4@, WeaponType.Ak47, 100) 
        Actor.GiveWeaponAndAmmo(5@, WeaponType.PistolSilenced, 100)  
        Actor.GiveWeaponAndAmmo(6@, WeaponType.Tec9, 100) 
        Actor.GiveWeaponAndAmmo(7@, WeaponType.Mp5, 100) 
}        
01B2: give_actor 4@ weapon 31 ammo 100 // Load the weapon model before using this
01B2: give_actor 5@ weapon 23 ammo 100 // Load the weapon model before using this
01B2: give_actor 6@ weapon 32 ammo 100 // Load the weapon model before using this
01B2: give_actor 7@ weapon 29 ammo 100 // Load the weapon model before using this
         
        02E2: set_actor 4@ weapon_accuracy_to 5
        02E2: set_actor 5@ weapon_accuracy_to 5  
        02E2: set_actor 6@ weapon_accuracy_to 5
        02E2: set_actor 7@ weapon_accuracy_to 5

         
        00BA: show_text_styled GXT '_SPAWN2' time 2300 style 1  
         
        07A5: AS_actor 4@ attack_actor $PLAYER_ACTOR time 9999999999999
        07A5: AS_actor 5@ attack_actor $PLAYER_ACTOR time 9999999999999
         
        07A5: AS_actor 6@ attack_actor $PLAYER_ACTOR time 9999999999999
        07A5: AS_actor 7@ attack_actor $PLAYER_ACTOR time 9999999999999
    //end
 //   if
     //   $8224 == 1
 //   then
                 04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 1.0 2.0 -1.0
         4@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 2.0 2.0 -1.0
         5@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 3.0 2.0 -1.0
         6@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 4.0 2.0 -1.0
         7@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 5.0 2.0 -1.0
         8@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
                  
         
         00BA: show_text_styled GXT '_SPAWN1' time 2300 style 1  
         
         07A5: AS_actor 4@ attack_actor $PLAYER_ACTOR time 9999999999999
         07A5: AS_actor 5@ attack_actor $PLAYER_ACTOR time 9999999999999
         
         07A5: AS_actor 6@ attack_actor $PLAYER_ACTOR time 9999999999999
         07A5: AS_actor 7@ attack_actor $PLAYER_ACTOR time 9999999999999
         
         07A5: AS_actor 8@ attack_actor $PLAYER_ACTOR time 9999999999999
         Model.Destroy(#BALLAS1)  
Model.Destroy(#AK47)
Model.Destroy(#SILENCED)
Model.Destroy(#TEC9)
Model.Destroy(#MP5LNG)  
  end   
end
 

Edited by Strs
forgot about that release to put in script :)
Link to comment
Share on other sites

4@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)

This code is wrong..

- Are you using some kind of ChatGPT to write this weirdo script?

- We have already commented on your request and even post you a better script (Especially Strs).. Why are you ignoring us and showing up with wrong script again?

- "$8224 == 0"...... Global Variable usage on a CLEO Script.. it's definitely NOT RECOMMENDED.. you should avoid using them or convert to local variable..

- Why are you leaving blanks on each code block? Are you reading or at least taking a peek these CLEO Coding Tutorials?

7 minutes ago, Strs said:

        02E2: set_actor 4@ weapon_accuracy_to 5

he is trying to use more local variable which is good...i have just an idea.. he may also define ammo and accuracy values at the header so he don't need to go down and do these changes.. 🙂

Link to comment
Share on other sites

? "(Especially Strs).. Why are you ignoring us" who ? look bro i have high temper problem ok let me clear it if you dont like its fine you copy code once and put in your sannybuilder and see what happens those // is ignore area where he made a mistakes and you talking here as OSMFG ? i give what he ask i dont have to explain everything right ?  

Edited by Strs
add
Link to comment
Share on other sites

5 hours ago, ArmanCan said:
4@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)

This code is wrong..

- Are you using some kind of ChatGPT to write this weirdo script?

- We have already commented on your request and even post you a better script (Especially Strs).. Why are you ignoring us and showing up with wrong script again?

- "$8224 == 0"...... Global Variable usage on a CLEO Script.. it's definitely NOT RECOMMENDED.. you should avoid using them or convert to local variable..

- Why are you leaving blanks on each code block? Are you reading or at least taking a peek these CLEO Coding Tutorials?

he is trying to use more local variable which is good...i have just an idea.. he may also define ammo and accuracy values at the header so he don't need to go down and do these changes.. 🙂

What's wrong with that specific code? It works.

1. No i don't

2. The code that strs posted in earlier post is broken and less readable than the code i had. Also the code that strs posted in this post doesn't do the things i want(every 10 seconds either spawn ballas with weapons or without)

3. Sure i'll change it to local variable

4. I am leaving blanks on each code block to make code more readable. Yes i am reading docs.

5 hours ago, Strs said:

{$cleo .cs}

0000:
while true
if and
    Player.Defined($PLAYER_CHAR)
    Player.Controllable($PLAYER_CHAR)
jf  continue

model.load(#ballas1)
model.load(#AK47)
model.load(#SILENCED)
model.load(#TEC9)
model.load(#MP5LNG)

038B: load_requested_models

0ADF: add_dynamic_GXT_entry '_SPAWN1' your_text "Ballas Spawned!"
0ADF: add_dynamic_GXT_entry '_SPAWN2' your_text "Ballas with weapons spawned!"

:label
while true     
     wait 10000
     //why you use here ? waiting if so then dont use that 0099: $8224 = random_int_in_ranges_0_to_1 or 0209: 9@ = random_int_in_ranges 0 5 make no sense
     actor.RemoveReferences(4@)
     actor.DestroyInstantly(4@)
         
     actor.RemoveReferences(5@)
     actor.DestroyInstantly(5@)
         
     actor.RemoveReferences(6@)
     actor.DestroyInstantly(6@) 
                  
     actor.RemoveReferences(7@)
     actor.DestroyInstantly(7@)
                  
     actor.RemoveReferences(8@)
     actor.DestroyInstantly(8@)
//0209: 9@ = random_int_in_ranges 0 5  //idk why you use this but ok here the thing you selsect 0 to   then there is chance 2 more often ok if you choose 0 to 1 nd you looking for 0 its not going to happen
     
    // 0099: $8224 = random_int_in_ranges_0_to_1
     
    // if
     //   9@ == 2
     //then
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 1.0 2.0 -1.0
        4@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 2.0 2.0 -1.0
        5@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 3.0 2.0 -1.0
        6@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
        04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 4.0 2.0 -1.0
        7@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
{         
         
        Actor.GiveWeaponAndAmmo(4@, WeaponType.Ak47, 100) 
        Actor.GiveWeaponAndAmmo(5@, WeaponType.PistolSilenced, 100)  
        Actor.GiveWeaponAndAmmo(6@, WeaponType.Tec9, 100) 
        Actor.GiveWeaponAndAmmo(7@, WeaponType.Mp5, 100) 
}        
01B2: give_actor 4@ weapon 31 ammo 100 // Load the weapon model before using this
01B2: give_actor 5@ weapon 23 ammo 100 // Load the weapon model before using this
01B2: give_actor 6@ weapon 32 ammo 100 // Load the weapon model before using this
01B2: give_actor 7@ weapon 29 ammo 100 // Load the weapon model before using this
         
        02E2: set_actor 4@ weapon_accuracy_to 5
        02E2: set_actor 5@ weapon_accuracy_to 5  
        02E2: set_actor 6@ weapon_accuracy_to 5
        02E2: set_actor 7@ weapon_accuracy_to 5

         
        00BA: show_text_styled GXT '_SPAWN2' time 2300 style 1  
         
        07A5: AS_actor 4@ attack_actor $PLAYER_ACTOR time 9999999999999
        07A5: AS_actor 5@ attack_actor $PLAYER_ACTOR time 9999999999999
         
        07A5: AS_actor 6@ attack_actor $PLAYER_ACTOR time 9999999999999
        07A5: AS_actor 7@ attack_actor $PLAYER_ACTOR time 9999999999999
    //end
 //   if
     //   $8224 == 1
 //   then
                 04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 1.0 2.0 -1.0
         4@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 2.0 2.0 -1.0
         5@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 3.0 2.0 -1.0
         6@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 4.0 2.0 -1.0
         7@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
         
         04C4: store_coords_to 1@ 2@ 3@ from_actor $player_actor with_offset 5.0 2.0 -1.0
         8@ = Actor.Create(Criminal, #ballas1, 1@, 2@, 3@)
                  
         
         00BA: show_text_styled GXT '_SPAWN1' time 2300 style 1  
         
         07A5: AS_actor 4@ attack_actor $PLAYER_ACTOR time 9999999999999
         07A5: AS_actor 5@ attack_actor $PLAYER_ACTOR time 9999999999999
         
         07A5: AS_actor 6@ attack_actor $PLAYER_ACTOR time 9999999999999
         07A5: AS_actor 7@ attack_actor $PLAYER_ACTOR time 9999999999999
         
         07A5: AS_actor 8@ attack_actor $PLAYER_ACTOR time 9999999999999
         Model.Destroy(#BALLAS1)  
Model.Destroy(#AK47)
Model.Destroy(#SILENCED)
Model.Destroy(#TEC9)
Model.Destroy(#MP5LNG)  
  end   
end
 

This code doesn't do what i want. I want to spawn ballas every 10 seconds either with or without weapons. I use random int to choose it randomly

Link to comment
Share on other sites

What is purpose of first if statement? Skip loading models? Also I'm not sure if player is defined and controllable as script starts, so it perhaps always skips that part. Add some text prints to see what part of the code is actually executed and what skipped. Like:
 

0AD1: show_formatted_text_highpriority "Debug text" time 10000

 

Link to comment
Share on other sites

30 minutes ago, MiranDMC said:

What is purpose of first if statement? Skip loading models? Also I'm not sure if player is defined and controllable as script starts, so it perhaps always skips that part. Add some text prints to see what part of the code is actually executed and what skipped. Like:
 

0AD1: show_formatted_text_highpriority "Debug text" time 10000

 

Thanks for suggestion. About first if statement - ArmanCan said "It seems your script is initiated with the player.. you must check if the player is "defined" and i think "controllable" also.. and than you should start to load your models.." and provided me with this code in earlier post, so i used it.

Edited by Nohet
Link to comment
Share on other sites

@Nohet as @ArmanCan said you are chat gpt guy now i know. 🤣 if it wasn't chatgpt then you are mean person i was first person who thought ill help but you are so mean you wrote "The code that strs posted in earlier post is broken and less readable than the code i had. Also the code that strs posted in this post doesn't do the things i want(every 10 seconds either spawn ballas with weapons or without)" someone try this script and see if i give something else not what he ask. 

Link to comment
Share on other sites

6 hours ago, Strs said:

@Nohet as @ArmanCan said you are chat gpt guy now i know. 🤣 if it wasn't chatgpt then you are mean person i was first person who thought ill help but you are so mean you wrote "The code that strs posted in earlier post is broken and less readable than the code i had. Also the code that strs posted in this post doesn't do the things i want(every 10 seconds either spawn ballas with weapons or without)" someone try this script and see if i give something else not what he ask. 

I said "The code that strs posted in earlier post is broken and less readable than the code i had" because ArmanCan said why i don't use your script. The code you posted in earlier post(about spawning an actor) throws an error and someone already gave me a solution to my problem. That's why i don't use it. I tested your script that you posted in this post and it doesn't do the things i want. Why are you getting mad bro? I'm just answering questions, not trying to be mean.

Link to comment
Share on other sites

 "Why are you getting mad bro?" you said my script broken ? that is your script not mine i just remove sh*t from it that you add it that's all if its broken its yours not mine why would i mad because i can write script i dont ask Chat GPT for broken script 😂 

Link to comment
Share on other sites

You should wait till player is available.

 

while True
	if and
    		Player.Defined($PLAYER_CHAR)
    		Player.Controllable($PLAYER_CHAR)
	then
		break // exit the loop
	end
	
	wait 0 // skip till next frame
end

 

Edited by MiranDMC
Link to comment
Share on other sites

54 minutes ago, MiranDMC said:

You should wait till player is available.

 

while True
	if and
    		Player.Defined($PLAYER_CHAR)
    		Player.Controllable($PLAYER_CHAR)
	then
		break // exit the loop
	end
	
	wait 0 // skip till next frame
end

 

I debugged like you suggested and i've found out what is the problem. The problem is with generating random int. Instead of it generating int from ranges 0 to 1 it generates int from 0 to 32767. Do you know how I can fix that?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.