Welcome to the Creatures Wiki! Log in and join the community.

Difference between revisions of "Vendor as plant script"

From Creatures Wiki
Jump to navigation Jump to search
m (→‎Plant Timer script: change "food" to "fruit")
Line 84: Line 84:
 
  * Create a new fruit object
 
  * Create a new fruit object
 
  new: simp 2 8 2000 "tutorial_tomato" 1 2 1200
 
  new: simp 2 8 2000 "tutorial_tomato" 1 2 1200
  * Check if the food object can be created in this spot
+
  * Check if the fruit object can be created in this spot
 
  doif tmvt va02 va03 eq 1
 
  doif tmvt va02 va03 eq 1
 
  * If yes, create it
 
  * If yes, create it
 
  mvto va02 va03
 
  mvto va02 va03
  * also move the food away from the plant
+
  * also move the fruit away from the plant
 
  velo rand -5 5 -5
 
  velo rand -5 5 -5
 
  else
 
  else

Revision as of 07:47, 12 June 2020

A Docking Station tomato agent, using the sprite file File:tutorial_tomato.c16. It is a single feature plant which vends a fruit object if it is pushed, pulled, hit, and on a regular timed basis, with appropriate stimuli. Fragrant fruit will usually appear around the foot of the tomato plant, attracting creatures. It's useful to use the CAOS Tool or another highlighting tool to read the code because they can make the CAOS syntax easier to read.

CAOS2PRAY

Monk, ready to use 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 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 "tutorial_tomato.agents"
 *# DS-Name "Tutorial Tomato"
 *# attach tutorial_tomato.c16
 *# desc = "A feature plant for your Capillata."
 *# Agent Animation File = "tutorial_tomato.c16"
 *# Agent Animation String = "0"
 *# Agent Sprite First Image = 0
 *# Agent Animation Gallery = "tutorial_tomato"
 *# Web URL = "creatures.wiki"
 *# Web Label = "Creatures Wiki"

Install script

new: simp 2 4 2000 "tutorial_tomato" 2 0 1100

  • The construction script automatically gets called after creation (= now)
  • The plant has been created now, move it into the correct place - held in the hand
mesg wrt+ pntr 1000 targ null 0 

Plant construction script

scrp 2 4 2000 10
* Call the construction script instantly
	inst
* Attr: mouseable 2 + collide 64 + physics 128 = 194
	attr 194
* Bhvr: act1 1 + act 2 2 + hit 8
	bhvr 11
* Set physics attributes
	accg 2
	aero 3
* Set collision attributes
	perm 100
	fric 100
	elas 0
* emit flower smell (optional, if it is a flower)
	emit 9 0.3
* set the timer script to a random tick (timer script gets called to make fruit)
	tick rand 400 800
endm

Plant Activate 1 (push) script (play with plant)

scrp 2 4 2000 1
* Stim the pushing creature (from) with "played with good plant"
	stim writ from 84 1
** Reset the timer script
	mesg writ ownr 9
endm

Plant Activate 2 (pull) script (play with plant)

scrp 2 4 2000 2
* Stim the pulling creature (from) with "played with good plant"
	stim writ from 84 1
** Reset the timer script
	mesg writ ownr 9
endm

Plant hit script (play with plant)

scrp 2 4 2000 3
* Stim the hitting creature (from) with "played with good plant"
	stim writ from 84 1
** Reset the timer script
	mesg writ ownr 9
endm

Plant Timer script

scrp 2 4 2000 9
* set the tick to a random value again
	tick rand 400 800
* if there's a tomato on the plant, create fruit.	
	doif pose ne 1
* Create fruit
* Save the coordinates of the plant into variables so the fruit can be created at the plant
		setv va02 posl
		setv va03 post
* Create a new fruit object
		new: simp 2 8 2000 "tutorial_tomato" 1 2 1200
* Check if the fruit object can be created in this spot
		doif tmvt va02 va03 eq 1
* If yes, create it
			mvto va02 va03
* also move the fruit away from the plant
			velo rand -5 5 -5
		else
* If not, kill it
			kill targ
		endi
	endi
*setting targ to the ownr of the script	
	targ ownr
*look plucked	
	pose 1
*wait a second	
	wait 20
*grow back your tomato	
	pose 0
endm

Fruit creation script

scrp 2 8 2000 10

  • Attr: mouseable 2 + collide 64 + physics 128 = 194

attr 194

  • Bhvr: eat 16 + pick up 32

bhvr 48

  • Set physics attributes

accg 2 aero 3

  • Set collision attributes

perm 60 fric 60 elas 30

  • Emit fruit smell

emit 6 0.3

  • Set a tick after which the food will decay

tick 3000 endm

Fruit eat script

scrp 2 8 2000 12 stim writ from 78 2 kill ownr endm

Fruit Timer script

scrp 2 8 2000 9

  • If around for too long, kill it
  • First check if it's not being carried

doif carr eq null

  • Go to the dying subroutine

gsub detritus else

  • It's being carried. Make the tick smaller now since it's quite old already and should decay some while after being dropped.

tick 200 endi

  • This is the detritus subroutine

subr detritus

  • This could have been "create detritus" but I'm lazy and I'll just kill the food.

kill ownr retn endm


Remove scripts

rscr enum 2 4 2000 kill targ next enum 2 8 2000 kill targ next

scrx 2 4 2000 10 scrx 2 4 2000 1 scrx 2 4 2000 2 scrx 2 4 2000 3 scrx 2 4 2000 9 scrx 2 8 2000 10 scrx 2 8 2000 12 scrx 2 8 2000 9

Whole script

  **CAOS2PRAY
  *# Pray-File "tutorial_tomato.agents"
  *# DS-Name "Tutorial Tomato"
  *# attach tutorial_tomato.c16
  *# desc = "A feature plant for your Capillata."
  *# Agent Animation File = "tutorial_tomato.c16"
  *# Agent Animation String = "0"
  *# Agent Sprite First Image = 0
  *# Agent Animation Gallery = "tutorial_tomato"
  *# Web URL = "creatures.wiki"
  *# Web Label = "Creatures Wiki"

* Install script
new: simp 2 4 2000 "tutorial_tomato" 2 0 1100
* The construction script automatically gets called after creation (= now)
* The plant has been created now, move it into the correct place - held in the hand
 mesg wrt+ pntr 1000 targ null 0 


**
** Plant scripts
**

** Plant construction script
scrp 2 4 2000 10
* Call the construction script instantly
	inst
* Attr: mouseable 2 + collide 64 + physics 128 = 194
	attr 194
* Bhvr: act1 1 + act2 2 + hit 8
	bhvr 11
* Set physics attributes
	accg 2
	aero 3
* Set collision attributes
	perm 100
	fric 100
	elas 0
* emit flower smell (optional, if it is a flower)
	emit 9 0.3
* set the timer script to a random tick (timer script gets called to make fruit)
	tick rand 400 800
endm

** Plant Activate 1 (push) script (play with plant)

scrp 2 4 2000 1
* Stim the pushing creature (from) with "played with good plant"
	stim writ from 84 1
** Reset the timer script
	mesg writ ownr 9
endm

** Plant Activate 2 (pull) script (play with plant)

scrp 2 4 2000 2
* Stim the pulling creature (from) with "played with good plant"
	stim writ from 84 1
** Reset the timer script
	mesg writ ownr 9
endm

** Plant hit script (play with plant)

scrp 2 4 2000 3
* Stim the hitting creature (from) with "played with good plant"
	stim writ from 84 1
** Reset the timer script
	mesg writ ownr 9
endm

** Plant Timer script

scrp 2 4 2000 9
* set the tick to a random value again
	tick rand 400 800
* if there's a tomato on the plant, create fruit.	
	doif pose ne 1
* Create fruit
* Save the coordinates of the plant into variables so the fruit can be created at the plant
		setv va02 posl
		setv va03 post
* Create a new fruit object
		new: simp 2 8 2000 "tutorial_tomato" 1 2 1200
* Check if the food object can be created in this spot
		doif tmvt va02 va03 eq 1
* If yes, create it
			mvto va02 va03
* also move the food away from the plant
			velo rand -5 5 -5
		else
* If not, kill it
			kill targ
		endi
	endi
*setting targ to the ownr of the script	
	targ ownr
*look plucked	
	pose 1
*wait a second	
	wait 20
*grow back your tomato	
	pose 0
endm

** Food creation script

scrp 2 8 2000 10
* Attr: mouseable 2 + collide 64 + physics 128 = 194
	attr 194
* Bhvr: eat 16 + pick up 32
	bhvr 48
* Set physics attributes
	accg 2
	aero 3
* Set collision attributes
	perm 60
	fric 60
	elas 30
* Emit fruit smell
	emit 6 0.3
* Set a tick after which the food will decay
	tick 3000
endm

** Fruit eat script 

scrp 2 8 2000 12
	stim writ from 78 2
	kill ownr
endm

** Fruit Timer script

scrp 2 8 2000 9
* If around for too long, kill it
* First check if it's not being carried
	doif carr eq null
* Go to the dying subroutine
		gsub detritus
	else
* It's being carried. Make the tick smaller now since it's quite old already and should decay some while after being dropped.
		tick 200
	endi

* This is the detritus subroutine
	subr detritus
* This could have been "create detritus" but I'm lazy and I'll just kill the food.
		kill ownr
	retn
endm

rscr
enum 2 4 2000
	kill targ
next
enum 2 8 2000
	kill targ
next

scrx 2 4 2000 10
scrx 2 4 2000 1
scrx 2 4 2000 2
scrx 2 4 2000 3
scrx 2 4 2000 9
scrx 2 8 2000 10
scrx 2 8 2000 12
scrx 2 8 2000 9