So there you have it.
Code: Select all
# TacoBot's Universal Better Encounter System (TUBES)
# A super cool replacement to the OHRRPGCE's foemapping system that
# comes with a side of rice and beans!
#
##### Benefits over regular foemapping system:
#
# * MANY more encounter sets (4,294,967,294 as opposed to 255!)
# * Set as many encounter rates to a single foemap as you'd like! (Rates
# aren't dependent on formation set)
# * More control over encounters! Want to make enemies appear only if 3
# globals are set to certain values? No problem!
# * Encounters can do anything scriptable! Want an encounter to show a
# textbox, give you an item, create an npc, etc.? No problem!
# * Up to 100 "occurences" per encounter set Want more? Good heavens,
# that's a lot of encounters... but you can do it, no problem!
# * Up to 15 encounter sets per tile (zone limitation)
# * Up to 9999 encounter sets per map!
# * Ability to call foemap any time! (Default foemap only works like an
# "each step" script)
#
##### How to use at map level:
#
# Use zones between battleZoneStart and battleZoneEnd
#
# Set extra data like so:
#
# Extra data 0: battleZoneID (arbitrary constant that identifies the
# zone as a foemap)
# Extra data 1: Encounter chance (% chance of encounter every step [or
# whenever you call the script])
# Extra data 2: Encounter set (defined way down below)
define constant, begin
1337, battleZoneID ### Completely arbitrary. Set it to a number that zones in battle zone range would never use otherwise.
1, battleZoneStart ### Start of battle zones.
9999, battleZoneEnd ### End of battle zones.
end
global variable, begin
300, encounterMultiplier ### Modifier for encounter rates. Eg: 1 = Default rate, 2 = 2x rate, etc. Set this to something in your new game script. Set to 0 to disable all encounters.
end
### Call this in your eachstep script for any map on which you'd like encounters (or put if somewhere else if you want to be creative)
plotscript, battleZoneCheck, begin
# Prevent division by zero
if (encounterMultiplier > 0) then (
variable(i, zoneUnderfoot)
for (i, 0, 14) do (
zoneUnderfoot := zoneAtSpot(heroX(me), heroY(me), i)
if (zoneUnderfoot >= battleZoneStart && zoneUnderfoot <= battleZoneEnd) then (
if (getZoneExtra(zoneUnderfoot, 0) == battleZoneID) then (
variable(chance, set)
chance := getZoneExtra(zoneUnderfoot, 1)
set := getZoneExtra(zoneUnderfoot, 2)
fightSet(chance, set)
)
)
)
)
end
##################################################
# WARNING! WORLD'S LARGEST SWITCH CASE INCOMING! #
# I can't think of any better way to implement #
# this without arrays. If you can, I'd love to #
# hear about it. #
##################################################
plotscript, fightSet, chance, set, begin
seedRandom()
variable(rand, encounter)
rand := (random(1, 100) / encounterMultiplier)
encounter := random (1, 100) ### Use this to determine the encounter. Use a range between 1 and 100 (change this if you need more than 100 encounters for some esoteric purpose).
if (rand <chance>= 66) then (
fightFormation(1)
) else if (encounter >= 33) then (
fightFormation(2)
) else (
fightFormation(3)
)
)
### 1: Example 2 - Fights one formation 75% of the time, and one 25% of the time.
case (1) do (
if (encounter >= 75) then (
fightFormation(4)
) else (
fightFormation(5)
)
)
### 2: Fight a formation 90% of the time, show a textbox 10% of the time.
case (2) do (
if (encounter >= 90) then (
fightFormation(6)
) else (
showTextBox(42) ### "You stumble upon a wandering merchant (or something)"
)
)
### Fallback
case (else) do (
### Absolutely nothing.
)
)
)
end
Code: Select all
plotscript, newgame, begin
encounterMultiplier := 1
end