Experimental swim command
Posted: Mon Feb 02, 2009 6:57 pm
Here is a swim command I wrote a long time ago to test how it should look like.
Requires Pol096 because of the CoordinateDistance function. But here is a scripted version of that function.
And then change MoveObjectToLocation function to MoveCharacterToLocation and you can use this with Pol094 and 095 aswell.
Requires Pol096 because of the CoordinateDistance function. But here is a scripted version of that function.
And then change MoveObjectToLocation function to MoveCharacterToLocation and you can use this with Pol094 and 095 aswell.
Code: Select all
function CoordinateDistance( x1, y1, x2, y2 )
if( !x1 || !y1 || !x2 || !y2 )
return error;
endif
var xd := Abs( x1 - x2 );
var yd := Abs( y1 - y2 );
if ( xd > yd )
return xd;
else
return yd;
endif
endfunction
Code: Select all
use uo;
use os;
use math;
program Command_swim( who, speed )
Set_Critical( 1 );
if ( GetObjProperty( who, "Swimming" ) )
return 0;
endif
SetObjProperty( who, "Swimming", ReadGameClock() );
Set_Critical( 0 );
SendSysMessage( who, "Where do you wish to swim?" );
var where := TargetCoordinates( who );
if ( !where )
SendSysMessage( who, "Cancelled." );
EraseObjProperty( who, "Swimming" );
return 0;
endif
var water := array{ 22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,115,116,130,134,140,141,142,143,145,146,147,149,152,153,154,155,160,161,162,163,168,169,170,171,310,311,441,443,444,445,446,450,454,463,465 };
if ( !( GetMapInfo( where.x, where.y ).landtile in water ) )
SendSysMessage( who, "You can't swim in there. " + GetMapInfo( where.x, where.y ).landtile );
EraseObjProperty( who, "Swimming" );
return 0;
elseif( CoordinateDistance( who.x, who.y, where.x, where.y ) > 3 )
SendSysMessage( who, "That is too far away." );
EraseObjProperty( who, "Swimming" );
return 0;
endif
if ( speed && who.cmdlevel )
speed := CInt( speed );
else
speed := 2000;
endif
Detach();
MoveObjectToLocation( who, where.x, where.y, where.z - 4, who.realm, MOVEOBJECT_FORCELOCATION );
while ( !who.dead )
PerformAction( who, 16 );
Sleepms( speed );
Case ( who.facing )
0: MoveObjectToLocation( who, who.x, who.y - 1, who.z, who.realm, MOVEOBJECT_FORCELOCATION ); break;
1: MoveObjectToLocation( who, who.x + 1, who.y - 1, who.z, who.realm, MOVEOBJECT_FORCELOCATION ); break;
2: MoveObjectToLocation( who, who.x + 1, who.y, who.z, who.realm, MOVEOBJECT_FORCELOCATION ); break;
3: MoveObjectToLocation( who, who.x + 1, who.y + 1, who.z, who.realm, MOVEOBJECT_FORCELOCATION ); break;
4: MoveObjectToLocation( who, who.x, who.y + 1, who.z, who.realm, MOVEOBJECT_FORCELOCATION ); break;
5: MoveObjectToLocation( who, who.x - 1, who.y + 1, who.z, who.realm, MOVEOBJECT_FORCELOCATION ); break;
6: MoveObjectToLocation( who, who.x - 1, who.y, who.z, who.realm, MOVEOBJECT_FORCELOCATION ); break;
7: MoveObjectToLocation( who, who.x - 1, who.y - 1, who.z, who.realm, MOVEOBJECT_FORCELOCATION ); break;
Default:
Print( "Invalid facing. " + who.facing );
return 0;
endcase
if ( !( GetMapInfo( who.x, who.y ).landtile in water ) )
MoveObjectToLocation( who, who.x, who.y, GetStandingHeight( who.x, who.y, who.z ).z );
break;
endif
Sleepms( 2 );
endwhile
PrintTextAbove( who, "landtile " + GetMapInfo( who.x, who.y ).landtile );
EraseObjProperty( who, "Swimming" );
return 1;
endprogram