Results 1 to 11 of 11

Thread: Script to delete specific static obj

  1. #1
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Script to delete specific static obj

    Edited
    Thanks to @Marcost and @ATAG_Oskar
    Here is the code I'm using:
    Code:
    ...
    			string findMe = "0:Static21";
    
    			foreach (GroundStationary gs in GamePlay.gpGroundStationarys())
    			{
    				Console.WriteLine("this groundstationary is " + gs.Name); // let's see what is passing through the loop (optical)
    				if (gs.Name.Equals(findMe))
    				{
    					Console.WriteLine("Found target object: " + gs.Name); // let's see if windsocks are found (optical)	
    					gs.Destroy();
    				}
    ...
    p.s.Here the "0 : Static21" is the object code name from this particular mission.

    ( Bugs? as far as I know:
    When deal with windsock, it will delete all objects in the mis
    Fire, smoke, lights(etc) can not be found by this)


    ***************
    Previously
    I have read these:
    https://theairtacticalassaultgroup.c...ad.php?t=32595
    https://theairtacticalassaultgroup.c...ad.php?t=24127
    https://forums.twcpilots.com/showthread.php?tid=165
    But still can't figure out how it works for a specific static object.
    Last edited by fenbeiduo; Dec-18-2020 at 21:15.

  2. #2
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Script to delete specific static obj

    Hi,

    I had problems with IndexOf for this type of find, ended up using Contains.

    How about this:


    Code:
    string findMe = "Windsock";
    	
    foreach (GroundStationary rr in GamePlay.gpGroundStationarys())
              {
    			
                  if (rr.Contains(findMe))
    		{
    		   rr.Destroy();
    		}	
    	   }
    Also make sure Windsock spelling is case-correct

    Regards

  3. Likes fenbeiduo liked this post
  4. #3
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Question Re: Script to delete specific static obj

    Thanks @Marcost!
    Quote Originally Posted by Marcost View Post
    ...
    Code:
    ...	
                  if (rr.Contains(findMe))
    		{
    		   rr.Destroy();
    		}	
    ...
    ...
    I've tried but ...negative, the windsock still there after Trigger fired. I also tried if (rr.Name.Contains(...))


    Quote Originally Posted by Marcost View Post
    ...Also make sure Windsock spelling is case-correct
    Yes the text was paste directly from the .mis file.

    p.s. FMB compile shows "OK"
    Last edited by fenbeiduo; Dec-11-2020 at 13:42.

  5. Likes Marcost liked this post
  6. #4
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Script to delete specific static obj

    Ok how about adding some console output to help debug:

    Code:
    string findMe = "Windsock";
    
    Console.WriteLine("Entering windsock check loop"); // check your code is getting to this point
    	
    foreach (GroundStationary rr in GamePlay.gpGroundStationarys())
              {
                  Console.WriteLine("this groundstationary is " +rr); // let's see what is passing through the loop		
                  if (rr.Contains(findMe))
    		{
                       Console.WriteLine("Found a windsock: " +rr); // let's see if windsocks are found	
    		   rr.Destroy();
    		}	
    	   }

  7. Likes fenbeiduo liked this post
  8. #5
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script to delete specific static obj

    Quote Originally Posted by Marcost View Post
    Ok how about adding some console output to help debug
    Code:
    Console.WriteLine("this groundstationary is " +rr);
    Looks like something beyond my knowledge XD :
    20201212033027_1.jpg
    ...

  9. #6
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script to delete specific static obj

    Just replace your code with that. It will print to the log file showing you what's happening.

    First it will print: Entering windsock check loop

    Then for each stationary in the mission it will print: this groundstationary is whatever

    When it finds a match it will print: Found a windsock windsock name

  10. Likes fenbeiduo liked this post
  11. #7
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script to delete specific static obj

    Quote Originally Posted by ATAG_Oskar View Post
    Then for each stationary in the mission it will print: this groundstationary is whatever
    Yes and it print:
    xln2glTvKUckqdbT1Tt2H4sEQ9saO7OeXdst4ToZrm6QHujyYc uFW9z4M5lu177Nrg
    xln2glTvKUckqdbT1Tt2H4sEQ9saO7OeXdst4ToZrm6QHujyYc uFW9z4M5lu177Nrg
    xln2glTvKUckqdbT1Tt2H4sEQ9saO7OeXdst4ToZrm6QHujyYc uFW9z4M5lu177Nrg
    ...(repeat)

    p.s. I use if (rr.Name.Contains(findMe)) ; otherwise the game does not recognize the code.

  12. #8
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script to delete specific static obj

    Quote Originally Posted by fenbeiduo View Post
    Yes and it print:
    xln2glTvKUckqdbT1Tt2H4sEQ9saO7OeXdst4ToZrm6QHujyYc uFW9z4M5lu177Nrg
    xln2glTvKUckqdbT1Tt2H4sEQ9saO7OeXdst4ToZrm6QHujyYc uFW9z4M5lu177Nrg
    xln2glTvKUckqdbT1Tt2H4sEQ9saO7OeXdst4ToZrm6QHujyYc uFW9z4M5lu177Nrg
    ...(repeat)

    p.s. I use if (rr.Name.Contains(findMe)) ; otherwise the game does not recognize the code.
    You are correct, the code should look like this:

    Console.WriteLine("Found a windsock: " + rr.Name); // let's see if windsocks are found

    if (rr.Name.Contains(findMe))

    Console.WriteLine("this groundstationary is " + rr.Name); // let's see what is passing through the loop

  13. Likes fenbeiduo liked this post
  14. #9
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Script to delete specific static obj

    Ok then I think that is your problem... you are assuming the routine will return the name of the object as it is shown in the mission file. But, clod names in code are not the same as names in .mis. You have to derive the .mis name from the 'coded' groundstationary name that your code generates.

    e.g.

    rr = groundstationary.name()

    where .name() gives you the 'readable' .mis version of the object name.

    Sorry I don't know the code for that offhand. Maybe analyse the dll's or previous scripts?

    Regards,

    M

  15. Likes fenbeiduo liked this post
  16. #10
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script to delete specific static obj

    Quote Originally Posted by Marcost View Post
    ...But, clod names in code are not the same as names in .mis. You have to derive the .mis name from the 'coded' groundstationary name that your code generates...
    I think I've got this point now.
    Last edited by fenbeiduo; Dec-12-2020 at 01:38.

  17. #11
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script to delete specific static obj

    Quote Originally Posted by ATAG_Oskar View Post
    ...code should look like this:

    Console.WriteLine("Found a windsock: " + rr.Name); // let's see if windsocks are found

    if (rr.Name.Contains(findMe))

    Console.WriteLine("this groundstationary is " + rr.Name); // let's see what is passing through the loop
    Thanks for the help, now I can find some of the static objects(in this case string findMe = "0 : Static21").
    But, when rr.Destroy(); is running, all statics were deleted (.. maybe an array should be used in this case?
    I've tried something like: string[] objlist = rr.GetItems(); but failed)

    On the other hand, after some tests, I find that:
    1) Object which loaded from a 'postload' .mis can not be found by this method.*correction* for postmission1, change name to ‘1 : Static21’

    2) Fire, smoke, lights(etc) can not be found by this method.

    Question: Can we overcome this?(of course, for one specific object, not all), and how to?
    Last edited by fenbeiduo; Dec-13-2020 at 03:41.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •