Page 1 of 1

Trashbarrel massacre

Posted: Sat Mar 31, 2012 6:58 pm
by gundamwing84
Hey guys, ive been trying to get my trashbarrel script to work but im having next to no luck... Dont get me wrong it works but it wont sleep for 30seconds when i put in sleep(30);, it goes right through and deletes the item instantly :( would anyone be able to see what im doing wrong?

Code: Select all

use uo;
use os;

include "include/objtype";

program trash(who, trashcan)

	foreach item in EnumerateItemsInContainer(trashcan)
	
		if (item)
			DoWaitMessage(who, trashcan, "This item will be deleted in 30 seconds.");
			Sleep(30);
			if (item.container.serial == trashcan.serial)
				DestroyItem(item);
			endif
		endif

		PlaySoundEffect(trashcan, 0x226 );

	endforeach

endprogram

function DoWaitMessage(who, what, msg)

	if (who.concealed or what.container)
		if (msg)
			PrintTextAbovePrivate(what, msg, who);
		endif
	else
		if (msg)
			PrintTextAbove(what, msg);
		endif
	endif

endfunction

Re: Trashbarrel massacre

Posted: Sat Mar 31, 2012 7:19 pm
by RusseL
wrong way.
you should use OnInsert script, not use_script.

Code: Select all

program onInsert_trash (who, container, movetype, inserttype, item)

      if (!item)
         syslog("wtf was that!?");
         return;
      endif

      DoWaitMessage(who, container, "This item will be deleted in 30 seconds.");
      detach();
      Sleep(30);

      if (!item or !container)
            return;
      endif

      if (item.container.serial == container.serial)
            DestroyItem(item);
      endif
endprogram
something like this, haven't tested but should work:)

Re: Trashbarrel massacre

Posted: Mon Apr 02, 2012 1:03 pm
by gundamwing84
No that doesnt seem to work either, it just deleted it straight away :( thanks anyway though russel

Re: Trashbarrel massacre

Posted: Mon Apr 02, 2012 3:18 pm
by RusseL
ok then

but it's a wrong way anyway.
if you use your trashcan 100 times, it starts the timer 100 times (then it plays soundeffect 100 times etc.)..
if you use your trashcan, wait 29secs, and then insert an item - it'll be destroyed in 1 second.

bad idea imho;)
better use onInsert or control script for something like this, or do some checks if trashcan is already used.

Code: Select all

program trash(who, trashcan)

   DoWaitMessage(who, trashcan, "This item will be deleted in 30 seconds.");
   detach();
   Sleep(30);

   foreach item in EnumerateItemsInContainer(trashcan)
      if (item)
         if (item.container.serial == trashcan.serial)
            DestroyItem(item);
         endif
      endif
      PlaySoundEffect(trashcan, 0x226 );
   endforeach

endprogram

Re: Trashbarrel massacre

Posted: Mon Apr 02, 2012 4:37 pm
by gundamwing84
i have it set as the oninsert script:

Code: Select all

Container 0x17057
{
	Name				TrashBarrel
	Desc				trash barrel
	Gump				0x003E
	Graphic			0x0E77
	Color			1154
	MinX				40
	MaxX				60
	MinY				20
	MaxY				80
	RequiresAttention	0
	Weight			5
	movable			1
	VendorSellsFor		400
	MaxItems			65535
	Maxweight			65535
	OldObjtype		0x7057
	OnRemoveScript		onremove_chest
	CanRemoveScript	canremove_chest
	OnInsertScript		trash
	CanInsertScript	caninsert_chest
}
im not completely sure as to why it doesnt work and im ok with the timer starting over again or not starting. id just rather there be a timer incase someone puts something in there, they have the chance to get it out, so they cant blame the game im makin for losing something. as is, the script that was there before would just delete the item after double clicking on it and give u a penny for it lmao

Re: Trashbarrel massacre

Posted: Mon Apr 02, 2012 7:47 pm
by Agata
Why not put a CProp on the trashcan with a ReadGameClock()+29 at insertion time? And have the sleep(30), and next check if the cprop is lower than the current gameclock. If it's lower, then destroy all items, if not, just skip, leaving all items untouched.

Re: Trashbarrel massacre

Posted: Mon Apr 02, 2012 9:28 pm
by Turley
oninsert is started as a critical script. so your sleep gets ignored.

Re: Trashbarrel massacre

Posted: Mon Apr 02, 2012 10:50 pm
by gundamwing84
ahh ok :( so how should i go about doing this?

Re: Trashbarrel massacre

Posted: Tue Apr 03, 2012 2:55 am
by RusseL
gundamwing84 wrote:ahh ok :( so how should i go about doing this?
so, try to explain your idea, how should it work

Re: Trashbarrel massacre

Posted: Tue Apr 03, 2012 6:17 am
by gundamwing84
ok, so i want the trash barrel to act like a normal one, that just deletes items from the game after player go for a hunt or watever when they are clearing out there pack. but incase they put something valuable into the trash barrel, i would like it to tell the player that it will be deleted in 30 seconds so that they have a bit of time to make sure what they put in isnt something valuable.

i think this will also stop people from harrassing or blaming me if they destroy a large price item accidently, because then you have the chance of being able to take the item out of the trash barrel before it deletes it. so will need a can remove and onremove script to support this, im currently using the WOD container chest ones.

Re: Trashbarrel massacre

Posted: Tue Apr 03, 2012 8:46 am
by RusseL
TrashCan onInsert

Code: Select all

program onInsert_trash (who, container, movetype, inserttype, item)

      if (!item)        // don't know if this check is really required
         syslog("wtf was that!?");
         return;
      endif

      DoWaitMessage(who, container, "This item will be deleted in 30 seconds.");

      var script := start_script( "DestroyThisItem", array{item, container} );
      if( script.errortext )
             SysLog( "Error starting script <DestroyThisItem> -->"+script.errortext );
      endif

endprogram

function DoWaitMessage(who, what, msg)

   if (who.concealed or what.container)
      if (msg)
         PrintTextAbovePrivate(what, msg, who);
      endif
   else
      if (msg)
         PrintTextAbove(what, msg);
      endif
   endif

endfunction
DestroyThisItem.src

Code: Select all

use uo;

program DestroyItem(item, trashcan)

      Sleep(30);

      if (!item or !trashcan)
            return;
      endif

      if (item.container.serial == trashcan.serial)
            PlaySoundEffect(trashcan, 0x226 );
            DestroyItem(item);
      endif

endprogram

Re: Trashbarrel massacre

Posted: Tue Apr 03, 2012 10:58 am
by Agata
If you don't want people to blame or harass you if they lose an item, then don't be apologetic about it. If they put it in the trash can and lost it, it's their fault, you have to make that clear and stand firm. Also, in most shards, harassing a staff member is a bannable offense.

Re: Trashbarrel massacre

Posted: Tue Apr 03, 2012 11:25 am
by RusseL
Agata wrote:If you don't want people to blame or harass you if they lose an item, then don't be apologetic about it. If they put it in the trash can and lost it, it's their fault, you have to make that clear and stand firm. Also, in most shards, harassing a staff member is a bannable offense.
+1
my trashcan script

PlaySoundEffect(who , 0x236); // gilotin1.wav
destroyitem (item);
SendSysMessage (who, "You trash the item");

Re: Trashbarrel massacre

Posted: Tue Apr 03, 2012 3:57 pm
by gundamwing84
ahh guess i might be a bit too nice then =\

uhh ok so ive done one thing to the destroythisitem.src, i had to rename the program from DestroyItem because its a function pol wont accept it. ive tested it out and oninsert_trash works perfectly, but once it goes through to DestroyThisItem.src, it fails and i cant figure out why or where in the script :(

Code: Select all

program DestroyThisItem(item, trashcan)

      Sleep(30);

      if (!item or !trashcan)
            return;
      endif

      if (item.container.serial == trashcan.serial)
            PlaySoundEffect(trashcan, 0x226 );
            DestroyItem(item);
      endif

endprogram
it doesnt play the sound effect so it must be getting caught up in the first if statement thinking theres no item or trashcan? :s

Re: Trashbarrel massacre

Posted: Fri Apr 06, 2012 9:09 pm
by Agata
It's likely none of them exists... try changing to this:

Code: Select all

program DestroyThisItem(parms)
      Sleep(30);
      var item := parms[1];
      var trashcan := parms[2];
      if (!item or !trashcan)
            syslog ("Item = " + item + ", trashcan = " + trashcan);
            return;
      endif

      if (item.container.serial == trashcan.serial)
            PlaySoundEffect(trashcan, 0x226 );
            DestroyItem(item);
      endif

endprogram
If it works fine, you can remove the syslog call.