how to end a script when pc disconnects

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am

how to end a script when pc disconnects

Post by Gnafu »

i wrote a script that change the hame of a pc ad sets the objproperty "oldname".

I need it to run for a certain time

Code: Select all

  Detach();
  set_critical(1);
  sleep( 10 * CInt(GetEffectiveSkill( who, SKILLID_HIDING )/10 ) );
	RestoreThief(who);
 SendSysmessage(who, "fine script", 3, 33);
If the player disconnect and reconnect in time, it works well, but if the player disconnect and waits....

when it reconnect it have the name changed forever...

who can i fix it?

Thanks
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Post by tekproxy »

Check for "oldname" in logon.src (remember, individual packages can have their own logon, logoff and reconnect scripts), and correct the name there.

You also might be able to change their name with the RestoreTheif function if you changed it to accept a serial instead of a character refrence. I could be wrong about this though, but I vaguely remember doing it... Send the serial to RestoreTheif(), and use:

Code: Select all

who := SysFindObjectBySerial( player_serial, SYSFIND_SEARCH_OFFLINE_MOBILES )
Then from there just change their name. Again, I'm not sure if this will work. If you use this method and it works, let me know. :)

Be careful with using set_critcal(1). It seems a bad combination having detach, set_critical(1) and sleep...
qrak
Grandmaster Poster
Posts: 198
Joined: Sun Feb 05, 2006 4:35 pm

Post by qrak »

or use member mobile.connected in pol96
FreeSoul
Master Poster
Posts: 90
Joined: Sat Feb 04, 2006 9:14 am

Post by FreeSoul »

i'm not shure if critical script can have sleeps
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am

Post by Gnafu »

qrak wrote:or use member mobile.connected in pol96
can you explain?
freesoul wrote:(remember, individual packages can have their own logon, logoff and reconnect scripts)
USEFULL!!!

I'm going to test your idea..
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Post by CWO »

just read the core changes if you have POL096...
09-15 Austin
Added : mobile.connected - To determine if the character is actively connected to the game.
Is set to 1 before logon/reconnect scripts are run and 0 right before logofftest is run.
FreeSoul
Master Poster
Posts: 90
Joined: Sat Feb 04, 2006 9:14 am

Post by FreeSoul »

Gnafu wrote:
freesoul wrote:(remember, individual packages can have their own logon, logoff and reconnect scripts)
USEFULL!!!

I'm going to test your idea..
I???

Ok but... there is no difference if logon/logoff is in misc/skill/tool/etc package

it will run when you logon/off
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Post by tekproxy »

I think his problem is that he has a script that changes the name of the player, sleeps for a time and then sets the name back. However, if the character goes offline and the script finishes sleeping and attempts to restore the old name, it gets an error because the character is offline.

Take, for example, the incognito spell. This is the code for the incognito spell in 095:

Code: Select all

program incognito(parms)
  var caster := parms.caster;
  if (!GetObjProperty( caster, "realname"))
    SetObjProperty( caster, "realname", caster.name );
  endif
  var newName := AssignName(caster);
  SetName( caster, newName );
  PlaySoundEffect(caster, 0x1e1);
  Detach();
  set_critical(1);
  sleep( 60 * CInt(GetEffectiveSkill( caster, SKILLID_MAGERY )/10 ) );
  SetName( caster, GetObjProperty( caster, "realname" ) );
  EraseObjProperty( caster, "realname" );
endprogram
If realname already exists then the player has incognito on them already and is casting it again so don't over write it. It sleeps for a time dependant on the player's magic skill and then resets the name and erases the object property. However, if the mobile is offline you get an error.


In the corrected example, it stores the casters serial while they're online and if they become offline by the end of the script, it gets an offline mobile refrence to them so changes can be made. Here is the corrected code:

Code: Select all

program incognito(parms)
  var caster := parms.caster;
  if (!GetObjProperty( caster, "realname"))
    SetObjProperty( caster, "realname", caster.name );
  endif
  var newName := AssignName(caster);
  SetName( caster, newName );
  PlaySoundEffect(caster, 0x1e1);
  Detach();
  var casterSerial := caster.serial;
  Sleep(60 * CInt(GetEffectiveSkill( caster, SKILLID_MAGERY )/10 ));
 
  // If you try to do something to a mobile when they're offline you get this error:
  // error{ errortext = "Mobile is offline" }
  if (!caster.connected)
    caster := SystemFindObjectBySerial( casterSerial, SYSFIND_SEARCH_OFFLINE_MOBILES );
  endif
  
  SetName( caster, GetObjProperty( caster, "realname" ) );
  EraseObjProperty( caster, "realname" );
endprogram
So you don't even need to use logon, logoff, reconnect, etc...
Post Reply