Aller au contenu

Photo

Script to insert item on load or new character


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

#1
Gambler1971

Gambler1971
  • Members
  • 19 messages
I am very new to this game and cant code for crap. most of the following code comes from the tuts laying around on this site (thanks). What I am trying to do is make my game give me the items when I make a new character, or if it has not given it to me (as I have started before installing the mod) give it to me on load. Currently I am using:

// ---- SCRIPT STARTS HERE ----
#include "utility_h"
#include "plt_gam_mabari_plot"
void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    switch ( nEventType )
    {
        // for when a new character is started
        case EVENT_TYPE_CHARGEN_END:
        {
            int nTime = GetPlayTime();
            if (nTime < 60)
                UT_AddItemToInventory(R"gam_mabariwares_collar.uti", 1);
            if (nTime < 60)
                UT_AddItemToInventory(R"gam_mabariwares_paint.uti", 1);
            if (nTime < 60)
                WR_SetPlotFlag( PLT_GAM_MABARI_PLOT, GAM_MABARI_CHECK_FLAG, TRUE );
            break;   // probably should be a return here?
        }
    }
    // Check on load if its ever been given (give if not)
    if ( WR_GetPlotFlag( PLT_GAM_MABARI_PLOT, GAM_MABARI_CHECK_FLAG ) == TRUE )
        return;
    switch ( nEventType )
    {
        case EVENT_TYPE_MODULE_LOAD:
        {
            UT_AddItemToInventory(R"gam_mabariwares_collar.uti", 1);
            UT_AddItemToInventory(R"gam_mabariwares_paint.uti", 1);
            WR_SetPlotFlag( PLT_GAM_MABARI_PLOT, GAM_MABARI_CHECK_FLAG, TRUE );
            break;
        }
        default:
            break;
    }
}
// ---- SCRIPT ENDS HERE ----

The problem I have is there (under testing) are times when (for a new character) the item does not get given (unless I raise the time to like 2 mins). So I guess if, during the initial start screens I went and made a coffee, the play time may exceed 2 mins before I have actually gotten to the point where I can control the character.

For the load part (second part of script), it works 99% of the time, but I did have one time (as I tested by removing the timed section at the start) where I started a new char, saved and loaded, and the items did not get given. But out of the dozen or so trials I did like this, that only happened once (cant tell why).

Any one know what I am doing wrong, or have a code that would work instead?

Thanks

#2
Gambler1971

Gambler1971
  • Members
  • 19 messages
Damm...took me 2 days of getting no where...put up this post...then I came up with the following...it seems to work ok.

// ---- SCRIPT STARTS HERE ----
#include "utility_h"
#include "plt_gam_mabari_plot"
void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    switch ( nEventType )
    {
        case EVENT_TYPE_MODULE_START:
            {
             // -----------------------------------------------------------------
             // Initiate character generation.
             // -----------------------------------------------------------------
             WR_SetPlotFlag( PLT_GAM_MABARI_PLOT, GAM_MABARI_CHECK_FLAG, FALSE );
             break;
            }
    }
    // If our plot flag is set to TRUE, that means we have already
    // given the items to the player, there is no need to continue
    // running this script.
    if ( WR_GetPlotFlag( PLT_GAM_MABARI_PLOT, GAM_MABARI_CHECK_FLAG ) == TRUE )
        return;
    // We will watch for every event type and if the one we need
    // appears we will handle it as a special case. We will ignore the rest
    // of the events
    switch ( nEventType )
    {
        // This event happenes every time the module loads
        // This usually happenes when creating a new game
        // or loading a savegame
        case EVENT_TYPE_CHARGEN_END:
        {
            UT_AddItemToInventory(R"gam_mabariwares_collar.uti", 1);
            UT_AddItemToInventory(R"gam_mabariwares_paint.uti", 1);
            WR_SetPlotFlag( PLT_GAM_MABARI_PLOT, GAM_MABARI_CHECK_FLAG, TRUE );
            break;
        }
        case EVENT_TYPE_MODULE_LOAD:
        {
            UT_AddItemToInventory(R"gam_mabariwares_collar.uti", 1);
            UT_AddItemToInventory(R"gam_mabariwares_paint.uti", 1);
            WR_SetPlotFlag( PLT_GAM_MABARI_PLOT, GAM_MABARI_CHECK_FLAG, TRUE );
            break;
        }
        default:
            break;
    }
}
// ---- SCRIPT ENDS HERE ----