SphereCommunity
Odd issue with my potion drinking EVENT. - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Odd issue with my potion drinking EVENT. (/Thread-Odd-issue-with-my-potion-drinking-EVENT)

Pages: 1 2


Odd issue with my potion drinking EVENT. - Rayvolution - 09-18-2012 11:14 PM

I'm trying to get my potion drinking script to work, and the only way I can is with a little work around. But, the work around should *not* be required. I'm totally puzzled why it's acting the way it is.

The "Working" script with the work around, you'll notice I had to create a new potion, have the NPC drink that, then consume the original one:

Code:
ON=@GetHit
    IF (<RESTEST 1 i_potion_regeneration_health>) && (<HITPOINTS> < <STR>) && (<EVAL RAND(5)> == 1)
            SERV.NEWITEM i_potion_regeneration_health
            EMOTE drink a <NEW.NAME>!
            NEW.CONT=<findlayer.21.uid>
            USEITEM <NEW>
                 return 1
    ENDIF

What SHOULD work, but isn't. It's actually making the NPC's target attempt to drink the potion in the NPC's backpack.

Code:
ON=@GetHit
    IF (<RESTEST 1 i_potion_regeneration_health>) && (<HITPOINTS> < <STR>) && (<EVAL RAND(5)> == 1)
            EMOTE drink a <NEW.NAME>!
                 findid.i_potion_regeneration_health.useitem
                 return 1
    ENDIF

Any advice? Tongue


RE: Odd issue with my potion drinking EVENT. - Mordaunt - 09-18-2012 11:34 PM

Doesn't CONSUME make the item work like it has been used?


RE: Odd issue with my potion drinking EVENT. - darksun84 - 09-19-2012 12:07 AM

I think because useitem(fired from an item) refers to the src, and in @gethit the src is the character that do the damage.

The workaround works because that USEITEM fires from the character that receives the damage.

You should try to do :
PHP Code:
ON=@GetHit
    
IF (<RESTEST 1 i_potion_regeneration_health>) && (<HITPOINTS> < <STR>) && (<EVAL RAND(5)> == 1)
            
USEITEM <findid.i_potion_regeneration_health//or something similar :P
              
return 



RE: Odd issue with my potion drinking EVENT. - Rayvolution - 09-19-2012 02:06 AM

(09-19-2012 12:07 AM)darksun84 Wrote:  I think because useitem(fired from an item) refers to the src, and in @gethit the src is the character that do the damage.

The workaround works because that USEITEM fires from the character that receives the damage.

You should try to do :
PHP Code:
ON=@GetHit
    
IF (<RESTEST 1 i_potion_regeneration_health>) && (<HITPOINTS> < <STR>) && (<EVAL RAND(5)> == 1)
            
USEITEM <findid.i_potion_regeneration_health//or something similar :P
              
return 

I tried that method also before posting, didn't work. Has the same effect; the attacker tried to use the NPC's potion in the NPC's pack. Sad

I also wanted to make sure it wasnt something totally wonky with my potions (they're completely custom) so I tested it on an i_candle instead of a potion, and when it fired my character (who was attacking the potion drinker) equipped the NPC's i_candle in his pack. lol. Tongue


RE: Odd issue with my potion drinking EVENT. - darksun84 - 09-19-2012 03:04 AM

I tried same trigger with default yellow potion and it works Shock


RE: Odd issue with my potion drinking EVENT. - Rayvolution - 09-19-2012 03:59 AM

very strange! When I get home, I'll try again. Maybe I typo'ed/goofed somewhere. I was writing that in the wee hours of the night Tongue


RE: Odd issue with my potion drinking EVENT. - Rayvolution - 09-19-2012 08:24 AM

IF (<RESTEST 1 i_potion_heal_minor>) && (<HITPOINTS> < (<STR>/2)) && (<EVAL RAND(5)> == 1)
EMOTE drink a <findid.i_potion_heal_minor.name>! // <--This works! (EDIT: I even removed the .name part and it'll display the UID of the potion it found in the character's pack.)
USEITEM <findid.i_potion_heal_minor>
return 1
ENDIF

Still doesn't work. Sad

Also tried:
findid.i_potion_heal_minor.useitem
findid.i_potion_heal_minor.use
USE <findid.i_potion_heal_minor>

Here's the entire code for everything related to the script..

The Event:
Code:
[EVENTS e_AI_Potion_Drinker]
ON=@GetHit
    IF (<RESTEST 1 i_potion_heal_minor>) && (<HITPOINTS> < (<STR>/2)) && (<EVAL RAND(5)> == 1)
            EMOTE drink a <findid.i_potion_heal_minor.name>!
            USEITEM <findid.i_potion_heal_minor>
                 return 1
    ENDIF

Potion itself:
Code:
[ITEMDEF I_POTION_HEAL_MINOR]
ID I_BOTTLE_SMALL_FULL
NAME Minor Heal Potion
TYPE T_POTION
VALUE
TDATA1 I_BOTTLE_SMALL_EMPTY
RESOURCES I_BOTTLE_SMALL_WATER,I_REAG_GINSENG 2
SKILLMAKE ALCHEMY 5.0
CATEGORY=Aetharia Magic Items
SUBSECTION=Potions
DESCRIPTION=Heal Minor
ON=@CREATE
COLOR 028
MORE1 S_HEAL_POTION
MORE2 30

[SPELL 805]
DEFNAME S_HEAL_POTION
NAME Heal
FLAGS SPELLFLAG_TARG_CHAR|SPELLFLAG_DIR_ANIM| SPELLFLAG_FX_TARG | SPELLFLAG_PLAYERONLY
RUNE_ITEM I_RUNE_ALCHEM_3
DURATION 2*60.0,4*60.0
ON=@EFFECT
IF <SRC.HITS> < <SRC.MAXHITS>
  SRC.HITS += <ARGO.dMORE2>
  IF <SRC.HITS> > <SRC.MAXHITS>
   SRC.HITS <SRC.MAXHITS>
  ENDIF
ENDIF

Changes to t_potion def:
Code:
[TYPEDEF T_POTION]
ON=@DCLICK
IF <TOPOBJ> != <SRC>
SRC.SYSMESSAGENEG <NAME> must be in your backpack.
RETURN 1
ENDIF

The test NPC with the event:
Code:
[CHARDEF c_m_alton_guard]
NAME=#NAMES_HUMANMALE the Alton City Guard
ID=BASE_C_ELF_MALE
DESIRES=i_gold,e_notoriety,t_magic
AVERSIONS=t_TRAP,t_eerie_stuff
TSPEECH=spk_human_prime
TSPEECH=jobGuard
TSPEECH=spk_needs
TSPEECH=spk_rehello
TSPEECH=spk_human_default
TEVENTS=e_Human_HearUnk
TEVENTS=e_Human_Needs
TEVENTS=e_Human_ConvInit
TEVENTS=e_Human_Greet
TEVENTS=e_Human_Space
TEVENTS=e_Human_Refuse
TEVENTS=e_Human_Environ
TEVENTS=e_AI_Guard
TEVENTS=e_AI_Friendly
TEVENTS=e_AI_Potion_Drinker
CATEGORY=Alton Civilized
SUBSECTION=Guards
DESCRIPTION=Guard (male)

ON=@Create
    NPC=brain_human
    COLOR=colors_skin
    STR={100 150}
    DEX={100 150}
    INT={51 65}
    DETECTINGHIDDEN={90.0 100.0}
    FORENSICS={90.0 100.0}
    FENCING={90.0 100.0}
    PARRYING={90.0 100.0}
    SWORDSMANSHIP={30.0 50.0}
    WRESTLING={90.0 100.0}
    MACEFIGHTING={90.0 100.0}
    MAGICRESISTANCE={90.0 100.0}
    TACTICS={90.0 100.0}
    ITEMNEWBIE=random_male_hair
    COLOR=colors_hair
    ITEMNEWBIE=random_facial_hair
    COLOR=match_hair    

ON=@NPCRestock
    ITEM=i_shield_heraldic_bronze
    ITEM=i_broadsword_bronze
    ITEM=i_ringmail_tunic_iron
    ITEM=i_ringmail_sleeves_iron
    ITEM=i_ringmail_gloves_iron
    ITEM=i_leather_gorget
    ITEM=i_cape
    COLOR=colors_blue
    ITEM=i_sash
    COLOR=colors_blue
    ITEM=i_boots_thigh
    ITEM=i_potion_heal_minor,3
    ITEM=t_coin_purse

I'm *completely* stumped. I'm sure it's just a syntax problem with findid though, but what's wrong with it, I have no idea. :/


RE: Odd issue with my potion drinking EVENT. - Skul - 09-19-2012 12:04 PM

Maybe useitem does not accept an argument? Try using trysrc to do it.


RE: Odd issue with my potion drinking EVENT. - darksun84 - 09-20-2012 07:26 AM

maybe on the typedef t_potion part

SRC it's considered attacker i guess, so as skul wrote you can use trysrc on useitem


RE: Odd issue with my potion drinking EVENT. - Rayvolution - 09-20-2012 07:42 AM

Hrm, what would be the correct syntax for TRYSRC? I've never used it before, and the syntaxes ived tried on the wiki aren't working Tongue