void main()
{
    object oPC = GetPCSpeaker(); 
    int nValue = StringToInt(GetLocalString(oPC, "I_SAID")); // Value set in conversation for tokens

    object oCasinoHandle = GetItemPossessedBy(oPC, "I_CAS_CASINOHANDLE");
    if (!GetIsObjectValid(oCasinoHandle))
    {
        SendMessageToPC(oPC, "Casino handle not found in your inventory.");
        return;
    }

    int nCurrentTokenCount = GetLocalInt(oCasinoHandle, "nCAS_TOKEN");
    if (nValue > nCurrentTokenCount)
    {
        SendMessageToPC(oPC, "You don't have enough tokens to fill out the note.");
        return;
    }

    SetLocalInt(oCasinoHandle, "nCAS_TOKEN", nCurrentTokenCount - nValue);

    object oSlipHolder = CreateItemOnObject("cas_slipholder", oPC);
    if (!GetIsObjectValid(oSlipHolder))
    {
        SendMessageToPC(oPC, "Failed to create the item. Please check your inventory space.");
        return;
    }

    SetTag(oSlipHolder, "I_CAS_TOKEN");
    SetName(oSlipHolder, "Token Slip Holder: " + IntToString(nValue));
    SetLocalInt(oSlipHolder, "nCAS_TOKEN", nValue);

    // Log the creation of the token slip and the number of tokens
    string sCharacterName = GetName(oPC);
    string sPlayerUsername = GetPCPlayerName(oPC);
    string sPCId = IntToString(PLAYER_GetId(oPC)); // Replace PLAYER_GetId with your function to get the player's ID
    string sLogMessage = "Character: " + sCharacterName + ", Player Name: " + sPlayerUsername + " (PlayerID: " + sPCId + ") created a token slip with " + IntToString(nValue) + " tokens.";
    Log(sLogMessage, "cas");
}
