Sphereserver / Source-X

Ultima Online server emulator
Apache License 2.0
57 stars 45 forks source link

[Feature Request] New trigger: @Drink #1162

Closed canerksk closed 1 month ago

canerksk commented 11 months ago

There may be a need for a trigger that will fire when a character drinks potion. It may be necessary to replace the empty bottle returned by a potion, or you may want to adjust the time of drinking the next potion here, or you may want to turn off the loss of potion when the potion is drunk.

under void CChar::Use_Drink( CItem * pItem )

    const CItemBase *pItemDef = pItem->Item_GetDef();
    ITEMID_TYPE idbottle = (ITEMID_TYPE)pItemDef->m_ttDrink.m_ridEmpty.GetResIndex();

    int64 pDelay = 150;
    word pConsume = 1;

    TRIGRET_TYPE iRet = TRIGRET_RET_DEFAULT;
    if (IsTrigUsed(TRIGGER_DRINK))
    {
        CScriptTriggerArgs args;
        args.m_pO1 = pItem;
        args.m_VarsLocal.SetNumNew("IdBottle", idbottle);
        args.m_iN1 = pDelay;
        args.m_iN2 = pConsume;
        iRet = OnTrigger(CTRIG_Drink, this, &args);
        idbottle = (ITEMID_TYPE)args.m_VarsLocal.GetKeyNum("IdBottle");
        pDelay = args.m_iN1 ? args.m_iN1 : 150;
        pConsume = args.m_iN2 ? (word)(args.m_iN2) : 1;

        if (iRet == TRIGRET_RET_TRUE)
            idbottle = (ITEMID_TYPE)ITEMID_NOTHING;
    }

ON=@ drink // return 1 = does not give empty potions // argo =the potion she drank // local.IdBottle = empty potion id // src = drinking char // argn1 = cooldown time // argn2 = potion reduce amount

The codes here are purely examples. Although many have been tested, some may need to be rewritten.

drk84 commented 11 months ago

SpellEffect do that with argo being the item used, but it will be nice to add the coooldown time for potions as currently is hardcoded

canerksk commented 11 months ago

SpellEffect bunu argo kullanılan öğeyle yapıyor, ancak şu anda sabit kodlanmış olduğundan iksirlere bekleme süresi eklemek güzel olacak

It would also be nice if it gives an empty potion after using the potion or if it gives an empty potion with a different id.

Jhobean commented 11 months ago

I like this new trigger. Could be use on alcool bottle too.

Tolokio commented 8 months ago

SpellEffect bunu argo kullanılan öğeyle yapıyor, ancak şu anda sabit kodlanmış olduğundan iksirlere bekleme süresi eklemek güzel olacak

It would also be nice if it gives an empty potion after using the potion or if it gives an empty potion with a different id.

image image

U can modify data1 to retrieve a diferent empty bottle or whatever. And u can do it by script before potion is consumed,for example using the trigger drk84 said: @spelleffect or any other trigger that allow u to modify tdata1 before potion is consumed.

and LAYER_FLAG_PotionUsed should be able to be modified so u can set there the CoolDown by many ways.

image For example using @MEMORYEQUIP

on=@memoryequip
IF (<ARGN1> == LAYER_FLAG_PotionUsed)
      timer= 25
      if <src.tag0.potioverride>
           timer -=<src.tag0.potioverride>
           src.tag0.potioverride
     endif
eNDIF

I agree trigger could be interesting, maybe something like this:

    const CItemBase *pItemDef = pItem->Item_GetDef();
    if ((IsTrigUsed(TRIGGER_DRINK))
    {
        CScriptTriggerArgs pArgs;
        pArgs.m_iN1 = idbottle;
        if (pItem->OnTrigger(ITRIG_DRINK, this, &pArgs) == TRIGRET_RET_TRUE)
        {
            return;
        }
    }
    ITEMID_TYPE idbottle = (ITEMID_TYPE)pItemDef->m_ttDrink.m_ridEmpty.GetResIndex();
   on=@drink
   if (<type>==t_booze)  
       IF <src.tag. drunk>
            src.spelleffect s_bless 100.0 
       endif
        //You can script custom cd for boozes here.
   elif (<type>==t_potion && !<src.findlayer.layer.LAYER_FLAG_PotionUsed>) //be sure u will drink the potion!
       IF <src.tag. drunk>
          //modify potion before everything takes places.
          more1=s_poison 
          more2=1000
          Tdata1 = //no bottle back, put it on the floor instead
          serv.newitem i_cristals_2
          new.p=<src.p>
          src.message Why do u do this to me? Dont dare to give this %&/$ to me again!!
          tdata2=3000 //cd timer override ???
       endif
   else
       IF <src.tag. drunk>
              src.message I dont want to drink this.
              return 1
       endif
   endif
Tolokio commented 8 months ago

SpellEffect do that with argo being the item used, but it will be nice to add the coooldown time for potions as currently is hardcoded

Should be nice to use tdata2 for it. so if tdata2 is defined it would be used to override potion's cd.

canerksk commented 7 months ago

When the potion is made with the tdata value, this will be valid for all items. It seems like it would be nice to set the empty potion refund in a customized settings menu so that it can be turned on and off. For example, Empty Bottle Return is on/off and this will be character based. I don't think it's shockingly effective to include too many triggers instead of controlling many things about the pot you drink with a single trigger.