Page 1 of 1

Control over Corpses

Posted: Tue Apr 29, 2008 3:54 am
by OldnGrey
Can I please suggest that we have more control over how an npc corpse is dressed? I think the core randomly discards some clothing or armour before it displays the corpse facing in one direction or another.

The reason I want to do this is because I want to clone a player into an npc, slay the npc and move the corpse so it can lie on a bed dressed as the player. Then I change the player graphic to something tiny so they are not aware it's them.

The v5 client at least allows the corpse to be moved, so this seems feasible as an idea - I've long wanted to be able to lie on a bed in the inne!

Failing that, does anyone know any other way of lying on a bed?

Posted: Tue Apr 29, 2008 11:38 pm
by Nobono
I'm no scripter so this may be totally pointless but... How about forcing the "fall down" anim frame via packets and moving the player on the bed?

I think I've heard smth like that work somwhere, but have no clue if it really would work.

Posted: Wed Apr 30, 2008 6:39 am
by coltain
Yes, Yes, It works, just play the animation backward and loop the last frame

Posted: Thu May 01, 2008 4:05 am
by OldnGrey
Hmm
How can you loop the last frame?

The packet after the animation number is:

BYTE[1] unknown1 (0x00)
BYTE[1] direction
BYTE[2] repeat (1 = once / 2 = twice / 0 = repeat forever)
BYTE[1] forward/backwards(0x00=forward, 0x01=backwards)
BYTE[1] repeat Flag (0 - Don't repeat / 1 repeat)
BYTE[1] frame Delay (0x00 - fastest / 0xFF - Too slow to watch)


I can only see how you could loop the entire sequence

Posted: Thu May 01, 2008 7:15 am
by coltain
first and last frame can be "looped"

juzst play animation slowly and send packet faster then delay between frames

Posted: Thu May 01, 2008 12:33 pm
by Luth
That seems like it could be potentially very laggy. Does it not take a toll on performance? Even on large shards?

Posted: Thu May 01, 2008 4:10 pm
by OldnGrey
I imagine if you set the framerate to be incredibly slow it will simply get an animation packet every second per player which may not be excessive at all even with a few players onscreen.

I don't want to give up on this idea - apparently runuo has it already?

I will keep trying. I have to get it working eventually, but so far playing it backwards isn't doing what I expected for the dying backwards animation (21 decimal)

Posted: Thu May 01, 2008 4:27 pm
by Austin
The clothing is based on what the mobile was wearing before it died.

Make an npc and conceal it - equip it with matching stuff the player had - graphic, color and name. Set all those items once equipped to movable = 0 to keep people from stripping it.

You can then make the corpse movable and adjust its Z position to be above the bed and change its facing to go the right way.

Posted: Thu May 01, 2008 5:40 pm
by Luth
Corpse clothing does not always match the dead player's/npc's clothing, though. Unless that was recently changed and I missed it...?

Posted: Thu May 01, 2008 6:29 pm
by OldnGrey
Well here is a dot command I wrote that seems to do the animation thing sort of okay.

It's based on the packets.inc file most people might have. Oh, and I know there are better ways of doing fixPacketLength - it was just a test after all :)

Code: Select all

use uo;
use polsys;
use os;

program txt_testliedown(character, parm)
	if ( GetObjProperty(character, "#liedown") )
		return 0;
	endif
	SetObjProperty(character, "#liedown", 1);

	var x := character.x;
	var y := character.y;
	var z := character.z;

	var height := 4;
	if ( parm ) 
		if ( CInt(parm) <= 9 and CInt(parm) > 0 )
			height := CInt(parm);
		endif
	else
		SendSysMessage(character, "You can use a number between 1 and 9 to set the height. Default is 4");
	endif

	MoveObjectToLocation(character, x, y, z + height, character.realm, MOVEOBJECT_FORCELOCATION);

	while ( character )
		PlayCharAnim(character);
		sleepms(500);
		if ( character.x != x or character.y != y )
			break;
		endif
		sleepms(500);
		if ( character.x != x or character.y != y )
			break;
		endif
		sleepms(500);
		if ( character.x != x or character.y != y )
			break;
		endif
		sleepms(500);
		if ( character.x != x or character.y != y )
			break;
		endif
	endwhile
	MoveObjectToLocation(character, x, y, z, character.realm, MOVEOBJECT_FORCELOCATION);
	EraseObjProperty(character, "#liedown");
endprogram


function PlayCharAnim(who)
	var dir := 1;
	var speed := 30;				//0 = fastest, 30 = way too  slow
	var doesrepeat := 0;
	var framecount := 6;		// seems to set the frame it uses?
	var numrepeats := 1;

	var packetString := "6E";
	packetString := packetString + fixPacketLength(hex(who.serial), 4);
	packetString := packetString + fixPacketLength(hex(21), 2);			// animation

	packetString := packetString + fixPacketLength(hex(framecount), 2);		// frame count
	packetString := packetString + fixPacketLength(hex(numrepeats), 2);		// Repetition times

	packetString := packetString + fixPacketLength(hex(dir), 1);			// 00 == fwd, 01 == bkwd
	packetString := packetString + fixPacketLength(hex(doesrepeat), 1);		// Does this animation repeat? 01 == yes
	packetString := packetString + fixPacketLength(hex(speed), 1);			// frame delay

	foreach chr in ListMobilesNearLocation(who.x, who.y, who.z, 16, who.realm);
		SendPacket(chr, packetString);
	endforeach
endfunction


///////////////////////////////////////////////////////////////
//Pads a string with a "0" prefix, until it is of proper length
//	packetString	value to pad.
//	byteLength	number of bytes. Byte counted as two chars.
///////////////////////////////////////////////////////////////

function fixPacketLength(packetString, byteLength)
	if ( !packetString || packetString == error )
		packetString := 0;
	endif
	packetString := CStr(packetString);

	if ( packetString[1, 2] == "0x" )
		packetString := CStr(packetString[3, len(packetString)]);
	endif

	if ( len(packetString) > byteLength * 2 )
//		var extraBytes := (byteLength * 2) - len(packetString);
		var extraBytes := len(packetString) - (byteLength * 2) + 1;
		return CStr(packetString[extraBytes, len(packetString)]);
	endif

	while ( len(packetString) < byteLength * 2 )
		packetString := "0" + packetString;
	endwhile
	return packetString;
endfunction
You would need to put this in a logon.src too:
EraseObjProperty(character, "#liedown");

Posted: Thu May 01, 2008 11:59 pm
by coltain
OldnGrey

I just prepared my "bed script" to put it in here, but since You did it....

I sit laggy? Not at all, its just an animation to play every 300ms (or another setting)

I solved it this way... If somebody have another idea please share :)

Posted: Fri May 02, 2008 1:43 am
by OldnGrey
Oh I'd love to see another solution too. My script was the result of only a few hours of playtesting among our staff and trying to get them to look right on a bed without making them go up one storey. It has rudimentary checks for exploits but won't be as good as a well tested script.