- Code: Select all
**How to make a Patch Plant
**Using the Chili Pepper Plant as an example
**The first thing you need to do is make an invisible flag agent
**This agent is classified as 1 205 X, and stores information about your patch plant.
**This means a lot of NAME variables.
new: simp 1 205 22935 "blnk" 0 0 9000
*The first thing you're going to do is define the number of your spawn script
*This is the script that the patch core will trigger when it's time to spawn a fruit/bud/whatever.
*I'm going to use script 1000 for this... we'll get more into it later.
setv name "spawn_script" 1000
*Now you have to define the file name and image number of the sprite that will represent your plant
*when it is fully grown. This will be used both in placing a fruit/bud and serving as the little
*indicator that shows on the hand when you're placing the patch.
sets name "sprite_file" "chilli"
setv name "sprite_pose" 11
*finally, you need to define the classifiers for your produce
setv name "prod_fmly" 2
setv name "prod_gnus" 8
setv name "prod_spcs" 22935
*now personally, I like to define my blossoms as "fruit" all the way through the growing process,
*and just keep them invisible to creatures until they are fully grown. You might chose to do it
*differently and define them as flowers that later are killed and replaced with fruits. However
*you choose to do it is up to you-- but the only agents that are going to be considered part
*of your patch are those with those classifiers as defined above. Thus, once your flower is killed
*and replaced with a fruit, the patch won't recognize it anymore-- so you'll have have to do some
*more creative coding if you want to do it that way.
*Now that you have everything defined, you need to contact the patch core agent (1 1 22929) and let
*it know that you're here-- the patch scripts will take it from there and generate the
*placement windows, let the user choose options, and so on.
seta va00 targ
enum 1 1 22929
mesg wrt+ targ 1000 va00 0 0
**That's it for your install script!
*Now for your spawn script-- this is 1000 as we defined it in the install script.
scrp 1 205 22935 1000
*If this script is running, it's because the patch core decided it was time for your
*patch to spawn a new bud. It has also sent the coordinates it has decided were proper in
*_p1_ (x) and _p2_ (y). It has also stored the plane set by the patch options in the NAME
*So first, create your little fruit to be:
new: simp 2 8 22935 "chilli" 14 1 name "patch_plane"
*again, I like to keep my blossoms invisible to creatures so they don't
*try to eat them while they're still flowers. You also obviously don't want them to suffer
*physics just yet.
*And move it to the coords sent by the patch agent:
mvto _p1_ _p2_
*Now, a few new name variables have been defined in your patch flag agent since you last
*left it-- these are settings that have been defined in the options window as well as a
*unique patch ID number that has been generated. You'll need to copy these over to your
*your budding fruit!
*The patch ID is important-- if you don't copy it over, the patch plant won't realize that
*the fruit is there, and it will spawn another one, and continue spawning FOREVER.
setv name "patch_id" mame "patch_id"
*then there's the ticks as set in the options panel:
tick rand mame "tickfrom" mame "tickto"
*personally I like to define a default tick too, in case something goes wrong and the tick ends
*up as 0.
doif tick eq 0
*And that is just about it.
*From here you pretty much script it like you would any other blossoming plant-- give it a timer
*script to grow, ripen, become visible and so on. Of course, don't forget eat scripts,
*collision scripts, etc.
*Keep in mind: when your plant is picked (or falls off the patch if you decide to code it like that)
*aside from making it suffer physics, you'll also have to decide if you want to clear the
*patch_id variable. If you clear it, it will no longer count toward the total number of
*fruits growing on the patch, and a new one will spawn to take its place. If you don't clear
*it, the script will keep counting it and until that fruit is eaten or otherwise disappears,
*a new fruit won't spawn. If you haven't scripted your fruits to eventually decay, you may
*wish to keep the patch_id variable intact so you don't have a patch that keeps spawning
*endless numbers of fruits that pile up and slow down the game.
*Another thing you might consider doing is setting the tick to something static after the fruit
*falls off the patch, so that the growth rate set by the user does not affect the decay rate of
*the fruit. Personally, I choose not to do this, but it is an option to consider.
*This is my timer script:
scrp 2 8 22935 9
*if it's not fully grown, grow it to the next stage
doif pose lt 10
setv va00 pose
addv va00 1
*if it is fully grown, add to its timer (ov00), and make sure creatures can see/grab it.
doif ov00 lt 10
addv ov00 1
doif attr = 80
*also make it start smelling like a fruit
emit 6 0.01
*if it's fully grown and has been sitting on the plant for 10 turns,
*it should fall off the patch
doif attr = 67
*I'm going to chose to clear the patch_id variable so a new one can spawn where it fell.
setv name "patch_id" 0
*and if it's fully grown and already on the ground, it should add to its decay timer (ov01)
elif attr = 195
doif ov01 lt 10
addv ov01 1
*but if its been laying on the floor for 10 turns, go ahead and call it rotten.
*I'm going to be lazy and just kill targ, but if you have proper sprites prepared,
*turning it into detritus can benefit your ecosystem if you've got bugs and critters that eat it.
*here's the collision script-- in this case if it's hitting the floor for the first time
*it changes the sprite.
scrp 2 8 22935 6
doif ov02 = 0
pose rand 12 13
setv ov02 1
*This is the pickup script
scrp 2 8 22935 4
*if it's attr is still 67, you (or a creature) are picking it directly off the plant
*and need to set it so it doesn't act attached to the patch anymore
doif attr = 67
*Again, I'm going to chose to clear the patch_id variable so a new one can spawn.
setv name "patch_id" 0
*Finally, the eat script. Nom.
scrp 2 8 22935 12
stim writ from 78 1
*going to add hotness and vitamin C to mimic the hardman chilis.
doif from ne null
chem 153 .15
chem 99 .35
*Again, I'm just killing it here, but no reason you can create a fruit with multiple bites, or
*something that turns into detritus after it's eaten.
enum 1 205 22935
enum 2 8 22935
Feel free to post any questions you have in this thread! I will do my best to keep it updated with clarifications to make the development process as easy as possible.