Page 1 of 1

how to end a script when pc disconnects

Posted: Sun Apr 23, 2006 8:50 am
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

Posted: Sun Apr 23, 2006 9:01 am
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...

Posted: Sun Apr 23, 2006 9:23 pm
by qrak
or use member mobile.connected in pol96

Posted: Sun Apr 23, 2006 9:27 pm
by FreeSoul
i'm not shure if critical script can have sleeps

Posted: Mon Apr 24, 2006 12:17 am
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..

Posted: Mon Apr 24, 2006 1:02 am
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.

Posted: Mon Apr 24, 2006 3:08 am
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

Posted: Mon Apr 24, 2006 6:29 am
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...