Aller au contenu

Photo

Item activating a placeable campfire effect


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

#1
indio

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

#include "placeable_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);
    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 oCampfire = GetObjectByTag(CAMPFIRE);
        ApplyEffectOnObject (EFFECT_DURATION_TYPE_PERMANENT, EffectVisualEffect(LIGHT_CAMPFIRE),oCampfire);

        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);
    }
}

I'm using the above code, created by Sonmeister, to light my campfire. I was hoping to be able to create the following condition for it:
- It can only be lit if activated by a specific, quicklotted item

Can someone help me creating that condition please?

#2
TimelordDC

TimelordDC
  • Members
  • 923 messages
It depends on how you want that implemented:

a) If you just want to make sure the player has the item, you could do a call to UT_CountItemInInventory or GetItemsInInventory and check the count

B) If you want the player to place the item on the fire, you need to set the placeable type to a container and can trap the EVENT_TYPE_INVENTORY_ADDED instead of EVENT_TYPE_PLACEABLE_ONCLICK to light the fire. You would also need to add an If condition to check the item added against the item you want the player to place before the fire is lit.

#3
mikemike37

mikemike37
  • Members
  • 669 messages
it would actually be pretty easy to simply check for the item in the inventory, which would prevent the "wastage" of a quickbar slot.

If you're set on using a quickslotted item, youll be needing to make an ability for the item (look at ABI_base) and assign the ability to the item. Then instead of using the EVENT_TYPE_PLACEABLE_ONCLICK event youll need to use EVENT_TYPE_CAST_AT and perform a check on the ID of the spell cast. Unfortunately, the template doesnt offer any suggestions for an obvious means of retrieving the ability.

I suppose instead you could handle the ability itself and if target is your campfire, light it. that might be easier, not too sure. i would imagine either way is possible.

edit: timelord beat me to it hehe. guess youve got options!

Modifié par mikemike37, 26 juin 2010 - 01:08 .


#4
indio

indio
  • Members
  • 204 messages
That helps. Thanks kindly.

#5
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); 
        int iItemCount = CountItemsByTag(oPlayer, "pro_cft_camp_flint");
        
        if (iItemCount  == 1)
        
            ApplyEffectOnObject (EFFECT_DURATION_TYPE_PERMANENT, EffectVisualEffect(LIGHT_CAMPFIRE),oCampfire);

        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);
    }
}

Works a treat. Thanks for the help.

#6
mikemike37

mikemike37
  • Members
  • 669 messages
ah good - think checking the inventory was a nicer idea... using up a quickbar slot is generally to be avoided unless its being used a lot.