Jump to content

!place


catman

Recommended Posts

This is the one used on our server, i did it before i knew all of the token identifiers, so it's a bit messy, i'll rewrite it later..

(..any probs, just post em)

on *:SIGNAL:mta.command:{
 if ($3 == !place) {
   if ($4) {
     var %a = 1,%c
     while (%a <= $ini(mta.data.ini,AREA2,0)) {
       if ($4 isin $readini(mta.data.ini,AREA2,$ini(mta.data.ini,AREA2,%a))) { 
         %c = $ini(mta.data.ini,AREA2,%a) 
         goto done
       }
       !inc %a
     }
     :done 
     if (%c) {   
       var %a = 1,%x,%y
       while (%a <= $numtok(%c,44)) {
         if (%a = $numtok(%c,44)) {
           %y [ $+ [ $calc(%a / 2) ] ] = $right(%c,$calc(0 - $pos(%c,$chr(44),$calc(%a - 1))))
         }
         elseif ($calc(%a / 2) == $round($calc($calc(%a / 2) - 0.1),0)) {
           %y [ $+ [ $calc(%a / 2) ] ] = $right($left(%c,$calc(-1 + $pos(%c,$chr(44),%a))),$calc(0 - $pos($left(%c,$pos(%c,$chr(44),%a)),$chr(44),$calc(%a - 1))))
         }
         elseif (%a == 1) {
           %x [ $+ [ $calc($calc(%a + 1) / 2) ] ] = $left(%c,$calc(-1 + $pos(%c,$chr(44),%a)))
         }
         else {
           %x [ $+ [ $calc($calc(%a + 1) / 2) ] ] = $right($left(%c,$calc(-1 + $pos(%c,$chr(44),%a))),$calc(0 - $pos($left(%c,$pos(%c,$chr(44),%a)),$chr(44),$calc(%a - 1))))
         }
         !inc %a
       }
       var %a = 1,%north,%south,%east,%west
       while (%x [ $+ [ %a ] ] != $null) {
         if (%a == 1) { 
           %east = %x [ $+ [ %a ] ]
           %west = %x [ $+ [ %a ] ]
           %north = %y [ $+ [ %a ] ]
           %south = %y [ $+ [ %a ] ]
         }
         else {
           if (%x [ $+ [ %a ] ] > %east) %east = %x [ $+ [ %a ] ] 
           if (%x [ $+ [ %a ] ] < %west) %west = %x [ $+ [ %a ] ]
           if (%y [ $+ [ %a ] ] > %north) %north = %y [ $+ [ %a ] ]
           if (%y [ $+ [ %a ] ] < %south) %south = %y [ $+ [ %a ] ]
         }
         unset %x [ $+ [ %a ] ]
         unset %y [ $+ [ %a ] ]
         !inc %a
       }
       var %a,%b,%x,%y
       %a = $calc($calc($abs(%east) + $abs(%west)) / 2)    
       %b = $calc($calc($abs(%north) + $abs(%south)) / 2)   
       %x = $iif($abs(%east) > $abs(%west),%a,$calc(0 - %a))
       %y = $iif($abs(%north) > $abs(%south),%b,$calc(0 - %b))
       mta.say $1 Area: $readini(mta.data.ini,AREA2,%c) - Distance: $mta.distance($mta.location($1,$2,x),%x,$mta.location($1,$2,y),%y,0,0)
     }
     else mta.say $1 No such area found
   }
   else mta.say $1 $mta.name($1,$2) > Area: $mta.area($1,$2)
 }  
}
alias mta.distance {
 var %a,%b,%c,%x,%y,%z,%atan,%acos,%asin
 %a = $calc($1 - $2)
 %b = $calc($3 - $4)
 %x = $abs($calc($1 - $2))
 %y = $abs($calc($3 - $4))
 %z = $abs($calc($5 - $6))
 if %b < 0 && %a < 0 {
   if %x < $calc(%y / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres North
   elseif %y < $calc(%x / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres East
   else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres North East
 }
 elseif %b < 0 && %a >= 0 {
   if %x < $calc(%y / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres North
   elseif %y < $calc(%x / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres West
   else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres North West
 }
 elseif %b >= 0 && %a >= 0 {
   if %x < $calc(%y / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres South
   elseif %y < $calc(%x / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres West
   else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres South West
 }
 elseif %b >= 0 && %a < 0 {
   if %x < $calc(%y / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres South
   elseif %y < $calc(%x / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres East
   else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres South East
 }
 else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres
}

Link to comment

Here, cleaned up a little :P

on *:SIGNAL:mta.command:{
 if ($3 == !place) {
   if (!$4) mta.say $1 $mta.name($1,$2) > Area: $mta.area($1,$2)
   elseif (!$5) {
     var %a = $my.getarea($1,$4)
     if ($gettok(%a,1,32) != -1) mta.say $1 Distance: $mta.name($1,$2) > $my.getdist($1,$2,%a) > $gettok(%a,2-,32)
     else mta.say $1 $mta.name($1,$2) $+ , Area $+(',$4,') not found!
   }
   else {
     var %a = $iif($4,$iif($mta.name($1,$4) != Unknown,$4,$mta.getid($1,$4)),$2),%b = $my.getarea($1,$5)
     if (%a == -1) mta.say $1 $mta.name($1,$2) $+ , ID of $+(',$4,') not found!
     elseif ($gettok(%b,1,32) != -1) mta.say $1 Distance: $mta.name($1,%a) > $my.getdist($1,%a,%b) > $gettok(%b,2-,32)
     else mta.say $1 $mta.name($1,$2) $+ , Area $+(',$5,') not found!
   }
 }
}
alias my.getarea {
 var %a = 0,%b = $iif($mta.game($1) == GTA:3,AREA1,AREA2)
 while (%a <= $ini(mta.data.ini,%b,0)) {
   if ($2 isin $readini(mta.data.ini,%b,$ini(mta.data.ini,%b,%a))) !return %a $readini(mta.data.ini,%b,$ini(mta.data.ini,%b,%a))
   !inc %a
 }
 !return -1
}
alias my.getdist {
 var %a = 1,%b = $iif($mta.game($1) == GTA:3,AREA1,AREA2),%c = x,%x,%x2,%y,%y2
 while (%a <= $numtok($ini(mta.data.ini,%b,$gettok($3,1,32)),44)) {
   var %d = $gettok($ini(mta.data.ini,%b,$gettok($3,1,32)),%a,44)
   if (%c == x) {
     %c = y
     if (!%x) %x = %d
     elseif (%d < %x) %x = %d
     if (!%x2) %x2 = %d
     elseif (%d > %x2) %x2 = %d
   }
   elseif (%c == y) {
     %c = x
     if (!%y) %y = %d
     elseif (%d < %y) %y = %d
     if (!%y2) %y2 = %d
     elseif (%d > %y2) %y2 = %d
   }
   !inc %a
 }
 var %a,%b,%c,%d
 %a = $calc($calc($abs(%x2) + $abs(%x)) / 2)    
 %b = $calc($calc($abs(%y2) + $abs(%y)) / 2)   
 %c = $iif($abs(%x2) > $abs(%x),%a,$calc(0 - %a))
 %d = $iif($abs(%y2) > $abs(%y),%b,$calc(0 - %b))
 !return $mta.distance($mta.location($1,$2,x),%c,$mta.location($1,$2,y),%d,0,0)    
}
alias mta.distance {
 var %a,%b,%c,%x,%y,%z,%atan,%acos,%asin
 %a = $calc($1 - $2)
 %b = $calc($3 - $4)
 %x = $abs($calc($1 - $2))
 %y = $abs($calc($3 - $4))
 %z = $abs($calc($5 - $6))
 if %b < 0 && %a < 0 {
   if %x < $calc(%y / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres North
   elseif %y < $calc(%x / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres East
   else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres North East
 }
 elseif %b < 0 && %a >= 0 {
   if %x < $calc(%y / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres North
   elseif %y < $calc(%x / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres West
   else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres North West
 }
 elseif %b >= 0 && %a >= 0 {
   if %x < $calc(%y / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres South
   elseif %y < $calc(%x / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres West
   else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres South West
 }
 elseif %b >= 0 && %a < 0 {
   if %x < $calc(%y / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres South
   elseif %y < $calc(%x / 2) !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres East
   else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres South East
 }
 else !return $round($sqrt($calc(%x * %x + %y * %y + %z * %z)),2) Metres
}

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...