Bierbuikje Posted April 9, 2009 Share Posted April 9, 2009 Hello, I've made a mod to spawn bushes/plants and when a player presses '.' then only the last bush explodes. And not all the bushes that where spawned explodes. I don't know how to let explode all the bushes. Does someone know how tot fix this? :1$Plant = 0jump @Begin:BeginModel.Load(-201)038B: load_requested_models :Checkwait 0if not Model.Available(-201)else_jump @Check2wait 0jump @Check:Check2wait 0if0AB0: key_pressed 191else_jump @Check2wait 0jump @Plant:Plant$Plant += 104C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 1.0 -1.00107: $Plant = create_object -201 at [email protected] [email protected] [email protected] 0:Check3wait 0if0AB0: key_pressed 191else_jump @Check4wait 0jump @Plant:Check4wait 0if0AB0: key_pressed 190else_jump @Check3wait 0jump @Explosie:Explosie0400: store_coords_to $Plant1 $Plant2 $Plant3 from_object $Plant with_offset 0.0 0.0 0.00565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 50565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 100565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 150565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 200565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 250565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 300565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 350565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 400565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 450565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 50wait 001C4: remove_references_to_object $Plant // This object will now disappear when the player looks awaywait 0Model.Destroy(-201)wait 0jump @Begin Link to comment Share on other sites More sharing options...
Dutchy3010 Posted April 9, 2009 Share Posted April 9, 2009 (edited) When you are using a variable, and you use it again, the first one is rewritten. You can't use variables twice (well, you can, but it will only "remember" one value). That is why it only deletes one, the last one. The other values are gone. It is possible to make a "variable within a variable", so you can change the variable (called an array). Most of the time, coders use "$idx" for the second variable. I wrote a code with an array. If you don't understand a part, feel free to ask. Everytime you press Y, an actor will spawn. When you press N, you have to delete all actors. Make sure you add the "var ... end" in the beginning, because else it won't work. $ACTOR[$idx] is just a variable, so when $idx is 1, it becomes $ACTOR[1] and when $idx is 2, it becomes $ACTOR[2]. Just keep that in mind, when you are coding this. :STARTthread 'START'var$idx : integer$ACTOR: array 20 of Actorend$idx = 0:PRESSwait 100if00E1: player 0 pressed_key 11 then$idx += 104C4: store_coords_to $TEMPVAR_FLOAT_1 $TEMPVAR_FLOAT_2 $TEMPVAR_FLOAT_3 from_actor $PLAYER_ACTOR with_offset 0.0 3.0 0.0 009A: $ACTOR[$idx] = create_actor_pedtype 4 model #MALE01 at $TEMPVAR_FLOAT_1 $TEMPVAR_FLOAT_2 $TEMPVAR_FLOAT_3endif and00E1: player 0 pressed_key 10$idx > 0 then0084: $idx2 = $idx$idx = 0repeat wait 0$idx += 10321: kill_actor $ACTOR[$idx]until 003A: $idx == $idx2 endjump @PRESS Good luck. EDIT: I forgot to tell, you can only spawn 20 actors with this code. So you have to check if the player has more then 20... And beware for the limites of the engine. Edited April 9, 2009 by Dutchy3010 DYOM - Create, play, share! Link to comment Share on other sites More sharing options...
ZAZ Posted April 9, 2009 Share Posted April 9, 2009 (edited) To understand what Dutschy has written.. When you are using a variable, and you use it again, the first one is rewritten. You can't use variables twice (well, you can, but it will only "remember" one value). That is why it only deletes one, the last one. The other values are gone. It is possible to make a "variable within a variable", so you can change the variable (called an array). .. you need first to release the object instance $Plant from script before creating one more in same creation line like in this simple script below I changed object number with original object ID number and changed also the key_press numbers //DEFINE OBJECT GRASSPLANT // Object number -201//3409, grassplant:1thread 'PLANT'$Plant = 0:2wait 0 if Player.Defined($PLAYER_CHAR)jf @2if0AB0: key_pressed 55//------------ 7else_jump @2Model.Load(3409)038B: load_requested_models:Checkwait 0if not Model.Available(3409)else_jump @Plantwait 0jump @Check:Plant//$Plant += 104C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 1.0 -1.00107: $Plant = create_object 3409 at [email protected] [email protected] [email protected] 1000:Check4wait 0if0AB0: key_pressed 57//-------- 9else_jump @Check4:Explosie0400: store_coords_to $Plant1 $Plant2 $Plant3 from_object $Plant with_offset 0.0 0.0 0.00565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 1001C4: remove_references_to_object $Plant // This object will now disappear when the player looks awayModel.Destroy(3409)jump @2 To understand what Dutschy has written.. Most of the time, coders use "$idx" for the second variable. I wrote a code with an array. If you don't understand a part, feel free to ask. Everytime you press Y, an actor will spawn. When you press N, you have to delete all actors. Make sure you add the "var ... end" in the beginning, because else it won't work. $ACTOR[$idx] is just a variable, so when $idx is 1, it becomes $ACTOR[1] and when $idx is 2, it becomes $ACTOR[2]. Just keep that in mind, when you are coding this. ... the script below shows how to create multiple object instance of grassplants in same creation line by using arrays //DEFINE OBJECT GRASSPLANT // Object number -201//3409, grassplant:GPLANTthread 'GPLANT'0004: $PlantObj[0] = 0 // PED handle 0004: $PlantObj[1] = 0 // PED handle0004: $PlantObj[2] = 0 // PED handle0004: $PlantObj[3] = 0 // PED handle0004: $PlantObj[4] = 0 // PED handle0004: $PlantObj[5] = 0 // PED handle0004: $PlantObj[6] = 0 // PED handle0004: $PlantObj[7] = 0 // PED handle0004: $PlantObj[8] = 0 // PED handle0004: $PlantObj[9] = 0 // PED handle0004: $PlantObj[10] = 0 // PED handle$Plantcounter = 0:GPLANT_1wait 0 if Player.Defined($PLAYER_CHAR)jf @GPLANT_1if0AB0: key_pressed 55//------------key = 7else_jump @GPLANT_1Model.Load(3409)038B: load_requested_models:GPLANT_3wait 0if not Model.Available(3409)else_jump @GPLANT_5wait 0jump @GPLANT_3:GPLANT_5wait 004C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 1.0 -1.00107: $PlantObj($Plantcounter,16i) = create_object 3409 at [email protected] [email protected] [email protected]$Plantcounter += 1wait 1000:GPLANT_7wait 0if001A: 10 > $Plantcounter else_jump @GPLANT_9if8AB0: not key_pressed 55//------------key = 7else_jump @GPLANT_5:GPLANT_9if0AB0: key_pressed 57//--------key = 9else_jump @GPLANT_7:GPLANT_10wait 50000C: $Plantcounter -= 10400: store_coords_to $Plant1 $Plant2 $Plant3 from_object $PlantObj($Plantcounter,16i) with_offset 0.0 0.0 0.00565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 1001C4: remove_references_to_object $PlantObj($Plantcounter,16i) // This object will now disappear when the player looks awayif0038: $Plantcounter == 0 else_jump @GPLANT_10Model.Destroy(3409)jump @GPLANT_1 Edited April 9, 2009 by ZAZ CLEO MODS CLEO Script Tutorial Link to comment Share on other sites More sharing options...
Bierbuikje Posted April 9, 2009 Author Share Posted April 9, 2009 I have a question about this: $idx : integer$ACTOR: array 20 of Actor What is it meaning? And how to do this for an object? Is it then: ? $idx : integer$Plant: array 20 of Object Link to comment Share on other sites More sharing options...
Bierbuikje Posted April 9, 2009 Author Share Posted April 9, 2009 I tried the same as the script of ZAZ but my script is crashing ingame. I can spawn bushes/plants but when I press '.' (explode button) it crashes. The '.' butten is layer @Check4. {$CLEO .CS}:1jump @Begin:Begin0004: $Plant[0] = 00004: $Plant[1] = 00004: $Plant[2] = 00004: $Plant[3] = 00004: $Plant[4] = 00004: $Plant[5] = 00004: $Plant[6] = 00004: $Plant[7] = 00004: $Plant[8] = 00004: $Plant[9] = 00004: $Plant[10] = 00004: $Plant[11] = 00004: $Plant[12] = 00004: $Plant[13] = 00004: $Plant[14] = 00004: $Plant[15] = 00004: $Plant[16] = 00004: $Plant[17] = 00004: $Plant[18] = 00004: $Plant[19] = 0$Count = 0jump @Begin2:Begin2Model.Load(-201)038B: load_requested_models :Checkwait 0if not Model.Available(-201)else_jump @Check2wait 0jump @Check:Check2wait 0if0AB0: key_pressed 191else_jump @Check2wait 0jump @Plant:Plantwait 004C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 10.0 -1.00107: $Plant($Count,16i) = create_object -201 at [email protected] [email protected] [email protected]$Count += 1wait 0:Check3wait 0if and0AB0: key_pressed 191001A: 19 > $Count else_jump @Check4wait 0jump @Plant:Check4wait 0if0AB0: key_pressed 190else_jump @Check3wait 00084: $Count2 = $Countjump @Explosie:Explosierepeat$Count -= 10400: store_coords_to $Plant1 $Plant2 $Plant3 from_object $Plant($Count,16i) with_offset 0.0 0.0 0.00565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 50565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 100565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 150565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 200565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 250565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 300565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 350565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 400565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 450565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 50until 0084: $Count = 0wait 00084: $Count = $Count2repeat$Count -= 101C4: remove_references_to_object $Plant($Count,16i) // This object will now disappear when the player looks awayuntil 0084: $Count = 0Model.Destroy(-201)wait 0jump @Eind:Eindjump @Begin0A93: end_custom_thread Link to comment Share on other sites More sharing options...
Dutchy3010 Posted April 9, 2009 Share Posted April 9, 2009 Twice you are using the following code: until 0084: $Count = 0 This isn't possible. The opcode after 0084, has to be a condition. This isn't a condition, with this opcode you are saying: the variable $count has to be 0. I think you mean that the condition is true, when the variable count is 0. Then you have to use ==: 003A: $Count == $Count2 Second: repeat$Count -= 101C4: remove_references_to_object $Plant($Count,16i) // This object will now disappear when the player looks awayuntil 0084: $Count = 0 You don't have a wait in this repeat-wait-until loop. DYOM - Create, play, share! Link to comment Share on other sites More sharing options...
ZAZ Posted April 9, 2009 Share Posted April 9, 2009 (edited) $Plant($Count,16i) 16 is the maximum of possible instances in the array or other words: it defines the max counting you must increase it to can create 19 instances e.g. $Plant($Count,32i) Edited April 10, 2009 by ZAZ CLEO MODS CLEO Script Tutorial Link to comment Share on other sites More sharing options...
Seemann Posted April 10, 2009 Share Posted April 10, 2009 Bierbuikje, Model.Load(-201)...Model.Available(-201)...etc This is wrong. You can't use such ID (-201) there. Use model name (#..). Your code is full of unnecessary wait 0 and jump to the next label commands. You only need for 2 waits in your code: one for the key_pressed loop and one for the model_available loop. You dont have the player_defined check loop. And do not use global variables in CLEO scripts. Second: repeat$Count -= 101C4: remove_references_to_object $Plant($Count,16i) // This object will now disappear when the player looks awayuntil 0084: $Count = 0 You don't have a wait in this repeat-wait-until loop. And he doesn't have to. In other words, wait is not needed there, as this loop is finite and doesnt expect any input from the player or environment (for example key_pressed check is expecting player input, so the wait command must be there). Sanny Builder 3 • SA Memory Handling • OpenIV • gtamodding.com CLEO.li - The CLEO Library - Official site Link to comment Share on other sites More sharing options...
Dutchy3010 Posted April 10, 2009 Share Posted April 10, 2009 Second: repeat$Count -= 101C4: remove_references_to_object $Plant($Count,16i) // This object will now disappear when the player looks awayuntil 0084: $Count = 0 You don't have a wait in this repeat-wait-until loop. And he doesn't have to. In other words, wait is not needed there, as this loop is finite and doesnt expect any input from the player or environment (for example key_pressed check is expecting player input, so the wait command must be there). Yeah, you are right, I didn't look at what was in the loop. DYOM - Create, play, share! Link to comment Share on other sites More sharing options...
Bierbuikje Posted April 10, 2009 Author Share Posted April 10, 2009 Bierbuikje, Model.Load(-201)...Model.Available(-201)...etc This is wrong. You can't use such ID (-201) there. Use model name (#..). That's because it is a cleo script and this is working too. My script ain't working. I did everything you said, tried, editted, tried again. But it crashes all the time when I try to explode the bushes/plants. {$CLEO .CS}:1jump @Begin:Begin0004: $Plant[0] = 00004: $Plant[1] = 00004: $Plant[2] = 00004: $Plant[3] = 00004: $Plant[4] = 00004: $Plant[5] = 00004: $Plant[6] = 00004: $Plant[7] = 00004: $Plant[8] = 00004: $Plant[9] = 00004: $Plant[10] = 00004: $Plant[11] = 00004: $Plant[12] = 00004: $Plant[13] = 00004: $Plant[14] = 00004: $Plant[15] = 00004: $Plant[16] = 00004: $Plant[17] = 00004: $Plant[18] = 00004: $Plant[19] = 0$Count = 0jump @Begin2:Begin2Model.Load(-201)038B: load_requested_models:Checkwait 0if not Model.Available(-201)else_jump @Check2wait 0jump @Check:Check2wait 0if0AB0: key_pressed 191else_jump @Check2:Plantwait 0$Count += 104C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 10.0 -1.00107: $Plant($Count,32i) = create_object -201 at [email protected] [email protected] [email protected]:Check3wait 0if and0AB0: key_pressed 191001A: 19 > $Countelse_jump @Check4wait 0jump @Plant:Check4wait 0if0AB0: key_pressed 190else_jump @Check3wait 00084: $Count2 = $Count:Explosierepeat$Count -= 10400: store_coords_to $Plant1 $Plant2 $Plant3 from_object $Plant($Count,32i) with_offset 0.0 0.0 0.00565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 50565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 100565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 150565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 200565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 250565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 300565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 350565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 400565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 450565: create_temporary_explosion_fire $Plant1 $Plant2 $Plant3 50until 003A: $Count == 0wait 00084: $Count = $Count2repeatwait 0$Count -= 101C4: remove_references_to_object $Plant($Count,32i) // This object will now disappear when the player looks awayuntil 003A: $Count == 0Model.Destroy(-201):Eindjump @Begin0A93: end_custom_thread Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now