Oudy Posted May 19, 2007 Share Posted May 19, 2007 I'd like to start a topic where people can post scripting examples. I'll start with providing some examples from the missions made by 1C. Please try to keep this topic limited to examples of code and not discussion of other issues. How to attack a Rectangle </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">SetWorkArmy ( ARMY , 2 ) RunCommand ( GROUP , "Group_Ger_02" , STORM , RECT , "Rect_1" )</pre> Link to comment Share on other sites More sharing options...
Dennis50 Posted May 19, 2007 Share Posted May 19, 2007 I think Moon or Matt needs to make a new forum for this ...This is pretty hardcore stuff, which is way out of reach of my abilities ..but I still like reading it and trying to understand what it is all about ...but it is helter skelter mixed around in with all the other posts ...Moon and Matt fix or somfink. Regards, Gunz Link to comment Share on other sites More sharing options...
Guest lmgroth Posted May 19, 2007 Share Posted May 19, 2007 Agreed... a new forum for all of this is a good idea. The positive is that eventually many will get it. Then those of us with less programming saavy can modify what others have done. This way every new custom mission can be modded any number of ways (with less work) creating interesting new variations to challenge us and keep things fresh. Maybe the devs can turn out some empty terrain meshes from time to time? These should contain interesting/requested topographical features, that is specifically for the community to use once the map editor is released. Link to comment Share on other sites More sharing options...
Tartari Posted May 19, 2007 Share Posted May 19, 2007 Thank you Oudy, it will help me a lot! Link to comment Share on other sites More sharing options...
Webwing Posted May 19, 2007 Share Posted May 19, 2007 Oudy, Great idea and great bits of code!!! Saving them for later use.... Thanks --- Link to comment Share on other sites More sharing options...
Freaky Posted May 19, 2007 Share Posted May 19, 2007 Thanks a lot for that Link to comment Share on other sites More sharing options...
War RaVeN Posted May 20, 2007 Share Posted May 20, 2007 Yea, this is very helpful :cool: Moon, Madmatt. Is it not time to have a dedicated section here on the board for only coding, tips, tricks, mod, etc, etc .... to build a fine community around this great game? Regards, War Raven Link to comment Share on other sites More sharing options...
Oudy Posted May 20, 2007 Author Share Posted May 20, 2007 How to unlimber and fire a gun using code. This is a code of my own creation. With this example you have to cheat because there is no way to limber or unlimber using codes. So, here is what I did as a workaround. In the mission tree I created a transport vehicle, the artillery piece and a separate crew. I put the crew in the vehicle and attached the artillery piece. When the unit spawns the vehicle is towing the artillery piece with the crew inside. The vehicle is ordered to move to a rectangle. Once it is in the rectangle the crew is ordered out of the vehicle. The vehicle and gun are then destroyed and another vehicle and gun are respawned at that spot. The crew is then ordered to man the gun. Since there is no unlimber command, you need to know in advance where you want to position the gun because you have to manually place the replacement gun and vehicle in the editor. This example demonstrates the need for an unlimber command or at least the ability to dynamically spawn units in different locations during play. If anyone wants to improve on my meager coding attempt, please feel free. [Call from GTank_Reinf] </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">Set @group = "Group_AT_1Sect_Trans" Set @rect = "GArt_1" Set @army = 4 Set @crew = "Group_AT_1Sect_Crew" Set @gun = 533 Set @SdKfz7 = 534 RunTriggerInstance ( "GArt_Unlimber" , @group , @group , @rect , @army , @crew , @gun , @SdKfz7 )</pre> Link to comment Share on other sites More sharing options...
Jeff Duquette Posted May 20, 2007 Share Posted May 20, 2007 This would be a nice addition to the Sealow Heights scenario. There are two German AT guns that appear early on in the scenario. They are both initially limbered. First time I played the scenario I didn't even know they were there until Soviet tank fire had already destroyed both guns and their tractors -- while the guns were still limbered up. I played the scenario several additional times and I reckon I was able to get these dudes to unlimber and start shooting maybe 50% of the time. The other 50% of the time they were being KO'd by tank fire before my rapid click fest could get these guys out of their tractors and get the AT guns up and ready for shooting. Link to comment Share on other sites More sharing options...
Androo Posted May 28, 2007 Share Posted May 28, 2007 We really do need at least a sticky on this, if not a dedicated forum. If someone hadn't posted a link to this thread in the video tutorial thread I would have missed it altogether. Thanks for some great stuff Oudy, it's going to save me hours! [ May 27, 2007, 09:24 PM: Message edited by: Androo ] Link to comment Share on other sites More sharing options...
SlapHappy Posted May 28, 2007 Share Posted May 28, 2007 Yeah, and you could always make the truck drive out of the way or reverse slightly towards the enemy. My guns always got killed because they were trying to clear the truck and got shot to pieces before they could establish a line of sight. Link to comment Share on other sites More sharing options...
Oudy Posted May 28, 2007 Author Share Posted May 28, 2007 SlapHappy When I set up where the guns and trucks would respawn I made sure they were far enough away. I also had the guns unlimber where I thought they might be safe. The only problem with unlimbering them this way is that you have to know beforehand where they are going to be set up, so it isn't the most flexible piece of code. But it has its use. Oudy Link to comment Share on other sites More sharing options...
Freeboy Posted May 28, 2007 Share Posted May 28, 2007 It seems that making a "non command line" editer would be a big seller, I would pay for one Link to comment Share on other sites More sharing options...
Webwing Posted May 28, 2007 Share Posted May 28, 2007 I think if we could create some generic functions or classes to do some common stuff, that would reduce and simplify scripting quite a bit. Oudy's code snipets are already a good help. But I don't see TOW editor ever getting as intuitive as CM editor is, with the ability to change terrain and all. Maybe TOW2? - Link to comment Share on other sites More sharing options...
SlapHappy Posted May 28, 2007 Share Posted May 28, 2007 I have a mission file that is an example of an automated script to conduct an Armored Infantry Assault. If any would like, I can email it to you. It is meant to be watched more so than played, as it is more a cinematic example. However, it is possible to control different units within the group as yours is the army being scripted. It basically shows how you can combine different script commands to perform complex tasks. If you would like to elaborate on the script or have improvements, please feel free to do so. Link to comment Share on other sites More sharing options...
SlapHappy Posted May 29, 2007 Share Posted May 29, 2007 Incidentally, I'll be glad when they fix the hi-low-middle targeting thing. I see no way to put this into a script and I assume the default is always target middle. Link to comment Share on other sites More sharing options...
Broadsword Posted October 20, 2009 Share Posted October 20, 2009 After trying Oudy's limber-unlimber cheat workaraound code ( with a few tweaks of my own), I still can't seem to get any results. Problems: 1. The halftracks appear as reinforcements with the guns already attached, but there's no sign of the gun crews. How can I make them be in the halftrack as passengers? Doesn't the setting of the guns as "trailer" for the tractor vehicle in the Mission panel automatically make the gun crew a passenger too? 2. When the haltracks and guns appear, their little dot on the minimap (usually red for a German unit) appears as gray. How come? Does the game think the units are dead? 3. Despite all kinds of coding trial and error, the halftracks/guns never move from their arrival spot. My code: [in my trigger "Start_Attack" ] Delay ( 5000 ) SetWorkArmy ( Army , 7 ) RunTrigger ( "Mobile_Art" ) [Trigger "Mobile_Art" ] SetWorkArmy ( Army , 7 ) ReinforcementLand ( GROUP , "Group_Ger_GunTrans" ) ReinforcementLand ( GROUP , "Group_Ger_MobileGuns" ) ReinforcementLand ( GROUP , "Group_Ger_GunTrans_1" ) ReinforcementLand ( GROUP , "Group_Ger_MobileGuns_1" ) Delay ( 5000 ) Set @group = ( "Group_Ger_GunTrans" ) Set @crew = ( "Group_Ger_MobileGuns" ) Set @army = 7 Set @unit_vehicle = 591 Set @unit_gun = 607 Set @point = "Point_Mobile_Arty" RunTrigger ( "Move_Ger_Art" , @group , @rect , @army , @crew , @unit_gun , @unit_vehicle ) Delay ( 5000 ) Set @group = ( "Group_Ger_GunTrans_1" ) Set @crew = ( "Group_Ger_MobileGuns_1" ) Set @army = 7 Set @unit_vehicle = 621 Set @unit_gun = 630 Set @point = "Point_Arty_1" RunTrigger ( "Move_Ger_Art1" , @group , @rect , @army , @crew , @unit_gun , @unit_vehicle ) Delay ( 5000 ) Halt [Trigger "Move_Ger_Art"] PARAM IN @group PARAM IN @unit_vehicle PARAM IN @unit_gun PARAM IN @crew PARAM IN @army PARAM IN @rect SetWorkArmy ( ARMY , @army ) //fail safe to make sure units exist LABEL begin SET @unit_live = GetNUnits ( GROUP , @group , ARMOREDCAR , OK_ENGINE , NOT_EMPTY ) IF ( @unit_live = 0 ) Then HALT Endif //move the limbered units LABEL moving RunCommand ( UNIT , 591 , MOVE , POINT , @point ) Delay ( 6000 ) //check to make sure units reach destination SET @num_units = GetNUnitsInArea ( GROUP , @group , ALL , @rect ) IF ( @num_units = 0 ) Then Delay ( 2000 ) GoTo begin EndIF //unload the gun crew LABEL unlimber RunCommand ( UNIT , 591 , OUT_CREW , PASSENGER ) Delay ( 5000 ) //make the transport with limbered gun disappear, replace with unlimbered gun ReinforcementDestroy ( GROUP , @group ) ReinforcementLand ( UNIT , @unit_gun ) ReinforcementLand ( UNIT , @unit_vehicle ) //crew the gun RunCommand ( GROUP , @crew , IN_CREW , UNIT , @unit_gun ) Delay ( 6000 ) //move the vehicle out of the way RunCommand ( UNIT , @unit_vehicle , MOVE , RECT , "Halftracks_Hold" ) Delay ( 5000 ) HALT [end of code] Any ideas?? I'm really stumped! I changed from having the HTs move to a rect to having them move to a point, just in case that was the problem. I also tried specifying the actual unit numbers, where possible, to force them to react. How to unlimber and fire a gun using code. This is a code of my own creation.... Link to comment Share on other sites More sharing options...
Arzok Posted October 20, 2009 Share Posted October 20, 2009 If the unit is in grey, perhaps it has no crew, so it won"t move. Link to comment Share on other sites More sharing options...
Broadsword Posted October 20, 2009 Share Posted October 20, 2009 But I gave a crew to both the transport and the gun, and I see the individual crew members of both units listed on the Mission tree. Link to comment Share on other sites More sharing options...
Sneaksie Posted October 22, 2009 Share Posted October 22, 2009 They are grey because they either belong to neutral army or are empty. To place people inside halftracks or cars: 1) Make separate groups for each vehicle crew (they should contain only one infantry detachment each). Make sure that there are less or equal people to seats in the vehicle. 2) Set this group state to SLEEP. 3) After that you shpuld be able to specify this group in the 'passangers' tab of the vehicle. Link to comment Share on other sites More sharing options...
Broadsword Posted October 25, 2009 Share Posted October 25, 2009 Thanks everyone -- now I've got my two halftracks arriving with limbered guns, the "sleepy" gun crews wake up and board the vehicles, then they move with the german armor to an unlimber point. The gun crews dismount, and then (this is the trick) the original halftracks, with limbered guns disappear (using the ReinforcementDestroy trigger), to be instantly replaced with two identical halftracks and unlimbered guns that wake up and "land" in the same spot. The gun crews man their guns, look for visible targets, and fire away. Initially I had the unlimbered guns go into a "defend' order, but then they never shot at anything. So I did a "CreateRectByObject" trigger loop for them that has them target any visible enemy unit. Link to comment Share on other sites More sharing options...
Sneaksie Posted October 26, 2009 Share Posted October 26, 2009 If they didn't shoot at anything in defend - are you sure that their army isn't NEUTRAL to enemy? You don't have to wake sleeping groups in the field and order them to border halftracks. If you set them to sleep and specify like passangers of the vehicle, they should appear together with the vehicle when you wake it. Why you replace the halftracks with guns with the identical ones with unlimbered guns? Limber/unlimber command doesn't work? Link to comment Share on other sites More sharing options...
Broadsword Posted October 26, 2009 Share Posted October 26, 2009 I did it that way because I thought someone on this thread said the "attach" and "detach" commands didn't actually work in triggers. Also, I changed the "defend" command for the artillery to "attack_ground," so maybe that will make them more aggressive. Link to comment Share on other sites More sharing options...
Recommended Posts