Page 1 of 1

Handy general use scripts

Posted: Sat Feb 01, 2014 5:32 pm
by morbydvisns
Just a place to drop some handy general use scripts, some may find of great use they're very generic and can save quite a few lines when you find yourself making many replications of the same lines

here's one to start It will check for a specified minimum amount of a named item on player inventory.

Some of these may be internalized to the engine by now, I'm not sure. Some of these are a couple years old.

Code: Select all

Function HasItem($item,$amnt)
{
$itemCount = sysPlayerInventory("$item")
if ($itemCount >= $amnt)
 {
   return (1)
 }
  return (0)
}
and to use:

Code: Select all




if (HasItem("Sticks",5) == 1)
  {
   *say %player% has at least 5 sticks
  }


Posted: Sat Feb 01, 2014 5:38 pm
by morbydvisns
Here's another, this will check to see if the player is within a certain tile radius from a building. It's useful for usable items that you want to effect the outcome of use, using a building as an anchor point

Code: Select all

Function IsInBuildProx ($id,$radius)
{
setbuildingcontext($id)
$playerLocX = $gPlayerX
$playerLocX = $gPlayerY
$diffX = $gPlayerX - $gbuildingX
$diffY = $gPlayerY - $gbuildingY

 if ($diffX < 0 )
 {
  
   $diffX = -1 * $diffX
 }
 
 if ($diffY < 0 )
 {
   $diffY =  -1 * $diffY
 }

 if ($diffX <= $radius)
 {
    if ($diffY <= $radius)
  {
      return(1)
 	 restorecontext()
  }
  return (0)
  restorecontext()
   
 }
 restorecontext()
return (0)
}
and this is a companion to the above. It will find the building ID of the closest building if it's the bdat id specified.

Code: Select all

Function ClosestOfType ($type)
{
$nearest = $gNearestBuilding
$nearestCode = $gNearestBuildingCode

if ($nearestCode == $type)
 {

   return ($nearest)


 }
 else
 {
  return (0)
  
 }
}