3rd Party HSI Code
From OHRRPGCE-Wiki
[edit] Disclaimer and Notice
This pages hosts the actual code and keeps track of revisions to the code. If you are looking for documentation, please go to What is the 3rd Party HSI?
# 3rd Party Include File |
# version 1.7 (Last updated 8/16/2004) |
#Check the OHRRPGCE Homepage for the most up to date version |
#Please do not modify this file before sending or hosting |
#This version is intended for OHRRPGCE v.Ozarks |
# |
#The 3rd Party HSI is compiled and directed by FyreWulff |
#Please consult the README file for contributing authors |
#---------------------------------------------------------====/
#------------------------------------------------------------\
# It is highly suggested that you do not modify this file |
# so that people trying to help you debug scripts using |
# these functions will be able to do so. |
#-------------------------------------------------------=====/
#=====================#
#Constants Definitions#
#=====================#
define constant, begin
#these are for use in FyreWulff's havemoney script
1, strict
0, loose
#these are for use in T-Master's time-altering plotscripting commands
51, days
52, hours
53, minutes
54, seconds
#these are for use in FyreWulff's clearmap script
1, clearwalls
0, preserve walls
#For use in in Mad Cacti's math scripts
1, forwards
-1, backwards
#For use in FyreWulff's unequipparty script
0, entire party
1, active only
2, reserve only
end
#=====================#
#Operator Definitions#
#=====================#
define operator, begin #operators for your use, eg '50 + 100, times sine, 50'
25, times sin, sin wrap
25, times cos, cos wrap
25, times tan, tan wrap
30, div, divideround
end
#=====================#
# Global Variables # all Third Party HSI global variables start from 1024 and go back
#=====================# to prevent conflicts. For now let's keep them between 1001 and 1024
#comment out the below lines if your game uses these global var IDs
global variable, begin
1024, vehiclex #for use in savevechicleposition and etc
1023, vehicley # " " " "
1022, vehicledirection # saves vehicle direction, used in script above
1021, vehicleid # saves which NPC is the vehicle
end
#=====================#
# Script Definitions #
#=====================#
define script, begin
autonumber, tb, 1, 0 # tb(textbox) : shows text box with auto waitfortextbox
autonumber, havemoney , 2, 1, 0 #havemoney(amount,strictness) : checks for money
autonumber, distance , 2, 0, 2 #distance(num1,num2) : between two values
autonumber, xdistance , 2, 0, 1 #xdistance(Hero#,NPC#) : distance between hero# and npc# x's
autonumber, ydistance , 2, 0, 1 #ydistance(Hero#,NPC#) : distance between hero# and npc# y's
autonumber, abs , 1, 0 # absolute value
autonumber, trunc , 2, 0, 0 # truncate
autonumber, resettime , 0 # reset engine time
autonumber, getinterval , 1, 53 #get engine time interval
autonumber, setinterval , 2, 53, 0 # set engine time interval
autonumber, clearmap, 2, 0, 1 # clearmap(tile,walls) : map clear with tile #,
# default walls will also be cleared unless "preserve walls" is used
autonumber,save vehicle, 1, 0 # saves vehicle position
autonumber,restore vehicle, 0 #restores vehicle at it's saved position
#Mad Cacti's scripts#########################################################################
autonumber, divideround, 2, 0, 1 #Returns the rounded answer to <1st> / <2nd>
autonumber, digit, 2, 0, 0 #returns a digit <2nd> in number <1st>. A better, rewriten version of Cubes script.
autonumber, sine, 2, 0, 10000
autonumber, cosine, 2, 0, 10000
autonumber, tan, 2, 0, 10000
autonumber, sina, 1, 0 #functions used by another script. Not for regular use
autonumber, sinb, 1, 0 # same
autonumber, sinc, 1, 0 # same
autonumber, sind, 1, 0 # same
autonumber, sin wrap, 2, 0, 0 #functions used by another script. Not for regular use
autonumber, cos wrap, 2, 0, 0 # same
autonumber, tan wrap, 2, 0, 0 # same
autonumber, sqrt, 1, 0
autonumber, npc above, 8, 0, 0, 0, 0, 0, 0, 0, 0 #used to find the highest NPC at a spot
autonumber, npc below, 8, 0, 0, 0, 0, 0, 0, 0, 0 #same, but used to find the lowest
autonumber, swap npc ref, 2, 0, 0 #swaps two npc's properties
autonumber, number of npcs, 2, 0, 35
autonumber, first free id, 3, 0, 35, 1
#############################################################################################
autonumber,unequip party, 1, 0 #takes away all of the party's equipment
autonumber,delete all items, 0 #takes away all items in player's inventory
autonumber,reset tags, 0 # resets all regular tags and One Time Use NPC tags
autonumber,reset map, 0 # resets the map
autonumber,fake door, 3, 0, 0, 0 # fakes a door to map, x, y
end
#=====================#
# The Scripts #
#=====================#
script, tb, textbox, begin #TB script written by FyreWulff
showtextbox(textbox)
waitfortextbox
end
script, havemoney, amount, strictness, begin #have money script written by FyreWulff
if( paymoney(amount + 1) == true, and, strictness == strict ) then ( getmoney(amount), return (true) )
if( paymoney(amount -- 1) == true, and, strictness == strict ) then ( getmoney(amount), return (true) )
if( paymoney(amount) == true, and, strictness == loose ) then ( getmoney(amount), return (true) )
if( paymoney(amount) == false) then (return (false) )
end
script, distance, num1, num2, begin #by FyreWulff
# EDITED BY RINKU & TEE EM CEE TO AVOID OVERFLOW.
if (abs(num1/10 -- num2/10) >> 3276)
then (return (32767))
else (return (abs(num1 -- num2)))
end
script, x distance, heronum, npcnum, begin #by FyreWulff
return ( abs( herox(heronum) -- npcx(npcnum) ) )
end
script, y distance, heronum, npcnum, begin #by FyreWulff
return ( abs( heroy(heronum) -- npcy(npcnum) ) )
end
script, abs, n, begin #Written by T-Master
if(n<<0) then(return(n * -1))
else(return(n))
end
script, trunc, n, o, begin #written by T-master & CodyWatts
return((n -- (n, mod, o)) / o)
end
script, resettime, begin #Written by T-Master
write general(days, 0)
write general(hours, 0)
write general(minutes, 0)
write general(seconds, 0)
end
script, getinterval, interval, begin #Written by T-Master
return(read general(interval))
end
script, setinterval, interval, value, begin #Written by T-Master
write general(interval, value)
end
script, clearmap, cleartile, wallclear, begin
variable(xtile,ytile)
xtile := 0 , ytile := 0
for(xtile,0,3199,1) do, begin
for(ytile,0,1999,1) do, begin
writemapblock(xtile,ytile,cleartile)
if (wallclear) then ( writepassblock(xtile,ytile,0) )
end
end
end
script, save vehicle, vechnpc, begin
vehiclex := npcx(vechnpc)
vehicley := npcy(vechnpc)
vehicledirection := npcdirection(vechnpc)
vehicleid := vechnpc
end
script, restore vehicle, begin
setnpcposition(vehicleid,vehiclex,vehicley)
setnpcdirection(vehicleid, vehicledirection)
end
script, divideround, n, m, begin
return ((n + m / 2) / m)
end
script, sine, angle, mult, begin
variable (total, remain, val, sign)
if (angle << 0) then (angle := 0 -- angle, sign := 1) #allow for postive / negative wave nature of graph
sign := (sign + angle / 180), mod, 2
angle := angle, mod, 180 #this part converts the angle to a value between 0 and 90.
if (angle >> 90) then (angle := 180 -- angle)
#lookup table contains 32768*sin(angle)
#so sin(90) can not be stored
if (angle == 90) then (return (mult)) else (
if (angle << 45) then (
if (angle << 22) then (
val := sina (angle)
) else (
val := sinb (angle)
)
) else (
if (angle << 67) then (
val := sinc (angle)
) else (
val := sind (angle)
)
)
#work out result*mult/32768
#boohoho, so much for getting rid of the excess math
variable (multh, multl, valh, vall)
valh := (val / 256) #split val and mult into upper and lower bytes
vall := (val, mod, 256) #so that we can do 32-bit integar math without overflowing
multh := (mult / 256)
multl := (mult, mod, 256)
total := multh * valh * 2 + multh * vall / 128 + multl * valh / 128 + (multl / 2) * (vall / 2) / 8192
remain := (multh * vall), mod, 128 + (multl * valh), mod, 128 #ignore remainder of last part, too minor
increment (total, (remain + 64) / 128) #rounded divide
if (sign) then (return (0 -- total)) else (return (total))
)
end
script, cosine, angle, mult, begin
return (sine (angle + 90, mult))
end
script, tan, angle, mult, begin
variable (hval, divd, sign, val3)
angle := angle, mod, 180
if (angle << 0) then (angle := 0 -- angle, sign := 1)
if (mult << 0) then (mult := 0 -- mult, sign := sign, xor, 1)
if (angle >> 90) then (angle := 180 -- angle, sign := sign, xor, 1)
if (angle == 0) then (return (0)) else (
hval := sine (angle, mult)
val3 := (hval, mod, 2) * 64
hval := hval / 2
angle := 90 -- angle
if (angle << 45) then (
if (angle << 22) then (
divd := sina (angle)
) else (
divd := sinb (angle)
)
) else (
if (angle << 67) then (
divd := sinc (angle)
) else (
divd := sind (angle)
)
)
divd := divd / 2
divh := divd / 128
divl := divd, mod, 128
variable (t1, t2, t3, t4, ans, divh, divl)
if (hval / divd >> 1) then (noop) #result larger than 32767
divh := divd / 128
divl := divd, mod, 128
t1 := hval / divh #base quotient
t2 := (hval, mod, divh) * 128 + val3 #mod of above
t3 := t2 -- divl * t1 #remain
if (t3 << 0) then ( #t1 is too large, figure out by how much
t4 := (0 -- t3) / divd + 1
decrement (t1, t4) #result
increment (t3, divd * t4)#new remain
)
ans := t1 * 128
t1 := t3 / divh
t2 := (t3, mod, divh) * 128
t3 := t2 -- divl * t1
if (t3 << 0) then (
t4 := (0 -- t3) / divd + 1
decrement (t1, t4)
increment (t3, divd * t4)
)
increment (ans, t1)
ans := ans * 2 + (t3 + divd / 2) / divd
if (sign) then (return (0 -- ans)) else (return (ans))
)
end
script, sina, angle, begin
if (angle << 11) then (
if (angle << 5) then (
if (angle << 2) then (
if (angle == 0) then (return (0)) else (return (572))
) else (
if (angle == 2) then (return (1144)) else (
if (angle == 3) then (return (1715)) else (return (2286))
)
)
) else (
if (angle << 8) then (
if (angle == 5) then (return (2856)) else (
if (angle == 6) then (return (3425)) else (return (3993))
)
) else (
if (angle == 8) then (return (4560)) else (
if (angle == 9) then (return (5126)) else (return (5690))
)
)
)
) else (
if (angle << 16) then (
if (angle << 13) then (
if (angle == 11) then (return (6252)) else (return (6813))
) else (
if (angle == 13) then (return (7371)) else (
if (angle == 14) then (return (7927)) else (return (8481))
)
)
) else (
if (angle << 19) then (
if (angle == 16) then (return (9032)) else (
if (angle == 17) then (return (9580)) else (return (10126))
)
) else (
if (angle == 19) then (return (10668)) else (
if (angle == 20) then (return (11207)) else (return (11743))
)
)
)
)
end
script, sinb, angle, begin
if (angle << 33) then (
if (angle << 27) then (
if (angle << 24) then (
if (angle == 22) then (return (12275)) else (return (12803))
) else (
if (angle == 24) then (return (13328)) else (
if (angle == 25) then (return (13848)) else (return (14365))
)
)
) else (
if (angle << 30) then (
if (angle == 27) then (return (14876)) else (
if (angle == 28) then (return (15384)) else (return (15886))
)
) else (
if (angle == 30) then (return (16384)) else (
if (angle == 31) then (return (16877)) else (return (17364))
)
)
)
) else (
if (angle << 39) then (
if (angle << 36) then (
if (angle == 33) then (return (17847)) else (
if (angle == 34) then (return (18324)) else (return (18795))
)
) else (
if (angle == 36) then (return (19261)) else (
if (angle == 37) then (return (19720)) else (return (20174))
)
)
) else (
if (angle << 42) then (
if (angle == 39) then (return (20622)) else (
if (angle == 40) then (return (21063)) else (return (21498))
)
) else (
if (angle == 42) then (return (21926)) else (
if (angle == 43) then (return (22348)) else (return (22763))
)
)
)
)
end
script, sinc, angle, begin
if (angle << 56) then (
if (angle << 50) then (
if (angle << 47) then (
if (angle == 45) then (return (23170)) else (return (23571))
) else (
if (angle == 47) then (return (23965)) else (
if (angle == 48) then (return (24351)) else (return (24730))
)
)
) else (
if (angle << 53) then (
if (angle == 50) then (return (25102)) else (
if (angle == 51) then (return (25466)) else (return (25822))
)
) else (
if (angle == 53) then (return (26170)) else (
if (angle == 54) then (return (26510)) else (return (26842))
)
)
)
) else (
if (angle << 61) then (
if (angle << 58) then (
if (angle == 56) then (return (27166)) else (return (27482))
) else (
if (angle == 58) then (return (27789)) else (
if (angle == 59) then (return (28088)) else (return (28378))
)
)
) else (
if (angle << 64) then (
if (angle == 61) then (return (28660)) else (
if (angle == 62) then (return (28932)) else (return (29197))
)
) else (
if (angle == 64) then (return (29452)) else (
if (angle == 65) then (return (29698)) else (return (29935))
)
)
)
)
end
script, sind, angle, begin
if (angle << 78) then (
if (angle << 72) then (
if (angle << 69) then (
if (angle == 67) then (return (30163)) else (return (30382))
) else (
if (angle == 69) then (return (30592)) else (
if (angle == 70) then (return (30792)) else (return (30983))
)
)
) else (
if (angle << 75) then (
if (angle == 72) then (return (31164)) else (
if (angle == 73) then (return (31336)) else (return (31499))
)
) else (
if (angle == 75) then (return (31651)) else (
if (angle == 76) then (return (31795)) else (return (31928))
)
)
)
) else (
if (angle << 84) then (
if (angle << 81) then (
if (angle == 78) then (return (32052)) else (
if (angle == 79) then (return (32166)) else (return (32270))
)
) else (
if (angle == 81) then (return (32365)) else (
if (angle == 82) then (return (32449)) else (return (32524))
)
)
) else (
if (angle << 87) then (
if (angle == 84) then (return (32588)) else (
if (angle == 85) then (return (32643)) else (return (32688))
)
) else (
if (angle == 87) then (return (32723)) else (
if (angle == 88) then (return (32748)) else (return (32763))
)
)
)
)
end
script, sin wrap, mult, angle (return (sine (angle, mult)))
script, cos wrap, mult, angle (return (cosine (angle, mult)))
script, tan wrap, mult, angle (return (tan (angle, mult)))
script, sqrt, fi, begin
variable (start, divi, approx)
approx := -1
if (fi >= 32581) then (return (181)) else, begin #Prevent overflows
if (fi << 100) then (start := 0, divi := start ^ 2) else (
if (fi >= 22500) then (start := 150) else (
if (fi >= 14400) then (start := 120) else (
if (fi >= 8100) then (start := 90) else (
if (fi >= 4225) then (start := 65) else (
if (fi >= 1600) then (start := 40) else (
if (fi >= 900) then (start := 30) else (
if (fi >= 400) then (start := 20) else (start := 10)
))))))
divi := start ^ 2
if (fi / 3 >> divi / 2) then (start := (start / 5) * 6, divi := start ^ 2)
if (fi / 4 >> divi / 3) then (start := (start / 7) * 8, divi := start ^ 2)
)
while (approx == -1) do, begin
if (divi >= fi) then (approx := start) else (
increment (start)
divi := start ^ 2
)
end
if (divi == fi) then (return (approx)) else, begin
if ((divi -- approx) == fi) then (return (approx -- 1)) else (return (fi / approx + 1))
end
end
end
script, npc above, a, b, c, d, e, f, g, h, begin
variable (min)
if (a << b) then (min := a) else (min := b)
if (c) then (if (c << min) then (min := c)
if (d) then (if (d << min) then (min := d)
if (e) then (if (e << min) then (min := e)
if (f) then (if (f << min) then (min := f)
if (g) then (if (g << min) then (min := g)
if (h) then (if (h << min) then (min := h))
)
)
)
)
)
return (min)
end
script, npc below, a, b, c, d, e, f, g, h, begin
variable (max)
if (a >> b) then (max := a) else (max := b)
if (c) then (if (c >> max) then (max := c)
if (d) then (if (d >> max) then (max := d)
if (e) then (if (e >> max) then (max := e)
if (f) then (if (f >> max) then (max := f)
if (g) then (if (g >> max) then (max := g)
if (h) then (if (h >> max) then (max := h))
)
)
)
)
)
return (max)
end
script, swap npc ref, npc a, npc b, begin
variable (temp a, temp b, temp c, temp d)
if (npc a <> npc b) then (
temp a := npc pixel x (npc a)
temp b := npc pixel x (npc b)
temp c := npc pixel y (npc a)
temp d := npc pixel y (npc b)
put npc (npc a, temp b, temp d)
put npc (npc b, temp a, temp c)
temp a := get npc id (npc a)
temp b := get npc id (npc b)
change npc id (npc a, temp b)
change npc id (npc b, temp a)
temp a := npc direction (npc a)
temp b := npc direction (npc b)
set npc direction (npc a, temp b)
set npc direction (npc b, temp a)
)
)
script, number of npcs, low, high, begin
variable (total, i)
for (i, low, high) do (increment (total, npc copy count (i)))
return (total)
end
script, first free id, low, high, direction, begin
variable (found, i, temp)
found := -1
if ((high << low) xor (direction << 0)) then (temp := low, low := high, high := temp)
for (i, low, high, direction) do (
if (npc copy count (i)) else (found := i, i := high)
)
return (found)
end
script, digit, value, dgtno, begin
if (dgtno >> 5) then (dgtno := 5)
return ((value / 10 ^ (dgtno -- 1)), mod, 10)
end
script, unequip party, type, begin
variable(heroslot), heroslot := 0
variable(itemslot), itemslot := 0
variable(min hero slot) , min hero slot := 0
variable(max hero slot) , max hero slot := 40
if( type == active only ) then( max hero slot := 3 , min hero slot := 0 )
if( type == reserve only ) then( max hero slot := 40 , min hero slot := 4)
for(heroslot,min hero slot,max hero slot) do, begin
for(itemslot,1,5) do ( unequip( heroslot, itemslot ) )
end
end
script, delete all items, begin
variable(loop)
for(loop,0,255) do ( deleteitem(loop,100) )
end
script, reset tags, begin
variable(tagloop)
for(tagloop,2,2002) do ( settag(tagloop, false) )
end
script, reset map, begin
teleporttomap(currentmap,herox,heroy)
end
script, fake door, map, x, y, begin
suspendplayer
fadescreenout
wait(5)
teleporttomap(map,x,y)
wait(1)
fadescreenin
resumeplayer
end
# EOF
