Basic interactive plant script part 2

Introduction
This plant script uses a few basic variables and is coded so that creatures can push, pull or hit the plant, with the appropriate stimulus attached so that the creature is rewarded for playing with the plant. It follows on from the Basic interactive plant script, and adds more features to the script discussed there. The plant itself will grow and ungrow wherever it lands, and will die if it does not grow on soil or is hit to death. The plant will give a piece of food when played with by norns or the hand depending on if you're running C3 standalone (cheese) or a docked or DS standalone game (peaking pie). This plant's growth script does not use subroutines, and instead, relies on valid logic statements. It's useful to use the CAOS Tool or another highlighting tool because they can make the CAOS syntax easier to read.

CAOS2PRAY
CAOS2PRAY is a feature included with RProgrammer's Jagent which allows the coder to not have to code a separate PRAY file in their agents. This chunk of code goes at the top of the COS file, and when it is dragged and dropped onto Monk (also part of the Jagent suite), compiles the cos file, with its dependent sprite file, into an agent that will be easy for everyone to install and play with. For more details on CAOS2PRAY, see CAOS2PRAY: An Easier Way by Amaikokonut.

**CAOS2PRAY *# Pray-File "BasicInteractivePlant.agents" *# C3-Name "Basic Interactive Plant C3" *# DS-Name "Basic Interactive Plant DS" *# attach sharmflower.c16 *# desc = "A basic plant that grows and ungrows, and creatures can interact with to produce food. Injects into the C3 Norn Terrarium or the DS Norn Meso." *# Agent Animation File = "sharmflower.c16" *# Agent Animation String = "0 1 2 3 4 5 4 3 2 1 255" *# Agent Sprite First Image = 0 *# Agent Animation Gallery = "sharmflower" *# Web URL = "creatures.wiki" *# Web Label = "Creatures Wiki"

Install Script
inst reps 5 new: simp 2 4 5005 "sharmflower" 6 0 rand 200 6000 Note that the ATTR for this plant is 196, not 192: the 4 means that the hand can activate it. attr 196 bhvr 11 setting a range of 100 for smart vending abilities rnge 100 elas 0 setv ov00 0 setv ov99 0 This will run every 15 to 50 seconds. tick rand 300 1000 Check the engine and move it into the world - adapted from Hausmouse's Learn to PRAY. * Which game engine is it? doif gnam eq "Docking Station" A random X-location between 597 and 1721 (inclusive). setv va00 rand 597 1721 A constant Y-location of 8904. setv va01 8904 doif tmvt va00 va01 eq 1 mvto va00 va01 else mvsf va00 va01 endi elif gnam eq "Creatures 3" Using TMVT and a DOIF-ENDI to test whether it can move into the C3 norn terrarium, choosing a random X-location between 1740 and 2740, but a constant Y-location (674) to move to. doif tmvt rand 1740 2740 674 eq 1 mvto rand 1740 2740 674 else mvsf rand 1740 2740 674 endi endi repe

Push Script
Stimulating the creature who pushed the plant with stimulus # 84: played with friendly plant, and triggering script #1000 in the plant. *push script scrp 2 4 5005 1 stim writ from 84 1 mesg writ ownr 1000 endm

Pull Script
Stimulating the creature who pulled the plant with stimulus # 84: played with friendly plant, and triggering script #1000 in the plant. *pull script scrp 2 4 5005 2 stim writ from 84 1 mesg writ ownr 1000 endm

Timer Script
*timer script scrp 2 4 5005 9 *soil check doif rtyp room targ = 5 or rtyp room targ = 6 or rtyp room targ = 7 *Grow UP 		doif ov00 eq 0 doif pose lt 5 setv va00 pose addv va00 1 pose va00 else *remain in a mature pose, add to age counter. addv ov99 1 *Check game name to see if there are too many peakingpies/cheeses touching. doif gnam eq "Docking Station" inst etch 2 11 7 doif targ = null mesg writ ownr 1000 endi next elif gnam eq "Creatures 3" etch 2 11 2 doif targ = null mesg writ ownr 1000 endi next slow endi *you've been mature for too long now, prepare to become immature. doif ov99 eq 50 setv ov00 1 *MESG the vend script, starting off the vend routine. mesg writ ownr 1000 endi endi *grow DOWN doif ov00 eq 1 doif pose gt 0 setv va00 pose subv va00 1 pose va00 else *Reset plant setv ov99 0 setv ov00 0 endi endi endi *if you didn't land on soil else kill ownr endi endm

Hit Script
Very similar to the hit script in the Basic interactive plant script, except this plant can be smushed to death if it is hit while it is at its most vulnerable. If you allow the plant to die this way, it would be good to include a vendor with the plant so that people can bring it back!

*Hit script scrp 2 4 5005 3 stim writ from 84 1 *this makes sure that the plant itself is targeted to change pose. targ ownr *the plant grows DOWN if it is hit. doif pose gt 0 setv va00 pose subv va00 1 pose va00 *plant can be smushed to death elif pose eq 0 kill ownr endi endm

Script 1000: Custom Vending Script
Just a reminder: if you create your own food item instead of using the official peaking pie/cheese, you don't need to bother checking if the game is C3 or DS. (You just need to make sure the food sprites, catalogues, sounds and scripts are included with the plant.) The following is very similar to the script used in the Making a Smart Vendor tutorial. Note the liberal use of TARG OWNR after the ESEE and SIMP commands are completed.

scrp 2 4 5005 1000 lock doif gnam eq "Docking Station" setv va66 0 esee 2 11 7 addv va66 1 next targ ownr elif gnam eq "Creatures 3" setv va66 0 esee 2 11 2 addv va66 1 next targ ownr endi doif va66 le 2 setv va00 posx setv va01 post doif gnam eq "Docking Station" inst new: simp 2 11 7 "ds empathic vendor" 3 42 425 attr 195 bhvr 48 perm 64 elas 30 accg 5 fric 100 mvsf va00 va01 velo rand -5 10 rand 1 20 emit 8 .5 tick 120 slow targ ownr elif gnam eq "Creatures 3" inst new: simp 2 11 2 "infinite_cheese_machine" 2 44 8000 attr 195 bhvr 48 perm 64 elas 40 accg 10 aero 5 fric 100 mvsf va00 va01 velo rand -5 10 rand 1 20 setv ov61 30 emit 8 0.35 slow targ ownr endi endi unlk endm

Removal Script
This simply counts through all the objects in the world with that class number, removes them, and then removes the scripts that belong to that class number. It's important to double-check that the class numbers here match the class numbers you've been using all along, and make sure that all SCRPs in the object have a corresponding scrx. If the class numbers here do not match the ones you've been using, you might accidentally delete some other object in the player's world, or silently delete another object's scripts, which would be hard for someone to fix!

rscr enum 2 4 5005 kill targ next scrx 2 4 5005 1 scrx 2 4 5005 2 scrx 2 4 5005 9 scrx 2 4 5005 3 scrx 2 4 5005 1000

Whole Script
**CAOS2PRAY
 * Pray-File "BasicInteractivePlant.agents"
 * C3-Name "Basic Interactive Plant C3"
 * DS-Name "Basic Interactive Plant DS"
 * attach sharmflower.c16
 * desc = "A basic plant that grows and ungrows, and creatures can interact with to produce food. Injects into the C3 Norn Terrarium or the DS Norn Meso."
 * Agent Animation File = "sharmflower.c16"
 * Agent Animation String = "0 1 2 3 4 5 4 3 2 1 255"
 * Agent Sprite First Image = 0
 * Agent Animation Gallery = "sharmflower"
 * Web URL = "creatures.wiki"
 * Web Label = "Creatures Wiki"

inst reps 5 new: simp 2 4 5005 "sharmflower" 6 0 rand 200 6000 attr 196 bhvr 11 rnge 100 elas 0 setv ov00 0 setv ov99 0 tick rand 300 1000 doif gnam eq "Docking Station" setv va00 rand 597 1721 setv va01 8904 doif tmvt va00 va01 eq 1 mvto va00 va01 else mvsf va00 va01 endi elif gnam eq "Creatures 3" doif tmvt rand 1740 2740 674 eq 1 mvto rand 1740 2740 674 else mvsf rand 1740 2740 674 endi endi repe
 * setting a RANGE of 100 for smart vending abilities
 * Check the engine and move it into the world - adapted from Hausmouse's Learn to PRAY.
 * Which game engine is it?
 * X
 * Y
 * Norn Terrarium

scrp 2 4 5005 1 stim writ from 84 1 mesg writ ownr 1000 endm
 * push script

scrp 2 4 5005 2 stim writ from 84 1 mesg writ ownr 1000 endm
 * pull script

scrp 2 4 5005 9 doif rtyp room targ = 5 or rtyp room targ = 6 or rtyp room targ = 7 doif ov00 eq 0 doif pose lt 5 setv va00 pose addv va00 1 pose va00 else addv ov99 1 doif gnam eq "Docking Station" inst etch 2 11 7 doif targ = null mesg writ ownr 1000 endi next elif gnam eq "Creatures 3" etch 2 11 2 doif targ = null mesg writ ownr 1000 endi next slow endi doif ov99 eq 50 setv ov00 1 mesg writ ownr 1000 endi endi doif ov00 eq 1 doif pose gt 0 setv va00 pose subv va00 1 pose va00 else setv ov99 0 setv ov00 0 endi endi endi else kill ownr endi endm
 * timer script
 * soil check
 * Grow UP
 * remain in a mature pose, add to age counter.
 * Check game name to see if there are too many peakingpies/cheeses touching.
 * you've been mature for too long now, prepare to become immature.
 * MESG the vend script, starting off the vend routine.
 * grow DOWN
 * Reset plant
 * if you didn't land on soil

scrp 2 4 5005 3 stim writ from 84 1 targ ownr doif pose gt 0 setv va00 pose subv va00 1 pose va00 elif pose eq 0 kill ownr endi endm
 * Hit script
 * this makes sure that the plant itself is targeted to change pose.
 * the plant grows DOWN if it is hit.
 * plant can be smushed to death

scrp 2 4 5005 1000 lock doif gnam eq "Docking Station" setv va66 0 esee 2 11 7 addv va66 1 next targ ownr elif gnam eq "Creatures 3" setv va66 0 esee 2 11 2 addv va66 1 next targ ownr endi doif va66 le 2 setv va00 posx setv va01 post doif gnam eq "Docking Station" inst new: simp 2 11 7 "ds empathic vendor" 3 42 425 attr 195 bhvr 48 perm 64 elas 30 accg 5 fric 100 mvsf va00 va01 velo rand -5 10 rand 1 20 emit 8 .5 tick 120 slow targ ownr elif gnam eq "Creatures 3" inst new: simp 2 11 2 "infinite_cheese_machine" 2 44 8000 attr 195 bhvr 48 perm 64 elas 40 accg 10 aero 5 fric 100 mvsf va00 va01 velo rand -5 10 rand 1 20 setv ov61 30 emit 8 0.35 slow targ ownr endi endi unlk endm

rscr enum 2 4 5005 kill targ next scrx 2 4 5005 1 scrx 2 4 5005 2 scrx 2 4 5005 9 scrx 2 4 5005 3 scrx 2 4 5005 1000
 * REMOVE ME

Moving On

 * To simulate ungrowing to death, an additional, pure black, sprite could be added to the C16 file as sprite #0 to allow the plant to vanish, and the number used to note the peak of the plant's growth would also need to be changed.


 * If the whole agent was classed as a flower (genus number 7), it would be worthwhile adding a pollination script (303) for the bees, although this would make it compete with the foxglove in the C3 Norn Terrarium. A very simple one would be to just MESG WRIT the vending script:

scrp 2 7 5005 303 mesg writ ownr 1000 endm


 * As discussed earlier, MESG WRIT OWNR 1000 could be used to elicit food from the plant on pollination when smart vending is in script #1000.


 * Make a vendor to vend the plant, or add a seed object to the plant.


 * If a seed is used, a doif check using the range would be needed to make sure the plants did not grow too thickly, by killing the plant if there are too many close by.


 * See the fungi.cos fruit timer script (scrp 2 8 5 9) for an object that uses similar logic statements to grow, wait and then grow old and die, rather than grow and ungrow forever as this example plant does.


 * Follow the Creating a Metaroom tutorial, change the coordinates of the installation script (using the keyboard shortcut CTRL + SHIFT + X), and use the CAOS2PRAY "LINK" command (as described by Pilla in Make an .agents file) to include the plant in the new metaroom.


 * See Gardenboxifying a Traditional Plant to make this plant compatible with the Garden Box.