Aller au contenu

Photo

Check which item was deleted?


  • Veuillez vous connecter pour répondre
1 réponse à ce sujet

#1
Gambler1971

Gambler1971
  • Members
  • 19 messages
I am a noob coder, so please forgive my sloppy coding.

I am trying to figure out how to check if my item (which I added to the game ok) has been deleted by the player (so that I can add it back to the merchant [I have successfully added the item ok, but I have not been able to make the item respawn if the player deletes it from their inventory]).

I am using a plot file with the following code:
// ---- SCRIPT STARTS HERE ----
#include "utility_h"
#include "wrappers_h"
#include "events_h"
// edit line below
#include "plt_gam_lfgloves_plot"
void main()
{
    string myMerchantName = "store_camp_bodahn";
// edit 5 lines below
    string myProjectName = "gam_lfgloves";
    string myItemName = "gam_lfgloves";
    resource myUtiName = R"gam_lfgloves.uti";
    string MyPlotCheck = PLT_GAM_LFGLOVES_PLOT;
    int MyCheckFlag = GAM_LFGLOVES_CHECK_FLAG;
    object oPlayer = GetHero();
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    switch ( nEventType )
    {
        case EVENT_TYPE_MODULE_START:
        {
             WR_SetPlotFlag( MyPlotCheck, MyCheckFlag, FALSE );
             break;
        }
        case EVENT_TYPE_MODULE_LOAD:
        {
            object oItem = GetObjectByTag(myItemName);
            if (!IsObjectValid(oItem)) WR_SetPlotFlag( MyPlotCheck, MyCheckFlag, FALSE );
            break;
        }
        case EVENT_TYPE_INVENTORY_REMOVED:
        {
            object oDeletedItem = GetEventObject(ev, 0);
            string MyTest = ObjectToString(oDeletedItem);
            if (MyTest == myItemName)
            {
                object oItem = GetObjectByTag(myItemName);
                if (!IsObjectValid(oItem)) WR_SetPlotFlag( MyPlotCheck, MyCheckFlag, FALSE );
                break;
            }
            break;
        }
        case EVENT_TYPE_CREATURE_ENTERS_DIALOGUE:
        {
            if ( WR_GetPlotFlag( MyPlotCheck, MyCheckFlag ) == TRUE ) return;

            object[] oNearestStores = GetNearestObjectByTag(oPlayer, myMerchantName, OBJECT_TYPE_STORE, TRUE);
            if(GetArraySize(oNearestStores) == 0) return;
            object oNearbyStore = oNearestStores[0];
            if(oNearbyStore == OBJECT_INVALID) return;
            CreateItemOnObject(myUtiName, oNearbyStore, 1);
            WR_SetPlotFlag( MyPlotCheck, MyCheckFlag, TRUE );
            break;
        }
        default:
        {
            break;
        }
    }
}
// ---- SCRIPT ENDS HERE ----

The following area is the area I have just tried to create, but wont work:
--------------------------------------------------------------------------------------------------
        case EVENT_TYPE_INVENTORY_REMOVED:
        {
            object oDeletedItem = GetEventObject(ev, 0);
            string MyTest = ObjectToString(oDeletedItem);
            if (MyTest == myItemName)
            {
                object oItem = GetObjectByTag(myItemName);
                if (!IsObjectValid(oItem)) WR_SetPlotFlag( MyPlotCheck, MyCheckFlag, FALSE );
                break;
            }
            break;
        }
--------------------------------------------------------------------------------------------------
I dont think this event is firing anything at all.

I have used the plot file so I can deal with the item being stored somewhere else other than at the camp or in my inventory (or on a follower), and if it is deleted.

Really I just want a code that will check if the vendor has an item (without saving and re-loading) and give it to him if he doesnt have it. I have used >>>> dialog [event] + start [event] + load [event] + some event triggered when items are removed <<<<< to reduce lag from my coding whilst playing the game, and handle situations that normal item checks dont resolve.

Modifié par Gambler1971, 13 décembre 2009 - 11:02 .


#2
Gambler1971

Gambler1971
  • Members
  • 19 messages
I decided to go with this instead:

SINGLE ITEM:
---------------------------------------------------------------------------------------------
// ---- SCRIPT STARTS HERE ----
#include "utility_h"
const string myMerchantName = "store_camp_bodahn";
// edit 2 lines below
const string myItemName = "gam_lfgloves";
const resource myUtiName = R"gam_lfgloves.uti";

void main()
{
    object oPlayer = GetHero();
    object oItem = GetObjectByTag(myItemName);
    if (!IsObjectValid(oItem))
    {
        object[] oNearestStores = GetNearestObjectByTag(oPlayer, myMerchantName, OBJECT_TYPE_STORE, TRUE);
        if(GetArraySize(oNearestStores) == 0) return;
        object oNearbyStore = oNearestStores[0];
        if(oNearbyStore == OBJECT_INVALID) return;
        CreateItemOnObject(myUtiName, oNearbyStore, 1, myItemName);
    }
}
// ---- SCRIPT ENDS HERE ----
---------------------------------------------------------------------------------------------

MULTIPLE ITEMS:
---------------------------------------------------------------------------------------------
// ---- SCRIPT STARTS HERE ----
#include "utility_h"
const string myMerchantName = "store_camp_bodahn";
// edit 6 lines below
const string myItemName_01 = "andraste_amulet";
const resource myUtiName_01 = R"andraste_amulet.uti";
const string myItemName_02 = "andraste_armor";
const resource myUtiName_02 = R"andraste_armor.uti";
const string myItemName_03 = "andraste_belt";
const resource myUtiName_03 = R"andraste_belt.uti";

void main()
{
    object oPlayer = GetHero();
    object[] oNearestStores = GetNearestObjectByTag(oPlayer, myMerchantName, OBJECT_TYPE_STORE, TRUE);
    if(GetArraySize(oNearestStores) == 0) return;
    object oNearbyStore = oNearestStores[0];
    if(oNearbyStore == OBJECT_INVALID) return;
    object oItem_01 = GetObjectByTag(myItemName_01);
    object oItem_02 = GetObjectByTag(myItemName_02);
    object oItem_03 = GetObjectByTag(myItemName_03);

    if (!IsObjectValid(oItem_01))
    {
        CreateItemOnObject(myUtiName_01, oNearbyStore, 1, myItemName_01);
    }
    if (!IsObjectValid(oItem_02))
    {
        CreateItemOnObject(myUtiName_02, oNearbyStore, 1, myItemName_02);
    }
    if (!IsObjectValid(oItem_03))
    {
        CreateItemOnObject(myUtiName_03, oNearbyStore, 1, myItemName_03);
    }
}
// ---- SCRIPT ENDS HERE ----
---------------------------------------------------------------------------------------------

Works in all situations I could think of, unless you use the pocket plane mod and go store the item in a chest there, then sadly you can buy a second copy of the item from the camp. Not sure what this would do to game speed on older machines, sorry for anyone who cant use this stuff.