Author Topic: Player Respawn Penalty Not Working  (Read 310 times)

Legacy_Badwater

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Player Respawn Penalty Not Working
« on: July 17, 2011, 10:46:22 pm »


               I was testing some encounters in our PW and discovered that when a player respawns they do not get a penalty (no reduction in xp and gold). [On a PW, never rely on players to let you know a bug that is advantageous to them '<img'>]. That's certainly not the intention and our module respawn script has worked in the past, so I took a look. It's fairly basic, as follows:

--------------------------------------------
#include "nw_i0_plot"
#include "aps_include"
#include "_cb_core"
#include "ldp_include"

void unEquip(object oPlayer);

// * Applies an XP and GP penalty
// * to the player respawning
void ApplyPenalty(object oDead)
{
    int nXP = GetXP(oDead);
    int nPenalty = 50 * GetHitDice(oDead);
    int nHD = GetHitDice(oDead);
    // * You can not lose a level with this respawning
    int nMin = ((nHD * (nHD - 1)) / 2) * 1000;

    int nNewXP = nXP - nPenalty;
    if (nNewXP < nMin)
       nNewXP = nMin;
    SetXP(oDead, nNewXP);
    int nGoldToTake =  FloatToInt(0.10 * GetGold(oDead));
    // * a cap of 10 000gp taken from you
    if (nGoldToTake > 10000)
    {
        nGoldToTake = 10000;
    }
    AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
    DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
    DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));
}

void ApplyHeavyPenalty(object oDead)
{
    int nXP = GetXP(oDead);
    int nHD = GetHitDice(oDead);
    int nNewXP = ((( nHD * ( nHD - 1)) / 2) * 1000)-(((  nHD-1 ) * 1000 ) / 2 );
    SetXP(oDead, nNewXP);
    int nGoldToTake =  FloatToInt(0.10 * GetGold(oDead));
    // * a cap of 10 000gp taken from you
    if (nGoldToTake > 10000)
    {
        nGoldToTake = 10000;
    }
    AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
    DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
    DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));
    unEquip(oDead);
}

//////////////////////////////////////////////////////////////////////////////

After that are database functions and a penalty if the player does not get raised before they've respawned 3 times (they lose a level). Curiously, the level penalty does work. The database functions get updated. The gold and xp penalties, however, do not happen.

I added some shouts to the script to see what is firing and what isn't, as follows:

----------------------------------------------
#include "nw_i0_plot"
#include "aps_include"
#include "_cb_core"
#include "ldp_include"

void unEquip(object oPlayer);

// * Applies an XP and GP penalty
// * to the player respawning
void ApplyPenalty(object oDead)
{
    int nXP = GetXP(oDead);
    SpeakString("nXP: "+IntToString(nXP), TALKVOLUME_SHOUT);
    int nPenalty = 50 * GetHitDice(oDead);
    SpeakString("nPenalty: "+IntToString(nPenalty), TALKVOLUME_SHOUT);
    int nHD = GetHitDice(oDead);
    SpeakString("nHD: "+IntToString(nHD), TALKVOLUME_SHOUT);
    // * You can not lose a level with this respawning
    int nMin = ((nHD * (nHD - 1)) / 2) * 1000;

    int nNewXP = nXP - nPenalty;
    if (nNewXP < nMin)
       nNewXP = nMin;
       SpeakString("nNewXP: "+IntToString(nNewXP), TALKVOLUME_SHOUT);
    SetXP(oDead, nNewXP);
    int nGoldToTake =  FloatToInt(0.10 * GetGold(oDead));
    // * a cap of 10 000gp taken from you
    if (nGoldToTake > 10000)
    {
        nGoldToTake = 10000;
    }
    AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
    DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
    DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));
}

//////////////////////etc...

I get nothing. I don't get any shouts, much less get any values returned.

Does anyone have an idea on what the culprit here is?

Thanks - Badwater
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Player Respawn Penalty Not Working
« Reply #1 on: July 17, 2011, 10:56:42 pm »


               Since you get no shouts I can only guess the function is not firing.  

You however did not give the code that calls the function.   I can only guess that it is in the main code for your respawn.   If you could post the Main code body someone may be able to help you.
               
               

               
            

Legacy_Badwater

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Player Respawn Penalty Not Working
« Reply #2 on: July 17, 2011, 11:35:04 pm »


               This is the player respawn event:

//::///////////////////////////////////////////////
//:: Generic On Pressed Respawn Button
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
// * June 1: moved RestoreEffects into plot include
*/
//:://////////////////////////////////////////////
//:: Created By:   Brent
//:: Created On:   November
//:://////////////////////////////////////////////
#include "nw_i0_plot"
#include "aps_include"
#include "_cb_core"
#include "ldp_include"

void unEquip(object oPlayer);

// * Applies an XP and GP penalty
// * to the player respawning
void ApplyPenalty(object oDead)
{
    int nXP = GetXP(oDead);
    SpeakString("nXP: "+IntToString(nXP), TALKVOLUME_SHOUT);
    int nPenalty = 50 * GetHitDice(oDead);
    SpeakString("nPenalty: "+IntToString(nPenalty), TALKVOLUME_SHOUT);
    int nHD = GetHitDice(oDead);
    SpeakString("nHD: "+IntToString(nHD), TALKVOLUME_SHOUT);
    // * You can not lose a level with this respawning
    int nMin = ((nHD * (nHD - 1)) / 2) * 1000;

    int nNewXP = nXP - nPenalty;
    if (nNewXP < nMin)
       nNewXP = nMin;
       SpeakString("nNewXP: "+IntToString(nNewXP), TALKVOLUME_SHOUT);
    SetXP(oDead, nNewXP);
    int nGoldToTake =  FloatToInt(0.10 * GetGold(oDead));
    // * a cap of 10 000gp taken from you
    if (nGoldToTake > 10000)
    {
        nGoldToTake = 10000;
    }
    AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
    DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
    DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));
}

void ApplyHeavyPenalty(object oDead)
{
    int nXP = GetXP(oDead);
    int nHD = GetHitDice(oDead);
    int nNewXP = ((( nHD * ( nHD - 1)) / 2) * 1000)-(((  nHD-1 ) * 1000 ) / 2 );
    SetXP(oDead, nNewXP);
    int nGoldToTake =  FloatToInt(0.10 * GetGold(oDead));
    // * a cap of 10 000gp taken from you
    if (nGoldToTake > 10000)
    {
        nGoldToTake = 10000;
    }
    AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
    DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
    DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));
    unEquip(oDead);
}

//////////////////////////////////////////////////////////////////////////////

//maxdeaths indicates how high to let it go before resetting the value.
int ld_CheckDoublePenalty(object oPlayer)
{
    int retval=FALSE;
    string sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPlayer));
    string sTag = SQLEncodeSpecialChars(GetName(oPlayer));
    string sKey = " player_name='" + sPlayer + "' AND player_tag='" + sTag + "'";

    string sSQL="select deaths from player_info where" + sKey;
    SQLExecDirect(sSQL);
    if(SQLFetch())
    {
        int deaths=StringToInt(SQLGetData(1));
        //AssignCommand(oPlayer, ActionSpeakString("deaths at respawn: "+IntToString(deaths)));
        if(deaths==0)
        {
            int lev=GetLevelByPosition(1, oPlayer)+GetLevelByPosition(2, oPlayer)+GetLevelByPosition(3, oPlayer);
            if(lev > 5)
            {
                retval=TRUE;
            }
        }
    }
    return retval;
}

void main()
{
    object oModule = GetModule();
    object oRespawner = GetLastRespawnButtonPresser();
    DeletePersistentVariable(oRespawner, "CC_I_DIED");
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oRespawner);
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oRespawner)), oRespawner);
    RemoveEffects(oRespawner);
    //Return PC to assigned respawn point.  Until the module is restarted, this will function properly.
    //basically the following generates a character specific variable which
    //can be retrieved the next time they reenter the module, or when they die,
    //but which won't go away unless the module is reset.
    string sPlayer=GetPCPlayerName(oRespawner);
    string sName=GetName(oRespawner);
    string sVarName="RespawnPoint";
    string s1=sVarName+sName;
    string sAll=s1+sPlayer;
    //ex: player name="LantharD'Alton"
    //    character being played = "Siolad"
    //I get the variable name: "RespawnPointSioladLantharD'Alton"
    string sDestTag=GetPersistentString(oModule, sAll);
    if (GetIsObjectValid(GetObjectByTag(sDestTag)))
    {
        SetLocalLocation(oRespawner, "NW_L_I_DIED_HERE", GetLocation(GetLastRespawnButtonPresser()));
        SetLocalInt(oRespawner, "NW_L_I_DIED", 1);
        //use only the first 15 characters in tag.  This allows unique trigger tags.
        //you don't have to use unique trigger tags, but this lets you... just fill space
        //up to 15 chars with name of waypoint, and add unique ending.
        if(GetStringLength(sDestTag) > 15)
        {   //why not do sDestTag=GetSubString(sDestTag, 0, 15);??
            //because most functions like this will reset the target string, and
            //if it reset the target, and the target is the source, we get "" back.
            //not sure if that happens here, but just in case...
            string sTemp = GetSubString(sDestTag, 0, 15);
            sDestTag=sTemp;
        }
        //if you need to have something happen when they respawn in a certain location,
        //do it here.
        if (sDestTag == "WP_CANYONPORTAL")
        {   //they are still in canyon country area, or that is the closest point they may go to.
        }
        else if(sDestTag == "WP_CHALLENGE001")
        {
        }
        else if(sDestTag == "WP_CHALLENGE002")
        {
        }
        else if(sDestTag == "WP_CHALLENGE003")
        {
        }
        else if(sDestTag == "WP_CHALLENGE004")
        {
        }
        if(ld_CheckDoublePenalty(oRespawner))
            ApplyHeavyPenalty(oRespawner);
        else
            ApplyPenalty(oRespawner);
        object oSpawnPoint = GetObjectByTag(sDestTag);
        location spawnloc=GetStartingLocation();
        if(GetIsObjectValid(oSpawnPoint))
            spawnloc=GetLocation(oSpawnPoint);
        AssignCommand(oRespawner,JumpToLocation(spawnloc));
    }
    else
    {
        // * do nothing, just 'res where you are.
    }
    core(oRespawner);
    ldp_UpdatePlayerDeathState(oRespawner, PS_ALIVE);
    ldp_UpdatePlayerHP(oRespawner);
//    ExecuteScript("hc_mev_on_pl_spn", OBJECT_SELF);
}

void unEquip(object oPlayer)
{
    object oItem;
    int i=0;
    for(i=0; i<NUM_INVENTORY_SLOTS; i++)
    {
        oItem=GetItemInSlot(i, oPlayer);
        if(oItem!=OBJECT_INVALID)
        {
            AssignCommand(oPlayer, ActionUnequipItem(oItem));
            AssignCommand(oPlayer, ActionEquipItem(oItem, i));
        }
    }
}
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Player Respawn Penalty Not Working
« Reply #3 on: July 18, 2011, 02:22:44 am »


               The only thing i see is that if:

string sDestTag=GetPersistentString(oModule, sAll);

does not return a valid tag for the PC to port to and the PC respawns at the point they are standing.  the section the takes the xp from them is skipped.
               
               

               
            

Legacy_Badwater

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Player Respawn Penalty Not Working
« Reply #4 on: July 18, 2011, 11:28:54 am »


               Thanks Lightfoot, I will look at that and see what I can be doing. I appreciate the feedback!
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Player Respawn Penalty Not Working
« Reply #5 on: July 18, 2011, 09:19:34 pm »


               just move the entire xp reduction section.   

if(ld_CheckDoublePenalty(oRespawner))
            ApplyHeavyPenalty(oRespawner);
        else
            ApplyPenalty(oRespawner);

down to just before

core(oRespawner);