Trashbarrel massacre

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Trashbarrel massacre

Post 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
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: Trashbarrel massacre

Post 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:)
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Re: Trashbarrel massacre

Post by gundamwing84 »

No that doesnt seem to work either, it just deleted it straight away :( thanks anyway though russel
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: Trashbarrel massacre

Post 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
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Re: Trashbarrel massacre

Post 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
Agata
Journeyman Poster
Posts: 63
Joined: Sun Oct 30, 2011 6:33 am

Re: Trashbarrel massacre

Post 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.
Turley
POL Developer
Posts: 670
Joined: Sun Feb 05, 2006 4:45 am

Re: Trashbarrel massacre

Post by Turley »

oninsert is started as a critical script. so your sleep gets ignored.
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Re: Trashbarrel massacre

Post by gundamwing84 »

ahh ok :( so how should i go about doing this?
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: Trashbarrel massacre

Post by RusseL »

gundamwing84 wrote:ahh ok :( so how should i go about doing this?
so, try to explain your idea, how should it work
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Re: Trashbarrel massacre

Post 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.
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: Trashbarrel massacre

Post 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
Agata
Journeyman Poster
Posts: 63
Joined: Sun Oct 30, 2011 6:33 am

Re: Trashbarrel massacre

Post 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.
RusseL
Forum Regular
Posts: 375
Joined: Fri Feb 20, 2009 8:30 pm

Re: Trashbarrel massacre

Post 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");
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Re: Trashbarrel massacre

Post 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
Agata
Journeyman Poster
Posts: 63
Joined: Sun Oct 30, 2011 6:33 am

Re: Trashbarrel massacre

Post 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.
Post Reply