Knuckle Cracker

Particle Fleet => Map Makers, Ship Builders, and Coders => Topic started by: GameGlitch on October 21, 2016, 12:34:34 PM

Title: Flipping with PRPL
Post by: GameGlitch on October 21, 2016, 12:34:34 PM
Hey guys,

I'm new to the Creeper World series and I know very little about coding. I don't learn very well by reading FAQs, but I learn better with a starting point and reverse engineering from there (if you can phrase it that way).

In that case then, if you don't mind the questions of an absolute newb, is it possible to flip structures using PRPL? If so, what coding is necessary to do so?
Title: Re: Flipping with PRPL
Post by: Oblivion on October 21, 2016, 03:54:27 PM
There is a way to flip structures in the map editor. Its prebuilt in, as for flipping when something instead of a lathe causes it. I don't know the code for it. All the map maker labeled people apparently have access to all the codes.
Title: Re: Flipping with PRPL
Post by: planetfall on October 21, 2016, 04:05:57 PM
If you have the unit stored in the variable uid, you can flip it like this:

<-uid.UnitIsEnemy not ->uid.UnitIsEnemy

Here's an example "on-the-napkin" script to make something flippable by lathe:


once
CurrentCoords 0 1 GetAllUnitsInRange ->units
<-units GetListCount 0 do
  <-units[I] ->uid
  <-uid Self neq if
   break
  endif
loop
--units
endonce

<-uid.UnitHealth 0.05 lt if
<-uid.UnitMaxHealth ->uid.UnitHealth
<-uid.UnitIsEnemy not ->uid.UnitIsEnemy
endif
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 21, 2016, 10:00:36 PM
You know, I should have been a lot more clear with what I was asking. Thank you for responding; sorry for being unclear.

What was actually looking for was to code in for a lathable structure to cause other structures to flip. I've seen a structure lathe everything on the map before, so if that can be recreated, the structures only need to be set for "flip" as Oblivion suggested. How is that done?
Title: Re: Flipping with PRPL
Post by: Oblivion on October 22, 2016, 06:42:37 AM
In the map editor theres an option "Has Lathe" check it if you want the structure to be able to lathe anything in its range.
Title: Re: Flipping with PRPL
Post by: Builder17 on October 22, 2016, 07:09:14 AM
I think he means inhibitor like enemy what when lathed , flips other enemies?  :-\
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 22, 2016, 09:03:05 AM
If you mean a Totem-like structure which flips all units under certain conditions, another napkin script:


:destroyed
CurrentCoords 0 9999 GetAllUnitsInRange ->units
<-units GetListCount 0 do
   1 ->units[I].UnitIsEnemy
loop


This should flip all units to "good".
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 26, 2016, 06:47:21 PM
Thanks for all the help. I've been fiddling with things, so I didn't even realize an object like the totem existed (that is, expressly for destroying everything on the map) until very recently. Now that I understand how it works, that changes my question.

Ideally, I'd like to be able to lathe an info cache causing every allied structure except Omnis to flip to the enemy side. Basically, there's a story idea behind it, and it would be really cool to be able to do. It it possible to script something like that?





Title: Re: Flipping with PRPL
Post by: GoodMorning on October 26, 2016, 07:55:30 PM
Yes. Adapting the above code, you would need to have a Core which is invisible and indestructible (manual setting is easiest).

Then the script needs to find the info cache UID, and when it is destroyed, run a modified form of that code. When I have time, I'll write one for you if you need.
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 26, 2016, 08:34:36 PM
Yeah, when you get the chance, would you write it up? That would be greatly appreciated.

If I'm following right, the PRPL Core function is defined by the script that it holds/uses. As an indestructible object, the script won't be affect by being lathed. As invisible, it can't be seen, but can it still be lathed?
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 26, 2016, 09:00:49 PM
Here's a summary:
A PRPL core is a generic "unit", which you can attach scripts to. This allows it to have more function than a brick (or not, as you choose).

Like most units, you can check boxes for "lathable", "map goal", &c.

You can also set the image for the Core.

Assuming that there are no other units in on top of the cache, and you place the Core on top of it:


once
  CurrentCoords 0 1 GetAllUnitsInRange ->units
  <-units GetListCount 0 do
    <-units[I] ->uid
    <-uid Self neq if
      break
    endif
  loop
  --units
  <-uid ->Cache
  --uid
endonce

<-Cache.UnitIsDestroyed if
  Self 0 DestroyUnit #This has no further use when the cache is finished with.
endif

:destroyed
  CurrentCoords 0 9999 GetAllUnitsInRange ->units
  <-units GetListCount 0 do
    <-units[I] GetUnitType "OMNI" neq if #Spare the Omnis, better hope you brought an "Omni Reactors" upgrade to the table.
      1 ->units[I].UnitIsEnemy #Made a mistake before, this will make them "enemy"...
    endif
loop


This may not work correctly with regard to player ships, and I've likely mangled at least one of the functions (the docs are still mostly unstarted). However, it should give you the structure of what needs to be done. If you are comfortable with looking up the cache UID then you can use "123456 ->Cache" instead of the "once" block, where you replace "123456" with whatever the UID actually is.
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 27, 2016, 05:05:51 PM
So, I tried to input the script, but I did get an error. It reads as follows: "Line: 23: A dot is only allowed in string literals and floating point numbers: .UnitisEnemy"
Title: Re: Flipping with PRPL
Post by: Oblivion on October 27, 2016, 06:33:54 PM
is the I capitalized? if it is
<-units(Box with I in it) ->Unit
1 ->Unit.UnitIsEnemy
might work
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 28, 2016, 09:08:22 PM
Oblivion, I get an error bouncing back. "Line 23: An 'endif' is missing a matching 'if'"

Also, I would like to point out in my previous post that I said the error was for Line 23. The error concerning ".UnitIsEnemy." is actually on line 22. My apologies if that caused any confusion. Any ideas on why it's getting stuck?

Additionally, I would like to admit that it's possible I'm doing something wrong. For approximately two days (on and off), I thought I had attached the script to the PRPL core, but, uh, nope. Only a few few minutes ago did I realize my oversight. In any case, I'm slowly understanding how this all works, but I do really appreciate all the help.
Title: Re: Flipping with PRPL
Post by: Oblivion on October 28, 2016, 09:56:03 PM

      <-units[I] ->Unit
1 ->Unit.UnitIsEnemy


Those two lines in the area should fix it
Overall look:


  CurrentCoords 0 9999 GetAllUnitsInRange ->units
  <-units GetListCount 0 do
    <-units[I] GetUnitType "OMNI" neq if
      <-units[I] ->Unit
1 ->Unit.UnitIsEnemy
    endif
loop
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 28, 2016, 11:01:54 PM
A little testing, and I find that the attached script does almost exactly what you wish.

There are a few PRPL issues to be overcome:
1) Doppel "cores" will remain blue and hold the previous particle "ship", but gradually build a red particle "ship" over this. This may cause some damage, as the old blue particles are destroyed and replaced.
2) Player ships are still bound to the ship slots, and can be selected by this means. While the UI "DESTROY" button vanishes, the "DESTROY" hotkey can still cause them to self-destruct.

A previous discussion on map "surprises" leads me to say: If this is not the end of the mission, provide plenty of warning.

For the script input "WinMapOnCollection", use either 0 (aka FALSE) or 1 (aka TRUE). If you set it to 1, the mission will instantly be won when the cache is collected.
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 29, 2016, 10:26:27 AM
Good Morning, which script do you mean by attached script?
Title: Re: Flipping with PRPL
Post by: Builder17 on October 29, 2016, 10:36:02 AM

once
  CurrentCoords 0 1 GetAllUnitsInRange ->units
  <-units GetListCount 0 do
    <-units[I] ->uid
    <-uid Self neq if
      break
    endif
  loop
  --units
  <-uid ->Cache
  --uid
endonce

<-Cache.UnitIsDestroyed if
  Self 0 DestroyUnit #This has no further use when the cache is finished with.
endif

:destroyed
  CurrentCoords 0 9999 GetAllUnitsInRange ->units
  <-units GetListCount 0 do
    <-units[I] GetUnitType "OMNI" neq if #Spare the Omnis, better hope you brought an "Omni Reactors" upgrade to the table.
      <-units[I] ->Unit
      1 ->Unit.UnitIsEnemy #Made a mistake before, this will make them "enemy"...
    endif
loop


This script?
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 29, 2016, 12:16:11 PM
That's what I thought. If GoodMorning got it to work, there's nothing wrong with the script. I must be doing something wrong instead.

To recap what I'm doing, in the map editor, I go to scripts. I created a script named "Flip Script." After clicking edit, copy-pasting the script to notepad, and saving, I compiled it. There were no errors (making the adjustment that Oblivion suggested).

So, I added "File Script" to the PRPL Core and hit "Apply"  then placed the Core atop the Info Cache. I proceeded to Lathe the Cache, and when I do the Core disappears. But nothing on the map happens. I do have the Ticon Defense Cannons, Benign Emitters, and friendly Energy Mines on the map at the time of testing.

Title: Re: Flipping with PRPL
Post by: Oblivion on October 29, 2016, 04:12:44 PM
I believe I found what was wrong

once
  CurrentCoords 0 1 GetAllUnitsInRange ->units
  <-units GetListCount 0 do
    <-units[I] ->uid
    <-uid Self neq if
      break
    endif
  loop
  --units
  <-uid ->Cache
  --uid
endonce

<-Cache.UnitIsDestroyed if
  Self 0 DestroyUnit #This has no further use when the cache is finished with.
endif

:destroyed
  CurrentCoords 0 9999 GetAllUnitsInRange ->units
  <-units GetListCount 0 do
    <-units[I] GetUnitType "OMNI" neq if #Spare the Omnis, better hope you brought an "Omni Reactors" upgrade to the table.
      <-units[I] ->Unit
      1 ->Unit.UnitIsEnemy #Made a mistake before, this will make them "enemy"...
    endif
loop


Its not CurrentCoords 0 9999 its CurrentCoords 9999 0 GetAllUnitsInRange, it had a range of zero and a size of a square, reverse the numbers and it should be fine. That should be it I think.
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 29, 2016, 05:47:57 PM
No, I made the mistake of testing an idea I had while writing the post, and so detached the old script. I then forgot to attach the new one. When I am using that machine again I shall upload it.

Apologies. The version in code blocks here will not touch ships, so you might extrapolate that I had something else in mind.
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 29, 2016, 07:14:29 PM
Okay. I hadn't in mind that it would touch ships anyway. Perhaps I wasn't clear about that...
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 29, 2016, 08:53:43 PM
Well, the script as it stands will flip everything but Omnis.

However, it should be possible to safeguard or ignore whatever you wish, using the script as a base (when I get that machine out again to upload the file).
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 29, 2016, 09:13:20 PM
Here we are...

Note: You can place a Core carrying this over any unit, not just an info cache. Ships and particles are not deemed "units" by GetAllUnitsInRange, however. Use comments to remove any undesired functionality.

Perhaps I should check what happens if I try to turn Omnis to the red team... and would they still count against the build cap?
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 30, 2016, 01:29:10 AM
All right, we're making progress! The script did flip all the structures; I can even tell you what happens when the Omnis turn to the red team. I just... don't know how to turn that off. Despite the script, they did convert as well. Fascinatingly, I could still control the Omnis and they would still Lathe targets for me, but they would mire the land red instead of blue. I'm sure some map maker out there could use that to make some interesting maps.

In any case, I'll copy the script as I used it, just in case I botched one of the lines. Any idea why the Omnis flipped as well?

# --CacheFlip-- 10/29/2016 12:25:13 PM
$FinishMapOnCollection:0

once
ClearTraceLog
CurrentCoords 0 1 GetAllUnitsInRange ->Units
<-Units GetListCount 0 do
<-Units[I] ->UID
<-UID Self neq if
break
endif
loop
--Units
<-UID ->Cache
--UID

Self "main" "NONE" SetImage #Do not show up
Self ->Self
0 ->Self.UnitLatheTargets #Do not lathe
0 ->Self.UnitIsEnemy #Do not consider this opposition
0 ->Self.UnitMissionGoal
endonce

<-Cache.UnitIsDestroyed if
@MakeEnemy
<-FinishMapOnCollection if
WinMission
endif
Self 0 DestroyUnit #This Core has no further use when the cache is finished with.
endif

:MakeEnemy #[-] Turns all units to the enemy side.
CurrentCoords 9999 1 GetAllUnitsInRange ->Units
<-Units GetListCount 0 do
<-Units[I] GetUnitType "OMNI" neq if #Spare the Omnis, better hope you brought an "Omni Reactors" upgrade to the table.
<-Units[I] ->Unit
1 ->Unit.UnitIsEnemy
#<-Unit <-Unit GetUnitType Trace2
endif
loop
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 30, 2016, 02:21:50 AM
It's not impossible that where it says "OMNI" it needs to say "Omni". If you look at that section, you will see that I have attempted to exclude them based on GetUnitType. However, PRPL seems to differ from CRPL in that it does not return strings in "ALL CAPS", rather in either "Cobracase" or "CamelCase" (I don't recall a multi-word string return, so I cannot yet tell which). I assumed that the all-caps CRPLish form would work, but it seems to be otherwise.

I'll test:

(Edit): Yes, changing that does make it work. I'm now curious about the behaviour w.r.t. Emergent or particles. More testing to do.

(Edit): It seems that it is only the lathe and controls which remain loyal to the player. Enemy Omnis find particles and Emergent harmless. Omnis also remain counted toward the build limit. Box select fails, but doubleclick and normal click work to select them. Standard destruction methods work, the button isn't even hidden.
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 30, 2016, 03:23:18 PM
Worked like a charm! Mission is complete. If you're curious how your script turned out, here's the link (https://knucklecracker.com/forums/index.php?topic=22201.0) to the mission. I don't know if I gave sufficient warning for the cache or not, but we'll see how it goes. Thanks everyone for all your help. It's really appreciated!
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 30, 2016, 10:20:31 PM
As noted by some people playing, the script grabs the ship pickups and the amp gem factory, making it impossible to use them if the cache was grabbed early. GoodMorning, the only things that need to be selected are the cannons, energy sources, and emitters. If you can adjust the script for that, that would be awesome.
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 30, 2016, 10:33:24 PM
I encourage you to fix it yourself. In the section where you changed "OMNI" to "Omni", you will see that the line in question reads: <-Units[I] GetUnitType "Omni" neq if

What is required is to change this to something like:

<-Units[I] GetUnitType ->Type
<-Type "EnergyMine" eq
<-Type "TiconDefence" eq or
<-Type "Emitter" eq or if


I do not recall the exact names needed, however. If you can fill them in, good. I won't have time to test them for a while, I think.
Title: Re: Flipping with PRPL
Post by: GameGlitch on October 31, 2016, 08:34:27 AM
I'll give it a shot, and I'll let you know how things turn out.
Title: Re: Flipping with PRPL
Post by: GoodMorning on October 31, 2016, 08:42:00 AM
Placing this into a script could assist:


once
    CurrentCoords 9999 0 GetAllUnitsInRange ->Units
    <-Units GetListCount 0 do
        <-Units[I] ->Unit
        <-Unit <-Unit GetUnitType Trace2
    loop
endonce


It will give the type strings of everything on the map when the script first runs.

For some reason, even cannon shots and missiles were found last time I did something similar.
Title: Re: Flipping with PRPL
Post by: Oblivion on October 31, 2016, 06:40:38 PM
Cannon shots and missiles are considered units?