Aller au contenu

Photo

SetObjectInteractive FALSE firing regardless of condition


  • Veuillez vous connecter pour répondre
3 réponses à ce sujet

#1
indio

indio
  • Members
  • 204 messages
//:://////////////////////////////////////////////
//    Placeable events
//:://////////////////////////////////////////////

#include "placeable_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"

const string CAMPFIRE = "pro_campfire_lightable";
const int LIGHT_CAMPFIRE = 4007; //References the VFX_Base 2DA

void main()
{
    event ev     = GetCurrentEvent();
    int   nEvent = GetEventType(ev);
    Log_Events("", ev);
    int nEventHandled = FALSE; //keep track of whether the event has been handled
    switch (nEvent)
    {
        //---------------------------------------------------------------------
        //  Sent by engine when creature clicks on the placeable.
        //---------------------------------------------------------------------
        case EVENT_TYPE_PLACEABLE_ONCLICK: // or EVENT_TYPE_APPLY_EFFECT

        object oPlayer = GetHero();
        object oCampfire = GetObjectByTag(CAMPFIRE);
        object oFlint = GetItemPossessedBy (oPlayer, "pro_cft_camp_flint");
        object [] oCampfireInvis = GetNearestObjectByTag(oPlayer, "phae_dacft_egwpn_plc", OBJECT_TYPE_PLACEABLE);

            
        int iItemCount = CountItemsByTag(oPlayer, "pro_cft_camp_flint");

        if (iItemCount  == 0)

            DisplayFloatyMessage(oPlayer, "You need flint in your inventory to light a fire.", FLOATY_MESSAGE, 16777215, 1.0);
        
        if (iItemCount  >= 1)

            ApplyEffectOnObject (EFFECT_DURATION_TYPE_PERMANENT, EffectVisualEffect(LIGHT_CAMPFIRE),oCampfire);
            SetItemStackSize( oFlint, GetItemStackSize( oFlint ) - 1);
            [u][b]SetObjectInteractive(oCampfire, FALSE);[/b][/u]
            WR_SetObjectActive(oCampfireInvis[0], TRUE);
            
        nEventHandled = TRUE;
            break;
    }
    if (!nEventHandled) //If this event wasn't handled by this script, let the core script try
    {
        HandleEvent(ev, RESOURCE_SCRIPT_PLACEABLE_CORE);
    }
}
The bold/underlined line in the above code fires regardless of the ItemCount. Everything else works just fine. Any ideas on why?

#2
TimelordDC

TimelordDC
  • Members
  • 923 messages
You need to have curly brackets around your statements in a conditional block if the block contains more than one statement. Or, in other words, the commands that need to be executed when iItemCount >= 1 should be enclosed in curly brackets. As it is now, only the first command (ApplyEffectOnObject) will be run when iItemCount >= 1

#3
indio

indio
  • Members
  • 204 messages
Thanks. I, quite literally, could not do this without the help you, Mike, Phaenan and others give.

#4
indio

indio
  • Members
  • 204 messages
Sure enough, it works :)