Hey guys, never submitted code snippets here, so now I thought I ought to.
What it will do is basically check if two objects are within a specified distance of each other it will return a value of 1. A simple way of checking things if you like. It might be useful if you want to only let the player talk to an NPC if they're within a certain distance or if you want an enemy to only follow you if you're close enough.
Just as an example: write (inside of a loop and with 2 available objects)
val = CheckObjectCollisionArea(1,2,35)
if val = 1 then text 0,10,"We are in distance."
if val = 0 then text 0,10,"You're too far away."
function CheckObjectCollisionArea(Object1, object2, distance)
`Set the default to '0', the check variable is what we'll be returning - if the object is in the right area, a value will be returned
check = 0
`Get the First Object's position - I named the variables 'NPC' and 'Player', but that don't matter, it's just what I called them when
`coding
NPCx = Object position x(Object1)
NPCy = Object position y(Object1)
NPCz = object position z(Object1)
`Get the second object's position
PlayerX = Object position x(Object2)
PlayerY = object position y(Object2)
PlayerZ = object position z(Object2)
`Calculate the distance between points by removing the second object's position variables from the the first
`So is Object 2 is at X = 100 and Object 1 is at X = 30, then the returned 'x' value overall will be '70', thus the distance
`on the 'x' axis
Posx = NPCx - PlayerX
Posy = NPCy - PlayerY
Posz = NPCz - PlayerZ
`getting the distance
dis = distance
`This will check if the objects are close enough. Basically if you choose a distance value of '25', it'll check
`if the object distance is between -25 and 25 for all axis' If you're in that zone, then the check value returned will be '1'
if posx < dis and posx > -dis and posy < dis and posy > -dis and posz < dis and posz > -dis then check = 1
` text 100,100,"You may be able to talk"
`endif
endfunction check
Oh and I made a pretty picture too, just to show it in use (you'll see in the debug data where it returns a '1'):