DeleteSkinFloat(object, string)

Removes a persistent floating point variable from a creature's skin item.

void DeleteSkinFloat(
    object oCreature,
    string sVariableName
);

Parameters

oCreature

The creature object whose skin will have the variable removed from it.


sVariableName

The variable name used to identify the variable removed from the skin.


Description

Removes a persistent floating point variable from a creature's skin item. These variables are persistent when applied to a PC and travel with the character when exported.



Remarks

The variable name specified in sVariableName will be stripped of all underscore characters. Thus, a variable name specified as "My_Custom_Variable" will actually be stored under the name "MyCustomVariable".

If the object specified by oCreature is an NPC, the variable is removed from the creature itself rather than its skin. If used on an NPC who possesses an item with the TAG "x3_it_pchide", that item will be destroyed.

If used on a PC, the variable is removed from the skin item equipped in the PC's creature armor slot.

If used on a PC who has no item equipped in the creature armor slot, the PC is searched for an item with the TAG "x3_it_pchide". If one is found, the variable is removed from that item and the PC is forced to try and equip it into its creature armor slot. Should the item found be one that is not equippable in the creature armor slot, the equip action will fail but the variable will still be removed from the item found.

If used on a PC who has no item equipped in the creature armor slot and also does not possess an item with the TAG "x3_it_pchide", a new skin item is created from the standard blueprint "x3_it_pchide" and added to the PC's inventory. The PC is forced to equip the new skin in the creature armor slot.

Because of the special treatment of items whose TAG is set to "x3_it_pchide", it is important to not create items with that TAG that are not skin items. It is also important to ensure creatures will never possess more than one item with the TAG "x3_it_pchide".


Known Bugs

Although not technically a bug per se, a PC that has no skin equipped who is carrying an item with the TAG "x3_it_pchide" will be commanded to equip that item into the creature armor slot even when the item is not a skin. This does not cause a bug, but it does waste time trying to make the PC do something he is incapable of.

Should this function be used on a PC who has no skin equipped and is carrying more than one item with the TAG "x3_it_pchide", there's no telling which of the items will have the variable removed from it.

Due to the fact that the variable name is stripped of all underscores, it is not possible to use this function (or GetSkinFloat or SetSkinFloat either) to treat two skin variables whose names differ only by underscores as independent separate variables. In other words, if you use a skin variable called "My_Custom_Variable" you cannot have a different skin variable called "MyCustomVariable" since this function (and GetSkinFloat and SetSkinFloat as well) will treat them both as the same variable. The easiest way to avoid any potential problems related to this issue is to simply not put any underscores into your skin variable names.


Requirements

#include "x3_inc_skin"

Version

1.69

Example


// In this example the player is talking with a banker NPC in order to repay a loan he
// took out earlier. When the loan was issued the name of the agent who issued the
// loan, the amount borrowed, the date/time when the loan was made, and the daily
// interest rate were all stored on the player's skin so they would persist.
// The ActionTaken script below is being used to repay the loan in a conversation with
// the banker. The values are retrieved from the player's skin, the total amount due
// is computed and taken from his gold supply, and the loan variables are then removed
// from the skin item to indicate the player no longer has an outstanding debt to pay.
// It is assumed that there is a custom function called GetLoanPeriod that, given a
// date/time string, will compute the time period between that time and the current
// game time as measured in days including fractions.


// ActionTaken script - repay a bank loan
#include "x3_inc_skin"

void main()
{
    // First find the player who is talking to the NPC.
    object oPC = GetPCSpeaker();

    // Next, retrieve the loan variables from the player' skin.
    string sAgent     = GetSkinString(oPC, "EastSideBank LoanAgent");
    string sTime      = GetSkinString(oPC, "EastSideBank LoanTime");
    int    iPrincipal = GetSkinInt(   oPC, "EastSideBank Principal");
    float  fRate      = GetSkinFloat( oPC, "EastSideBank DailyRate");

    // If any of the variables are not valid, return without doing anything further.
    // Most likely the player has no variables at all and therefore does not have an
    // outstanding loan due.
    if((sAgent == "") || (sTime == "") || (iPrincipal <= 0) || (fRate < 0.0))
    {   return;   }

    // If the banker does not recognize the agent that issued the loan, return without
    // doing anything further.
    if( (sAgent != "Edwin Stikkum") &&
        (sAgent != "Fannie Faire" ) &&
        (sAgent != "Sarah Softie" )   )
     {   return;   }

    // Compute the period of the loan measured in days since the loan was issued.
    float fPeriod = GetLoanPeriod(sTime);

    // If the loan period isn't bigger than zero then the loan time string is invalid.
    if(fPeriod <= 0.0)
    {   return;   }

    // Next, compute the interest amount to be added to the principal.
    // Start by converting the principal to a floating point number so there will be no
    // round-off errors.
    float fPrincipal = IntToFloat(iPrincipal);

    // Now compute the interest due per day by multiplying the principal by the daily
    // interest rate.
    float fDailyInterestDue = fPrincipal * fRate;

    // The total interest due is found by multiplying the daily amount due by the
    // number of days in the loan period.
    float fTotalInterestDue = fDailyInterestDue * fPeriod;

    // The total amount due is then the principal plus the total interest due.
    float fTotalDue = fPrincipal + fTotalInterestDue;

    // And the last thing is to convert it back to an integer, rounded up, to figure
    // out the number of gold pieces to take from the player.
    int iGoldPiecesDue = FloatToInt(fTotalDue + 0.5);

    // If he cannot afford to repay it, just return without processing the loan.
    if(GetGold(oPC) < iGoldPiecesDue)
    {   return;   }

    // Now relieve the player of his gold.
    TakeGoldFromCreature(iGoldPiecesDue, oPC, TRUE);

    // Finally, remove the loan variables from the player's skin to cancel the loan.
    DeleteSkinString(oPC, "EastSideBank LoanAgent");
    DeleteSkinString(oPC, "EastSideBank LoanTime");
    DeleteSkinInt(   oPC, "EastSideBank Principal");
    DeleteSkinFloat( oPC, "EastSideBank DailyRate");
}


See Also

functions:  GetSkinFloat | SetSkinFloat
categories:  Get Data Functions | Get Data from Creature Functions | Local Variables Functions


author: Axe Murderer, editors: Mistress, Kolyana, contributor: Ken Cotterill