Difference between revisions of "Full Lifecycle Plant script"
ScoobyGambit (talk | contribs) m (→Fruit eat) |
ScoobyGambit (talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 27: | Line 27: | ||
Installs 30 fruits in the DS norn meso, using the [[sprite]] file [[:File:Tutorial seed.c16|tutorial_seed.c16]]. | Installs 30 fruits in the DS norn meso, using the [[sprite]] file [[:File:Tutorial seed.c16|tutorial_seed.c16]]. | ||
− | inst | + | [[inst]] |
− | reps 30 | + | [[reps]] 30 |
− | new: simp 2 8 1000 "tutorial_seed" 1 0 4900 | + | [[new: simp]] 2 8 1000 "tutorial_seed" 1 0 4900 |
− | attr 195 | + | [[attr]] 195 |
− | bhvr 48 | + | [[bhvr]] 48 |
− | elas 30 | + | [[elas]] 30 |
− | fric 50 | + | [[fric]] 50 |
− | accg 3 | + | [[accg]] 3 |
− | mvsf rand 748 1550 9547 | + | [[mvsf]] rand 748 1550 9547 |
− | velo rand -10 10 rand -15 -20 | + | [[velo]] rand -10 10 [[rand]] -15 -20 |
− | tick rand 300 600 | + | [[tick]] rand 300 600 |
− | emit 6 0.3 | + | [[emit]] 6 0.3 |
* dormancy counter - reaches 0 and dies | * dormancy counter - reaches 0 and dies | ||
− | setv | + | [[setv]] [[ov]]72 rand 10 40 |
* max light to sprout | * max light to sprout | ||
setv ov80 1 | setv ov80 1 | ||
Line 47: | Line 47: | ||
* min nutrients to sprout | * min nutrients to sprout | ||
setv ov87 0 | setv ov87 0 | ||
− | repe | + | [[repe]] |
==Fruit timer script== | ==Fruit timer script== | ||
− | Fruit timer script - first checks there aren't too many fruits nearby, then checks if the fruit is in water, then tests the environment for light, heat and nutrients (and then if there are enough, the plant grows, using the [[:File:Sharmflower.c16|sharmflower.c16]] file) but if there aren't enough, the fruit goes dormant and eventually is | + | Fruit timer script - first checks there aren't too many fruits nearby, then checks if the fruit is in water, then tests the environment for light, heat and nutrients (and then if there are enough, the plant grows, using the [[:File:Sharmflower.c16|sharmflower.c16]] file) but if there aren't enough, the fruit goes dormant and eventually is [[kill]]ed. |
Line 67: | Line 67: | ||
[[unlk]] | [[unlk]] | ||
* if not being carried or falling | * if not being carried or falling | ||
− | doif fall eq 0 and carr eq null | + | doif [[fall]] eq 0 and [[carr]] eq null |
− | doif rtyp room targ eq 8 or rtyp room targ eq 9 | + | doif [[rtyp]] room [[targ]] eq 8 or rtyp [[room]] targ eq 9 |
kill ownr | kill ownr | ||
endi | endi | ||
* check environment to test whether can sprout | * check environment to test whether can sprout | ||
− | gsub envi | + | [[gsub]] envi |
* if don't survive envi test, go dormant | * if don't survive envi test, go dormant | ||
− | gsub dorm | + | [[gsub]] dorm |
endi | endi | ||
**environment test - grow if successful | **environment test - grow if successful | ||
− | subr envi | + | [[subr]] envi |
* light check | * light check | ||
− | doif prop room targ 1 le ov80 | + | doif [[prop]] room targ 1 le ov80 |
setv va00 1 | setv va00 1 | ||
endi | endi | ||
* heat check | * heat check | ||
− | doif prop room targ 2 le ov82 | + | doif prop [[room]] targ 2 le ov82 |
setv va01 1 | setv va01 1 | ||
endi | endi | ||
* nutrient check | * nutrient check | ||
− | doif prop room targ 4 ge ov87 | + | doif prop room [[targ]] 4 ge ov87 |
setv va02 1 | setv va02 1 | ||
endi | endi | ||
Line 94: | Line 94: | ||
* can I grow? | * can I grow? | ||
doif va00 eq 1 and va01 eq 1 and va02 eq 1 | doif va00 eq 1 and va01 eq 1 and va02 eq 1 | ||
− | gsub grow | + | [[gsub]] grow |
endi | endi | ||
− | retn | + | [[retn]] |
**growing into plant routine | **growing into plant routine | ||
− | subr grow | + | [[subr]] grow |
− | setv va00 posl | + | [[setv]] va00 [[posl]] |
− | setv va01 post | + | setv va01 [[post]] |
− | new: simp 2 4 1000 "sharmflower" 9 0 140 | + | [[new: simp]] 2 4 1000 "sharmflower" 9 0 140 |
− | attr 199 | + | [[attr]] 199 |
− | bhvr 43 | + | [[bhvr]] 43 |
− | elas 0 | + | [[elas]] 0 |
*OV00 - Plant state (0=growing, 1=fruiting, 2=dying, 3=picked) | *OV00 - Plant state (0=growing, 1=fruiting, 2=dying, 3=picked) | ||
setv ov00 0 | setv ov00 0 | ||
Line 120: | Line 120: | ||
**dormancy routine | **dormancy routine | ||
− | subr dorm | + | [[subr]] dorm |
doif pose lt 4 | doif pose lt 4 | ||
* make it invisible | * make it invisible | ||
Line 138: | Line 138: | ||
endi | endi | ||
endi | endi | ||
− | retn | + | [[retn]] |
endm | endm | ||
Line 317: | Line 317: | ||
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 the class numbers here, and make sure that all [[SCRP]]s in the object have a corresponding scrx. | 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 the class numbers here, and make sure that all [[SCRP]]s in the object have a corresponding scrx. | ||
− | rscr | + | [[rscr]] |
− | enum 2 8 1000 | + | [[enum]] 2 8 1000 |
− | kill targ | + | [[kill]] targ |
− | next | + | [[next]] |
enum 2 4 1000 | enum 2 4 1000 | ||
− | kill targ | + | kill [[targ]] |
next | next | ||
− | scrx 2 8 1000 9 | + | [[scrx]] 2 8 1000 9 |
scrx 2 4 1000 9 | scrx 2 4 1000 9 | ||
scrx 2 8 1000 12 | scrx 2 8 1000 12 | ||
Line 332: | Line 332: | ||
scrx 2 4 1000 3 | scrx 2 4 1000 3 | ||
scrx 2 4 1000 1000 | scrx 2 4 1000 1000 | ||
− | |||
− | |||
==Whole script== | ==Whole script== |
Revision as of 22:43, 1 January 2021
This is a CAOS tutorial in the form of an in-depth analysis of an agent.
Introduction
This plant script has a full lifecycle and is interactive for creatures. The fruit timer script uses subroutines to check the environment and determine whether it's ok to grow, but the plant itself uses valid logic statements to govern its' timer. It is 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, compiles the cos file, with its dependant 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 "fulllifecycleplant.agents" *# DS-Name "Full Lifecycle Plant" *# attach sharmflower.c16 *# attach tutorial_seed.c16 *# attach chwp.wav *# attach smit.wav *# desc = "A basic plant that grows, fruits and dies, and creatures can interact with." *# Agent Animation File = "sharmflower.c16" *# Agent Animation String = "5" *# Agent Sprite First Image = 5 *# Agent Animation Gallery = "sharmflower" *# Web URL = "creatures.wiki" *# Web Label = "Creatures Wiki"
Initial installation
Installs 30 fruits in the DS norn meso, using the sprite file tutorial_seed.c16.
inst reps 30 new: simp 2 8 1000 "tutorial_seed" 1 0 4900 attr 195 bhvr 48 elas 30 fric 50 accg 3 mvsf rand 748 1550 9547 velo rand -10 10 rand -15 -20 tick rand 300 600 emit 6 0.3 * dormancy counter - reaches 0 and dies setv ov72 rand 10 40 * max light to sprout setv ov80 1 * max heat to sprout setv ov82 1 * min nutrients to sprout setv ov87 0 repe
Fruit timer script
Fruit timer script - first checks there aren't too many fruits nearby, then checks if the fruit is in water, then tests the environment for light, heat and nutrients (and then if there are enough, the plant grows, using the sharmflower.c16 file) but if there aren't enough, the fruit goes dormant and eventually is killed.
scrp 2 8 1000 9 *fruit population check lock rnge 30 setv va66 0 esee 2 8 1000 addv va66 1 next targ ownr doif va66 gt 7 kill ownr endi unlk * if not being carried or falling doif fall eq 0 and carr eq null doif rtyp room targ eq 8 or rtyp room targ eq 9 kill ownr endi * check environment to test whether can sprout gsub envi * if don't survive envi test, go dormant gsub dorm endi
**environment test - grow if successful subr envi * light check doif prop room targ 1 le ov80 setv va00 1 endi * heat check doif prop room targ 2 le ov82 setv va01 1 endi * nutrient check doif prop room targ 4 ge ov87 setv va02 1 endi * can I grow? doif va00 eq 1 and va01 eq 1 and va02 eq 1 gsub grow endi retn
**growing into plant routine subr grow setv va00 posl setv va01 post new: simp 2 4 1000 "sharmflower" 9 0 140 attr 199 bhvr 43 elas 0 *OV00 - Plant state (0=growing, 1=fruiting, 2=dying, 3=picked) setv ov00 0 *OV99 - an age counter, counts the amount of time spent in a mature state. setv ov99 0 doif tmvt va00 va01 eq 1 mvto va00 va01 else mvsf va00 va01 endi tick rand 200 1000 kill ownr retn
**dormancy routine subr dorm doif pose lt 4 * make it invisible attr 16 over endi * reduce dormancy counter subv ov72 1 * if been dormant too long, die doif ov72 le 0 doif room targ ne -1 altr room targ 3 0.1 altr room targ 4 0.1 kill ownr else kill ownr endi endi retn endm
Plant timer script
****plant timer scrp 2 4 1000 9 **OV00 is state *0=growing *1=fruiting *2=dying *3=picked
*increase age addv ov01 1
**growing doif ov00 eq 0 doif pose lt 5 setv va00 pose addv va00 1 pose va00 else * if in right pose and old enough, fruit doif ov01 ge 20 setv ov00 1 stop endi endi endi
**fruiting doif ov00 eq 1 doif pose lt 5 setv va00 pose addv va00 1 pose va00 else * create a fruit inst setv va00 posl setv va01 post new: simp 2 8 1000 "tutorial_seed" 1 0 4900 attr 195 bhvr 48 elas 30 fric 50 accg 3 doif tmvt va00 va01 <> 1 kill targ targ ownr setv ov00 2 stop endi doif tmvt va00 va01 = 1 mvto va00 va01 else mvsf va00 va01 endi velo rand -10 10 rand -15 -20 tick rand 300 600 emit 6 0.3 * dormancy counter - reaches 0 and dies setv ov72 rand 10 40 * max light to sprout setv ov80 1 * max heat to sprout setv ov82 1 * min nutrients to sprout setv ov87 0 targ ownr setv ov00 2 endi endi
**dying doif ov00 eq 2 doif pose lt 8 setv va00 pose addv va00 1 pose va00 else altr room targ 3 0.2 altr room targ 4 0.2 kill ownr endi endi
**if you've been picked doif ov00 eq 3 * if not carried or falling doif carr eq null and fall eq 0 altr room targ 3 0.2 altr room targ 4 0.2 kill ownr endi endi endm
Fruit eat
scrp 2 8 1000 12 lock sndc "chwp" stim writ from 78 1 kill ownr endm
Fruit fall
scrp 2 8 1000 6 doif wall = down sndc "smit" endi endm
Plant Hit script
This script reuses two pieces of code from previous scripts: it stimulates whoever hit the plant as per the push script, and it uses a bit of code repeated from the timer to make the plant grow down if it is hit when it is more than just a seedling.
scrp 2 4 1000 3 targ from stim writ from 84 1 targ ownr *the plant grows DOWN if it is hit. doif pose gt 0 setv va00 pose subv va00 1 pose va00 endi endm
Plant push script
scrp 2 4 1000 1 targ from stim writ from 84 1 targ ownr mesg writ ownr 1000 endm
Plant Pull script
scrp 2 4 1000 2 stim writ from 84 1 targ ownr mesg writ ownr 1000 endm
Special plant vend script
scrp 2 4 1000 1000 lock rnge 30 setv va66 0 esee 2 8 1000 addv va66 1 next targ ownr doif va66 le 4 setv va00 posl setv va01 post inst new: simp 2 8 1000 "tutorial_seed" 1 0 4900 attr 195 bhvr 48 elas 30 fric 50 accg 3 doif tmvt va00 va01 = 1 mvto va00 va01 else mvsf va00 va01 endi velo rand -10 10 rand -15 -20 tick rand 300 600 emit 6 0.3 endi endm
Remove
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 the class numbers here, and make sure that all SCRPs in the object have a corresponding scrx.
rscr enum 2 8 1000 kill targ next enum 2 4 1000 kill targ next scrx 2 8 1000 9 scrx 2 4 1000 9 scrx 2 8 1000 12 scrx 2 8 1000 6 scrx 2 4 1000 1 scrx 2 4 1000 2 scrx 2 4 1000 3 scrx 2 4 1000 1000
Whole script
**CAOS2PRAY *# Pray-File "fulllifecycleplant.agents" *# DS-Name "Full Lifecycle Plant" *# attach sharmflower.c16 *# attach tutorial_seed.c16 *# attach chwp.wav *# attach smit.wav *# desc = "A basic plant that grows, fruits and dies, and creatures can interact with." *# Agent Animation File = "sharmflower.c16" *# Agent Animation String = "5" *# Agent Sprite First Image = 5 *# Agent Animation Gallery = "sharmflower" *# Web URL = "creatures.wiki" *# Web Label = "Creatures Wiki" inst reps 30 new: simp 2 8 1000 "tutorial_seed" 1 0 4900 attr 195 bhvr 48 elas 30 fric 50 accg 3 mvsf rand 748 1550 9547 velo rand -10 10 rand -15 -20 tick rand 300 600 emit 6 0.3 * dormancy counter - reaches 0 and dies setv ov72 rand 10 40 * max light to sprout setv ov80 1 * max heat to sprout setv ov82 1 * min nutrients to sprout setv ov87 0 repe scrp 2 8 1000 9 *fruit population check lock rnge 30 setv va66 0 esee 2 8 1000 addv va66 1 next targ ownr doif va66 gt 7 kill ownr endi unlk * if not being carried or falling doif fall eq 0 and carr eq null doif rtyp room targ eq 8 or rtyp room targ eq 9 kill ownr endi * check environment to test whether can sprout gsub envi * if don't survive envi test, go dormant gsub dorm endi **environment test - grow if successful subr envi * light check doif prop room targ 1 le ov80 setv va00 1 endi * heat check doif prop room targ 2 le ov82 setv va01 1 endi * nutrient check doif prop room targ 4 ge ov87 setv va02 1 endi * can I grow? doif va00 eq 1 and va01 eq 1 and va02 eq 1 gsub grow endi retn **growing into plant routine subr grow setv va00 posl setv va01 post new: simp 2 4 1000 "sharmflower" 9 0 140 attr 199 bhvr 43 elas 0 *OV00 - Plant state: switches between growing UP and growing DOWN setv ov00 0 *OV99 - an age counter, counts the amount of time spent in a mature state. setv ov99 0 doif tmvt va00 va01 eq 1 mvto va00 va01 else mvsf va00 va01 endi tick rand 200 1000 kill ownr retn **dormancy routine subr dorm doif pose lt 4 * make it invisible attr 16 over endi * reduce dormancy counter subv ov72 1 * if been dormant too long, die doif ov72 le 0 doif room targ ne -1 altr room targ 3 0.1 altr room targ 4 0.1 kill ownr else kill ownr endi endi retn endm ****plant timer scrp 2 4 1000 9 **OV00 is state *0=growing *1=fruiting *2=dying *3=picked *increase age addv ov01 1 **growing doif ov00 eq 0 doif pose lt 5 setv va00 pose addv va00 1 pose va00 else * if in right pose and old enough, fruit doif ov01 ge 20 setv ov00 1 stop endi endi endi **fruiting doif ov00 eq 1 doif pose lt 5 setv va00 pose addv va00 1 pose va00 else * create a fruit inst setv va00 posl setv va01 post new: simp 2 8 1000 "tutorial_seed" 1 0 4900 attr 195 bhvr 48 elas 30 fric 50 accg 3 doif tmvt va00 va01 <> 1 kill targ targ ownr setv ov00 2 stop endi doif tmvt va00 va01 = 1 mvto va00 va01 else mvsf va00 va01 endi velo rand -10 10 rand -15 -20 tick rand 300 600 emit 6 0.3 * dormancy counter - reaches 0 and dies setv ov72 rand 10 40 * max light to sprout setv ov80 1 * max heat to sprout setv ov82 1 * min nutrients to sprout setv ov87 0 targ ownr setv ov00 2 endi endi **dying doif ov00 eq 2 doif pose lt 8 setv va00 pose addv va00 1 pose va00 else altr room targ 3 0.2 altr room targ 4 0.2 kill ownr endi endi **if you've been picked doif ov00 eq 3 * if not carried or falling doif carr eq null and fall eq 0 altr room targ 3 0.2 altr room targ 4 0.2 kill ownr endi endi endm scrp 2 8 1000 12 lock sndc "chwp" stim writ from 78 1 kill ownr endm scrp 2 8 1000 6 doif wall = down sndc "smit" endi endm *Hit script scrp 2 4 1000 3 targ from stim writ from 84 1 targ ownr *the plant grows DOWN if it is hit. doif pose gt 0 setv va00 pose subv va00 1 pose va00 endi endm *push script scrp 2 4 1000 1 targ from stim writ from 84 1 targ ownr mesg writ ownr 1000 endm *Pull script scrp 2 4 1000 2 stim writ from 84 1 targ ownr mesg writ ownr 1000 endm scrp 2 4 1000 1000 lock rnge 30 setv va66 0 esee 2 8 1000 addv va66 1 next targ ownr doif va66 le 4 setv va00 posl setv va01 post inst new: simp 2 8 1000 "tutorial_seed" 1 0 4900 attr 195 bhvr 48 elas 30 fric 50 accg 3 doif tmvt va00 va01 = 1 mvto va00 va01 else mvsf va00 va01 endi velo rand -10 10 rand -15 -20 tick rand 300 600 emit 6 0.3 endi endm rscr enum 2 8 1000 kill targ next enum 2 4 1000 kill targ next scrx 2 8 1000 9 scrx 2 4 1000 9 scrx 2 8 1000 12 scrx 2 8 1000 6 scrx 2 4 1000 1 scrx 2 4 1000 2 scrx 2 4 1000 3 scrx 2 4 1000 1000
Moving On
- Change the genus to be a bad plant (2 5 1000 instead of 2 4 1000) and change all three stimuli to 83, "Danger plant", instead of 84, "Friendly plant".
- Reserve and use your own class numbers at Creatures Caves.
- Search on OpenGameArt.org or take inspiration from the Creating Agent Art tutorial to make a new sprite for your plant.
- Make the plant appear in a different metaroom. Use the keyboard shortcut CTRL + SHIFT + X to explore different coordinates.
- Try using the Constructor Script (10) to hold various values for the plant.