Freezing creeper in a ring?

Started by ViperZer0, October 10, 2015, 11:04:53 PM

Previous topic - Next topic

ViperZer0

Hello there everyone! I've been working on a really neat script that creates creeper in a ring around the tower.

# DankMemes.crpl
# Created on: 10/7/2015 1:13:28 PM
# ------------------------------------------
once
$r:10
0 ->val
endonce

<-val cos <-r mul CurrentX add <-val sin <-r mul CurrentY add 10 SetCreeper
<-val cos -1 mul <-r mul CurrentX add <-val sin -1 mul <-r mul CurrentY add 10 SetCreeper
<-val 1 add ->val


Now what I'd like to do is freeze that creeper so it creates a solid circle around the tower of creeper. When the tower gets destroyed, I want the creeper to suddenly unfreeze and act normal. I'd like all other creeper to be unaffected.

If you don't understand the code above but would like to, it works like this:
I used polar coordinate plane to define a circle with (r, theta) where r is a distance and theta is an angle.

then I converted it to Cartesian and centered it around the tower.

Unrelated but something I'd like to know: Can you only attach scripts to CRPLCore towers or can I attach them to any unit?

Builder17

Nice looking script. You cannot attach scripts into any other units than CRPL cores , but if you create new emitter in script , you can use SetScriptVar to give it amount and interval , if you didn't knowed this.  :)

Lost in Nowhere

For the field, it would be better to just use a "do" loop, like such:
This code might not work. You've been warned.
:destroyed
    0 @SetField

:awake
    1 @SetField

:SetField
->sf
2 pi <-r mul mul 0 do
    I <-r div ->angle
    <-angle cos <-r mul CurrentX add <-angle sin <-r mul CurrentY add <-sf 0 SetPinFieldCell
loop

Just stick this in at the end of your script.
Fields don't behave too nicely; they don't persist across saves. It isn't terribly hard to work around this, though.
Don't die! :)

ViperZer0

#3
What exactly does that code do? I'm still pretty new at CPRL and I don't quite understand it.
It looks like radians or something, which I don't understand at all

ViperZer0

Also, this doesn't appear to be working.

This is what I have

# Ring.crpl
# Created on: 10/10/2015 7:07:02 PM
# ------------------------------------------

once
$r:10
endonce

<-val cos <-r mul CurrentX add <-val sin <-r mul CurrentY add 10 SetCreeper
<-val cos -1 mul <-r mul CurrentX add <-val sin -1 mul <-r mul CurrentY add 10 SetCreeper
<-val 1 add ->val

:destroyed
    0 @SetField

:awake
    1 @SetField

:SetField
->sf
2 pi <-r mul mul 0 do
    I <-r div ->angle
    <-angle cos <-r mul CurrentX add <-angle sin <-r mul CurrentY add <-sf 0 SetPinFieldCell
loop

Karsten75

In Virgil's Credits map, there is a room of "frozen" creeper. Expecting the CRPL in that map may tell you what he did that works.

ViperZer0

Quote from: Karsten75 on October 11, 2015, 10:57:14 AM
In Virgil's Credits map, there is a room of "frozen" creeper. Expecting the CRPL in that map may tell you what he did that works.

Boom, found it. Conveniently named FrozenBlock.crpl

# FrozenBlock.crpl
# Created on: 9/11/2013 10:24:45 AM
# ------------------------------------------


$width:10
$height:10

$creeper:40


once

CurrentCoords ->y ->x

do(<-height 0)

do(<-width 0)

SetCreeper(<-x add(I) <-y add(J) <-creeper)

loop
loop
endonce

:Awake

CurrentCoords ->y ->x

do(<-height 0)

do(<-width 0)

SetPinFieldCell(<-x add(I) <-y add(J) TRUE TRUE)
loop
loop



   

ViperZer0

Thank you all so much for your help! Everything works as planned now! The problem was that the :awake function is only called when the game starts, so I had to exit the map and enter again in order for it to work. Again, thank you all for your advice and assistance!