SphereCommunity
My Shrink Potion - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Submissions (/Forum-Script-Submissions)
+--- Thread: My Shrink Potion (/Thread-My-Shrink-Potion)



My Shrink Potion - sub-zero - 01-24-2015 02:52 PM

VERSION=0.56c

[ITEMDEF i_shrink_potion]
ID=i_bottle_white
NAME=shrink potion
TYPE=t_potion
TDATA1=i_bottle_empty
RESOURCES=2 i_reag_batwing,1 i_bottle_empty
SKILLMAKE=ALCHEMY 100.0, t_mortar

ON=@CREATE
MORE1=s_shrink
MORE2=100.0
COLOR=color_gray_lt

ON=@DROPON_CHAR
REF1=<ARGO>
IF (<REF1.DISTANCE> > 2)
SRC.SMSGL=-1,500446 // That is too far away.
RETURN 1
ENDIF
IF (<REF1.FLAGS> & STATF_CONJURED)
SRC.SMSG=@03B2,0,1 You cannot shrink summoned creatures.
RETURN 1
ENDIF
IF (<REF1.FLAGS> & STATF_WAR)
SRC.SMSG=@03B2,0,1 You cannot shrink your pet while it is in combat.
RETURN 1
ENDIF
IF (<REF1.FLAGS> & STATF_ONHORSE)
SRC.SMSGL=-1,1040016 // You cannot use this while riding a mount
RETURN 1
ENDIF
IF (<REF1.ISPLAYER>)
SRC.SMSGL=-1,500329 // That's not an animal!
RETURN 1
ENDIF
IF (!<REF1.ISMYPET>)
SRC.SMSGL=-1,502676 // That's not your pet!
RETURN 1
ENDIF
IF (((<REF1.BASEID> = c_horse_pack) || (<REF1.BASEID> = c_llama_pack)) && (<REF1.FINDLAYER.LAYER_PACK.FCOUNT> > 0))
SRC.SMSGL=-1,1042563 // You need to unload your pet.
RETURN 1
ENDIF
REF1.SHRINK
IF (<AMOUNT> > 1)
AMOUNT -= 1
ELSE
REMOVE
ENDIF
RETURN 1

ON=@DCLICK
IF (<TOPOBJ.UID> != <SRC>)
SRC.SMSGL=-1,1116249 // That must be in your backpack for you to use it.
RETURN 1
ENDIF
TARGET=@03B2,0,1 What do you wish to shrink?
RETURN 1

ON=@TARGON_CHAR
REF1=<SRC.TARG.UID>
IF (<REF1.DISTANCE> > 2)
SRC.SMSGL=-1,500446 // That is too far away.
RETURN 1
ENDIF
IF (<REF1.FLAGS> & STATF_CONJURED)
SRC.SMSG=@03B2,0,1 You cannot shrink summoned creatures.
RETURN 1
ENDIF
IF (<REF1.FLAGS> & STATF_WAR)
SRC.SMSG=@03B2,0,1 You cannot shrink your pet while it is in combat.
RETURN 1
ENDIF
IF (<REF1.FLAGS> & STATF_ONHORSE)
SRC.SMSGL=-1,1040016 // You cannot use this while riding a mount
RETURN 1
ENDIF
IF (<REF1.ISPLAYER>)
SRC.SMSGL=-1,500329 // That's not an animal!
RETURN 1
ENDIF
IF (!<REF1.ISMYPET>)
SRC.SMSGL=-1,502676 // That's not your pet!
RETURN 1
ENDIF
IF (((<REF1.BASEID> = C_HORSE_PACK) || (<REF1.BASEID> = C_LLAMA_PACK)) && (<REF1.FINDLAYER.LAYER_PACK.FCOUNT> > 0))
SRC.SMSGL=-1,1042563 // You need to unload your pet.
RETURN 1
ENDIF
REF1.SHRINK
IF (<AMOUNT> > 1)
AMOUNT -= 1
ELSE
REMOVE
ENDIF
RETURN 1

ON=@TARGON_ITEM
SRC.SMSGL=-1,500329 // That's not an animal!
RETURN 1

[EOF]

any suggestion will be welcome


RE: My Shrink Potion - XuN - 01-25-2015 01:17 AM

Just a tip, to improve it using less code and creating in the proccess a function that you can use in another situations:

Instead of calling the same code twice in both triggers you can create a function with all your checks:

Code:
ON=@TARGON_CHAR
SRC.TARG.f_shrink
IF (<AMOUNT> > 1)
    AMOUNT -= 1
ELSE
    REMOVE
ENDIF
RETURN 1

ON=@DROPON_CHAR
ARGO.f_shrink
IF (<AMOUNT> > 1)
    AMOUNT -= 1
ELSE
    REMOVE
ENDIF
RETURN 1


[function f_shrink]
IF (<DISTANCE> > 2)
    SRC.SMSGL=-1,500446 // That is too far away.
    RETURN 1
ENDIF
IF (<FLAGS> & STATF_CONJURED)
    SRC.SMSG=@03B2,0,1 You cannot shrink summoned creatures.
    RETURN 1
ENDIF
IF (<FLAGS> & STATF_WAR)
    SRC.SMSG=@03B2,0,1 You cannot shrink your pet while it is in combat.
    RETURN 1
ENDIF
IF (<FLAGS> & STATF_ONHORSE)
    SRC.SMSGL=-1,1040016 // You cannot use this while riding a mount
    RETURN 1
ENDIF
IF (<ISPLAYER>)
    SRC.SMSGL=-1,500329 // That's not an animal!
    RETURN 1
ENDIF
IF (!<ISMYPET>)
    SRC.SMSGL=-1,502676 // That's not your pet!
    RETURN 1
ENDIF
IF (((<BASEID> = C_HORSE_PACK) || (<BASEID> = C_LLAMA_PACK)) && (<FINDLAYER.LAYER_PACK.FCOUNT> > 0))
    SRC.SMSGL=-1,1042563 // You need to unload your pet.
    RETURN 1
ENDIF
SHRINK 1 // shrink will create the figurine in the char's position, shrink 1 will bounce it automatically

So this way the function is being called on both triggers and you can call it via script whenever you need it with a simple x.f_shrink or trysrc <whoever> x.f_shrink, etc.