Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: Ondrejoda on June 11, 2017, 10:48:24 AM

Title: I was trying to make a custom unit...
Post by: Ondrejoda on June 11, 2017, 10:48:24 AM
I was trying to make a custom unit, but i just found a problem. I am trying to find a way how to detect stored energy or AC, but I dont know the command. Could someone help me?
Title: Re: I was trying to make a custom unit...
Post by: Builder17 on June 11, 2017, 12:09:04 PM
Self CONST_AMMO GetUnitAttribute This gets current ammo of CRPLCORE script is in

Self CONST_AMMOAC GetUnitAttribute This gets current AC of CRPLCORE script is in

If you want get some other unit ammo/AC change Self to UID of unit

Also it would be nice to see that script you are making, just curious
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 11, 2017, 02:38:55 PM
Thank you, but then how do i reduce the stored ammount of AC/ammo?
Code:
Self CONST_AMMOAC GetUnitAttribute
if
   CurrentCoords -10 AddCreeper
   Delay 15
endif
Title: Re: I was trying to make a custom unit...
Post by: Nicant on June 11, 2017, 03:00:57 PM
To modify attributes, all you need to do is getunitattribute to setunitattribute and put a value in.
Here are some examples...


Self CONST_AMMO 10 SetUnitAttribute

Self CONST_AMMOAC 5 SetUnitAttribute


The 10 and 5 are where you place your value to change the attribute. This link may be helpful to you... http://knucklecracker.com/wiki/doku.php?id=crpl:crplreference (http://knucklecracker.com/wiki/doku.php?id=crpl:crplreference)
It shows every command you can use in CRPL and tells you how to use it too!
Title: Re: I was trying to make a custom unit...
Post by: Builder17 on June 11, 2017, 03:21:11 PM
What should this custom unit do?
Knowing it could help us

There should be comparator before if

Self CONST_AMMOAC GetUnitAttribute 10 gte
if
   
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 11, 2017, 03:21:40 PM
I was thinking about a unit, that you put in AC, and it makes AC around, just for a test.
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 11, 2017, 03:35:19 PM
And acually, can i make a unit, that will work like a Energy to AC Converter, or a different type of a reactor?
Title: Re: I was trying to make a custom unit...
Post by: Nicant on June 11, 2017, 04:26:35 PM
Yes, that's possible!
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 11, 2017, 05:05:38 PM
And how can I make that unit?
Title: Re: I was trying to make a custom unit...
Post by: Nicant on June 11, 2017, 05:42:08 PM
Heres the code for that unit! It will take in ammo and produce AC! I had nothing to do so i made it for you! You can even use this for your other units as a template
# EnergyToAC.crpl
# Created on: 6/11/2017 5:24:08 PM
# ------------------------------------------

once
Self CONST_MAXAMMO 25 SetUnitAttribute #Sets maximum ammo
Self CONST_AMMO 0 SetUnitAttribute #Sets ammo to 0
Self CONST_CONNECTABLE True SetUnitAttribute #Makes sure unit can connect to collectors
Self CONST_CANREQUESTAMMO True SetUnitAttribute #Makes sure unit can request ammo packets
Self CONST_SHOWAMMOBAR True SetUnitAttribute #Shows the ammo bar for the unit
0 SetTimer0 #Sets timer0 to 0 Timers are more useful than delays because they do not "freeze" the core
endonce

GetTimer0 eq0 if #Wait till the timer is at 0
Self CONST_AMMO GetUnitAttribute ->Ammo #Check how much ammo it has
<-Ammo 1 gte if #Check and see if there is atleast 1 ammo in it's ammo store
<-Ammo 1 sub ->Ammo #Subtract the total ammo supply by 1
CurrentCoords -10 AddCreeper #Makes anti creeper positive numbers for creeper, negative numbers for anti-creeper.
Self CONST_AMMO <-Ammo SetUnitAttribute #Sets the ammo to the amount of ammo that it has from the subtractor
30 SetTimer0 #Sets the timer to wait for 1 second. 30 frames = 1 second
endif
endif
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 11, 2017, 06:08:53 PM
Thank you all for the code, it is all working as it should.
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 01:35:11 AM
But wait, can i make a different type of a reactor?
Title: Re: I was trying to make a custom unit...
Post by: GoodMorning on June 12, 2017, 01:44:33 AM
Producing energy is difficult. Spawning standard Reactors or running the power through Siphons is the only really workable means, and both have inherent flaws.
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 01:47:53 AM
Welll, could you check out the other topic for the chimera cannons?
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 05:05:16 AM
Well, can i make a custom "AC Bertha", that the AC Bertha will have Auto Target for creeper, and when the AC bullet lands,it will make AC arround it.
Is it possible?
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 05:09:14 AM
And can i make a Creeper Bertha, what will work the same as the AC Bertha, too?
Title: Re: I was trying to make a custom unit...
Post by: GoodMorning on June 12, 2017, 05:27:48 AM
It's possible, but the effect can vary.

An AC Bertha would likely operate by flattening Creeper in the area, much as a normal Bertha, and then placing AC where it was. There's also the "titanic AC payload" option.

You can also have it operate as a conversion.
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 05:31:46 AM
And, could someone give me the two parts (the body and the barrel) of the sprayer?
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 05:33:53 AM
GoodMorning, could you give me the code for the first idea of the AC Bertha? (the first idea is the flattering and then putting down AC)
Title: Re: I was trying to make a custom unit...
Post by: GoodMorning on June 12, 2017, 06:01:19 AM
Well, I don't have scripts on hand, but it is possible.

I think you should talk to Nicant, who has built a Sleeper Bertha. The following commands may prove helpful:

http://knucklecracker.com/wiki/doku.php?id=crpl:docs:damagecreeper
http://knucklecracker.com/wiki/doku.php?id=crpl:docs:shortestangle
http://knucklecracker.com/wiki/doku.php?id=crpl:docs:addcreeper
http://knucklecracker.com/wiki/doku.php?id=crpl:docs:getdeepestcreepercell
Title: Re: I was trying to make a custom unit...
Post by: Nicant on June 12, 2017, 07:05:28 AM
If you want images for units, then you can get most of them here: http://knucklecracker.com/wiki/doku.php?id=crpl:custom_image_repository (http://knucklecracker.com/wiki/doku.php?id=crpl:custom_image_repository)
Or here: http://knucklecracker.com/wiki/doku.php?id=cw3:units:concepts (http://knucklecracker.com/wiki/doku.php?id=cw3:units:concepts)


Now making a working enemy Bertha is a bit difficult, but once one is made, you could reuse the code and make other turret-like units. Along with the Bertha you would also need a script for the projectile. I will make a rough script later that will help you form together a Bertha.
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 08:03:07 AM
I must say that the idea to be on the forum wasnt a bad idea... Anyways, thank you!
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 08:27:04 AM
Well, i just put out the "Bertha" idea, but i found a custom image (the Scout image) and instead of targetin the Creeper/Units, it will find the Higest ammount of Creeper (GetDeepestCreeperCell), then it will do a blast (DamageCreeper) and then it will deploy AC/Creeper (AddCreeper). But I didnt found a solution for the unit to come back to the units and reload. Maby I could locate the Units and Queue the movement..?
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 09:06:59 AM
Wait, how do I make a code, that it makes CRPLCores with a different code?
Title: Re: I was trying to make a custom unit...
Post by: GoodMorning on June 12, 2017, 09:30:02 AM
The approximate procedure is to write each script, and attach them to different Cores.

You ca also attach the same script to multiple Cores. Or multiple scripts to the same Core.
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 10:01:06 AM
Wait, I did finally manage to make it! I will upload the image and the code! (Put the Bertha.crpl to the CRPLCore, and dont attact the Bullet.crpl to anyting, just leave it there, put on the CRPLCore any image you want... :D
# Bertha.crpl
# Created on: 6/12/2017 2:42:36 PM
# ------------------------------------------

once
Self CONST_MAXAMMO 250 SetUnitAttribute #Sets maximum ammo
Self CONST_AMMO 0 SetUnitAttribute #Sets ammo to 0
Self CONST_CONNECTABLE True SetUnitAttribute #Makes sure unit can connect to collectors
Self CONST_SHOWAMMOBAR True SetUnitAttribute #Shows the ammo bar for the unit
0 SetTimer0 #Sets timer0 to 0 Timers are more useful than delays because they do not "freeze" the core
endonce

GetTimer0 eq0 if #Wait till the timer is at 0
Self CONST_AMMO GetUnitAttribute ->Ammo #Check how much ammo it has
<-Ammo 250 gte if #Check and see if there is atleast 100 ammo in it's ammo store
<-Ammo 250 sub ->Ammo #Subtract the total ammo supply by 100
CreateUnit("CRPLCore" CurrentCoords) ->Bullet
AddScriptToUnit(<-Bullet "Bullet.crpl")
Self CONST_AMMO <-Ammo SetUnitAttribute #Sets the ammo to the amount of ammo that it has from the subtractor
endif
endif

# Bullet.crpl
# Created on: 6/12/2017 3:10:38 PM
# ------------------------------------------

GetDeepestCreeperCell SetCurrentCoords
CurrentCoords -2500 AddCreeper
Destroy(self 3)



Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 01:52:59 PM
And, I just found a small problem. The problem is that when the bullet explodes, it leaves a Power Zone. Is there a command to turn off the Power Zone after destruction?
Title: Re: I was trying to make a custom unit...
Post by: Builder17 on June 12, 2017, 02:43:08 PM
Self CONST_CREATEPZ FALSE SetUnitAttribute

In Bullet.crpl there is one zero too much in creeper amount -2500?
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 02:44:24 PM
Dont matter about the number... I just made it SUUUUUUUUUUUUUUUUUUUUUUUUUUUUPER OP....
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 12, 2017, 03:32:30 PM
And, is it possible to locate a CRPLCore?
Title: Re: I was trying to make a custom unit...
Post by: Nicant on June 12, 2017, 03:47:05 PM
Yes, you can use GetCoresWithVar
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 13, 2017, 08:48:48 AM
And, is it possible to make a code that when you hold down the right buttonon the mouse, the CRPLCore will be right on the location of the mouse, and, when I will stop holding the right button on the mouse, the CRPLCore will stop moving?
Title: Re: I was trying to make a custom unit...
Post by: GoodMorning on June 13, 2017, 09:27:51 AM

1 GetMouseButton if #Right mouse button is down
GetMousePosition ->MousePX ->MousePY
Self CONST_PIXELCOORDX <-MousePX SetUnitAttribute
Self CONST_PIXELCOORDY <-MousePY SetUnitAttribute
endif


This should work.
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 13, 2017, 10:05:16 AM
And, can I set the CurrentCoords of a CRPLCore to a different CRPLCore?
Title: Re: I was trying to make a custom unit...
Post by: GoodMorning on June 13, 2017, 10:19:01 AM
Yes, provided you have the UID of the other Core.


Self CONST_PIXELCOORDX <-Other CONST_PIXELCOORDX GetUnitAttribute SetUnitAttribute

...and similarly for Y.
Title: Re: I was trying to make a custom unit...
Post by: Ondrejoda on June 13, 2017, 10:52:01 AM
Sorry, but the unit what will move is just going to the Down Left corner...