Knuckle Cracker

Particle Fleet => Map Makers, Ship Builders, and Coders => Topic started by: mirror corparation on November 09, 2016, 10:28:07 AM

Title: Custom Modules Problem
Post by: mirror corparation on November 09, 2016, 10:28:07 AM
I've got a few problems  :-[ with one of my scripts, and I wondered if someone could help me with them:
the script is meant to turn every enemy particulate into a friendly one

once
# Set up image(s). You NEED to set image layer to Ships, otherwise your module will render behind ships.
Self "main" "CustomSomething" SetImage
Self "main" "Ships" SetImageLayer
Self "main" 1 SetImageOrder
Self "main" 1 1 SetImageScale
Self "ShipModule.prpl" "Ship" GetScriptVar ->Ship
<-Ship.ShipIsEnemy ->IsEnemy
-1 ->target
endonce

#The heading of the ship the module is attached to.
Self "ShipModule.prpl" "ShipAngle" GetScriptVar ->ShipAngle

#The amount the heading has changed in the last frame (in radians)
Self "ShipModule.prpl" "delta" GetScriptVar ->Delta

#Whether the module exists.
#0 = hull destroyed
#1 = under construction
#2 = built
Self "ShipModule.prpl" "exist" GetScriptVar ->Exist

#If the module is destroyed, make it invisible and prevent the rest of the script from running.
<-Exist eq0 if
self "main" 0 0 0 0 SetImageColor
return
endif

#make module align with ship
self "main" <-ShipAngle SetImageRotation

IsPaused if
return
endif

<-Exist 1 eq if
# if under construction, make the module semi transparent.
# also use this for things like resetting turret rotation or cooldown if the module is destroyed and rebuilt
self "main" 255 255 255 128 SetImageColor
else
self "main" 255 255 255 255 SetImageColor
# I don't know of a way to read the Fire Multiple property on some enemy ships, which increases their fire rate.
# Instead, this script pretends that all enemy ships have amp gems.
<-Ship.ShipHasAmp <-IsEnemy or ->GemPresent
#code your module's abilities here
<-GemPresent 1 eq if
20 ->range
else
30 ->range
endif
CurrentCoords <-range 0 <-IsEnemy GetParticlesInRange ->particles
<-particles GetListCount 0 do
<-particles[I] GetParticlePosition <-ShipAngle <-particles[I] GetParticleHealth 2 mul SetParticleHealth <-particles[I] GetParticleMaxSpeed SetParticleMaxSpeed <-IsEnemy CreateParticle ->new
1 ->new.ParticleDestroyAtEdge
120 ->new.ParticleMaxAge

#<-NewParticle <-x ->SetParticleCoordX
#<-NewParticle <-y ->SetParticleCoordY
#<-NewParticle <-particles[I] GetParticleMaxSpeed SetParticleMaxSpeed
#<-NewParticle <-particles[I] GetParticleHealth 2 mul SetParticleHealth
#<-NewParticle 1 SetParticleDestroyAtEdge
#<-NewParticle 120 SetParticleMaxAge

loop

endif

:awake
# I dunno, I like to have all my scrpts OWP and exit partway through, I doubt it's caused by the brain chip.
1 OperateWhilePaused

;)
Title: Re: Custom Modules Problem
Post by: Karsten75 on November 09, 2016, 10:32:30 AM
Quote from: mirror corparation on November 09, 2016, 10:28:07 AM
I've got a few problems  :-[ with one of my scripts, and I wondered if someone could help me with them:
the script is meant to turn every enemy particulate into a friendly one

Usually helps if you say what the problems appear to be... :)
Title: Re: Custom Modules Problem
Post by: mirror corparation on November 09, 2016, 10:38:52 AM
 :o sorry, currently it does nothing on my ship after its build. it just sits there. I can only think of two possible problems:
- can't detect particulate in range due to some problems with the GetParticulateInRange function.
- Doesn't spawn friendly particulates when an enemy particulate is found due to some problems with the second line.

EDIT: I found one problem, no idea how to solve it though: it doesn't detect any particulate in a range of 20.
Title: Re: Custom Modules Problem
Post by: Sorrontis on November 09, 2016, 10:54:24 AM
you should provide the map it is on too. would make it easier for us to test :)
Title: Re: Custom Modules Problem
Post by: mirror corparation on November 09, 2016, 11:06:54 AM
here it is.
I've solved most of the problem now, only thingy left is to give the particulate the right direction and health.
some of the stupid issues:
didn't remove SetParticleHealth and SetParticleMaxSpeed in the arguments
only things left to fix:
- make it work on enemy ships. (I've used a constant for now to make it work, but ideally, i would use a inverted IsEnemy var)
- as said above, fix the health and direction.
hope you'll help me some more ::)
Title: Re: Custom Modules Problem
Post by: Oblivion on November 09, 2016, 04:45:16 PM
But in which direction do you want them to go?
On an assumption I'll assume you want them to continue as they were when they were enemies, but atm, and I've tried, not sure if it possible to extract that information.
Title: Re: Custom Modules Problem
Post by: mirror corparation on November 10, 2016, 02:30:58 AM
as for now, the ship direction is fine, but I'm still having trouble with setting the health. its GetParticleHealth 2 mul as of now, and it doesn't work the way I want it to. (i want it to soak up half of the enemy particle with its health, and be left with the same health as the original particle)
Title: Re: Custom Modules Problem
Post by: GoodMorning on November 10, 2016, 02:38:51 AM
As an alternative (I do not recall if the command exists...)


0 ->ParticleUID.ParticleIsEnemy
Title: Re: Custom Modules Problem
Post by: Oblivion on November 10, 2016, 06:27:43 AM
Just a guess at what you're doing.

<-ParticuleUID GetParticleHealth ->ParticleHealth
<-ParticleHealth 2 mul ->NewHealth
<-ParticuleUID <-NewHealth SetParticleHealth
Title: Re: Custom Modules Problem
Post by: mirror corparation on November 10, 2016, 09:37:58 AM
Quote from: Oblivion on November 10, 2016, 06:27:43 AM
Just a guess at what you're doing.

<-ParticuleUID GetParticleHealth ->ParticleHealth
<-ParticleHealth 2 mul ->NewHealth
<-ParticuleUID <-NewHealth SetParticleHealth

yes, that's what I'm trying to do