Author Sticky: Post Working Scripts Here
Zane_NBK Posted: Thursday, 27 June 08:17AM
Script: Respawn at race specific towns.

Currently this script only supports one town per race but if you combine it with other scripts (like the location saving script that uses an object to store the player's location before logging out) then you can do multiple towns per race. Having the player choose a starting town would be the only interesting part.

The script is pretty self-explanitory. Modify it to your liking and then set it as the script for your Module's OnPlayerRespawn event. You'll also need to setup a waypoint named "NW_<RACE>_RESPAWN" in every town for every race and a "NW_DEFAULT_RESPAWN" waypoint which will cover all non-specified races.

NWScript:
void main()

{

    object oRespawner = GetLastRespawnButtonPresser();

    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oRespawner);

    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oRespawner)), oRespawner);

    RemoveEffects(oRespawner);

    //* Return PC to respawn point based on race.

    string sDefaultDest = "NW_DEFAULT_RESPAWN";

    string sDestTag =  "NW_";

    int iRace = GetRacialType(oRespawner);

    switch (iRace)

    {

        case RACIAL_TYPE_HUMAN:

            sDestTag = sDestTag + "HUMAN";

            break;

        case RACIAL_TYPE_ELF:

            sDestTag = sDestTag + "ELF";

            break;

        case RACIAL_TYPE_GNOME:

            sDestTag = sDestTag + "GNOME";

            break;

        case RACIAL_TYPE_HALFELF:

            sDestTag = sDestTag + "HALFELF";

            break;

        case RACIAL_TYPE_HALFLING:

            sDestTag = sDestTag + "HALFLING";

            break;

        case RACIAL_TYPE_HALFORC:

            sDestTag = sDestTag + "HALFORC";

            break;

        case RACIAL_TYPE_DWARF:

            sDestTag = sDestTag + "DWARF";

            break;

        default:

            sDestTag = sDefaultDest;

            break;

    }

    sDestTag = sDestTag + "_RESPAWN";

    int iValidSpawn = 0;

    if (GetIsObjectValid(GetObjectByTag(sDestTag)))

    {

        iValidSpawn = 1;

    }

    // Unable to find the race specific spawn point, trying default spawn point.

    else if (sDestTag != sDefaultDest && GetIsObjectValid(GetObjectByTag(sDefaultDest)))

    {

        sDestTag = sDefaultDest;

        iValidSpawn = 1;

    }

    // If the spawn is valid, move us there, else apply the penalty and res

    // where they stand.

    if (iValidSpawn == 1)

    {

        // Store the location you died.

        SetLocalLocation(oRespawner, "NW_L_I_DIED_HERE", GetLocation(GetLastRespawnButtonPresser()));

        SetLocalInt(oRespawner, "NW_L_I_DIED", 1);

        // Apply any penalties.

        ApplyPenalty(oRespawner);

        // Move to the resurrection site.

        object oSpawnPoint = GetObjectByTag(sDestTag);

        AssignCommand(oRespawner,JumpToLocation(GetLocation(oSpawnPoint)));

    }

    else

    {

        // Unable to find the spawn point.

        // Apply the penalty and res where the player stands.

        ApplyPenalty(oRespawner);

    }

 }



I'm also working on having race-based starting locations, but that's more of a pain. Currently I can't do it without having a staging area loaded first which annoys me. If I ever solve that problem I'll post the script.