Page 1 of 1

Target*() timeout

Posted: Mon Jun 26, 2006 11:06 pm
by taxman
I wrote about it so i repeat..
additional parameter for Target*() calls - timeout for waiting. Now script stops on this call and waiting forever. Often it is not good.

Posted: Tue Jun 27, 2006 12:56 am
by Bytehawk
These two scripts might help in this situation (not tested!)

askfortarget.src sets a flag (cprop) on the player, starts a monitoring script (waitfortarget.src) and asks for a target. If the player does not chose a target within 5 seconds, waitfortarget.src kills the script askfortarget.src, which should also kill the target cursor. As I said above it's not tested, but should theoretically work :)

Code: Select all

// ----- askfortarget.src -----
use os;
use uo;

program askfortarget(who)

  SetObjProperty (who, "#waitfortarget", ReadGameClock ());
  start_script ("waitfortarget", array {who, GetPID (), 5});
  var victim:= Target (who);

  if (victim.acctname && (victim != who))
    PrintTextAbovePrivate (victim, who.name + " targetted you.", victim);
  else
    SendSysMessage (who, "Cancelled.");
  endif

  EraseObjProperty (who, "#waitfortarget");

endprogram

Code: Select all

// ----- waitfortarget.src -----
use os;
use uo;

program waitfortarget(params)

  var wait:= params[3];
  var pid:= params[2];
  var who:= params[1];
  Sleep (wait);

  if (GetObjProperty (who, "#waitfortarget"))
    EraseObjProperty (who, "#waitfortarget");
    GetProcess (pid).kill ();
  endif

endprogram

Posted: Tue Jun 27, 2006 1:26 am
by taxman
i can kill waiting script but i cant continue it execution. As sometimes people says in Odessa "Its two great differences" ;)

Posted: Tue Jun 27, 2006 5:42 am
by Marilla
I like this idea; let the Target() call expire, returning a specific error on timeout. The only thing I'd be interested in knowing about further would be could the target on the client be handled somehow, as just letting it sit there might be confusing. Though on expiration, the script could send a SysMessage or something to let the player know it expired, I guess.

Posted: Tue Jun 27, 2006 5:46 am
by CWO
You can make the client cancel a target just by

SendPacket(who, "6C000000000003000000000000000000000000")

This will automatically make the client send the target info as if you hit ESC.

Posted: Tue Jun 27, 2006 5:51 am
by Marilla
Beany-ness :)

Posted: Tue Jun 27, 2006 7:08 am
by Bytehawk
This is in fact a "little" bit more elegant then my solution.

Note to self: DO look at that packet thing finally!

Posted: Tue Jun 27, 2006 10:00 am
by tekproxy
Target() only sends a packet to the client, there is no way to "time out". Sending the cancel target packet is the closest thing.

And yes, you should look into those packet things. With packet hooking you can do almost anything. The power can be quite intoxicating.

Posted: Tue Jun 27, 2006 1:56 pm
by MuadDib
And, I am afraid without some intense thread work (aka, won't work without multithreading enabled in pol.cfg), a core-side option will take some time to come up with. Unless I actually do my job and investigate all possibilities. Which, atm, takes more time than I got.

But, never underestimate my level of boredom. Already done several 096.1 fixes, and much more. Will see what I can do, outside of thread work.