FANDOM


Created by Taz.

Using "RC_Core.rcm"
; Taming Script
 ; Date/Time: 8:55:06 PM on 11/2/2012
; By Dan Seguin on TAZCO-PC
;Taming attrbiute should be set through the ASETLVL.RSL script NOT the GUE.
Function Main()
Player = Actor()
Target = ContextActor()



;---------------------------------------------------------------------------------------------------------------------------

;---------------------------------------------------------------------------------------------------------------------------
;Check For tamed pets are alive.

StoredTamedID% = Split(ActorGlobal(Player, 3), 21, "|") ;if > then 0 player already has a tamed pet.
    If (StoredTamedID > 0) ;if greater then 0 player has a tamed pet.
        CheckStordLeader% = ActorGlobal(StoredTamedID, 1) ;check for actors stord leader.
        TamedHP% = Attribute(StoredTamedID, "Health")
        
                 If (TamedHP <= 0) ;if tamed npc hp is lower then 0 then its dead reset split command to 0
                     ;-----------------------------------------------------------------------------------------------------------  
                     ;Store Target ID to be used in pet abilitys and to see if player has a tamed pet.
                    ;Set changes to delimiter
                    
                            HealthStat% = Split(ActorGlobal(Player, 3), 1, "|")
                            ManaStat% = Split(ActorGlobal(Player, 3), 2, "|")
                            StrStat1% = Split(ActorGlobal(Player, 3), 3, "|")
                            TouStat% = Split(ActorGlobal(Player, 3), 4, "|")
                            DefStat% = Split(ActorGlobal(Player, 3), 5, "|")
                            AgiStat% = Split(ActorGlobal(Player, 3), 6, "|")
                            WizStat% = Split(ActorGlobal(Player, 3), 7, "|")
                            StatsCurr% = Split(ActorGlobal(Player, 3), 8, "|")
                            StBak% = Split(ActorGlobal(Player, 3), 9, "|")
                            RepCurr% = Split(ActorGlobal(Player, 3), 10, "|")     ;player rep
                            Gamble% = Split(ActorGlobal(Player, 3), 11, "|")      ;used in gambling
                            ClassStored% = Split(ActorGlobal(Player, 3), 12, "|") ;stores melee, ranging and magic
                            InOutCombat% = Split(ActorGlobal(Player, 3), 13, "|")  ;use in tracker in and out of combat
                            Extra1% = Split(ActorGlobal(Player, 3), 14, "|")
                            Extra2% = Split(ActorGlobal(Player, 3), 15, "|")
                            Extra3% = Split(ActorGlobal(Player, 3), 16, "|")
                            Extra4% = Split(ActorGlobal(Player, 3), 17, "|")
                            Extra5% = Split(ActorGlobal(Player, 3), 18, "|")
                            Extra6% = Split(ActorGlobal(Player, 3), 19, "|")
                            Extra7% = Split(ActorGlobal(Player, 3), 20, "|")
                            Extra8% = 0 ;store target ID
                            
                    
                    OtherThingsToStore$ = HealthStat + "|" + ManaStat + "|" + StrStat1 + "|" + TouStat + "|" +  DefStat + "|" + AgiStat + "|" + WizStat + "|" + StatsCurr + "|" + StBak + "|" + RepCurr + "|" + Gamble + "|" + ClassStored + "|" + InOutCombat + "|" + Extra1 + "|" + Extra2 + "|" + Extra3 + "|" + Extra4 + "|" + Extra5 + "|" + Extra6 + "|" + Extra7 + "|" + Extra8

                        SetActorGlobal(Player, 3, OtherThingsToStore) ;set dilimiter to actor global 3
                    
                ;-----------------------------------------------------------------------------------------------------------  
                ;-----------------------------------------------------------------------------------------------------------      
                            
                Endif;end tamed npc hp check
        
     Endif ;end stored npc check.

;---------------------------------------------------------------------------------------------------------------------------
;END Check For tamed pets are alive.
;---------------------------------------------------------------------------------------------------------------------------



PLvl% = ActorLevel(Player)
TLvl% = ActorLevel(Target)

PName$ = Name(Player)
TName$ = Name(Target) ;Name of selected target

PTameLvl% = Attribute(Player, "Taming") ;current amount of taming level for player
TarTamLvl% = Attribute(Target, "Taming") ;current amount of taming level for Target

TarTag$ = Tag(Target)


TamedID% = ActorLeader(Target) 
StoredTamedID% = Split(ActorGlobal(Player, 3), 21, "|") ;if > then 0 player already has a tamed pet.
    
 
 If (StoredTamedID > 0)
         OutPut(Player, "You already have a tamed NPC!", 255, 127, 90)
        Return
 Endif
 
 
     If (TamedID > 0) ;if > then 0 player already has a tamed pet.
        OutPut(Player, "You can not tame this NPC!.", 255, 127, 90)
        Return
     Endif
     
     
 
 If (TarTag = + PName + " s Pet")
     OutPut(Player, "You cant tame your own pet!", 255, 0, 0)
    Return
 Endif
 
 TarIsHuman% = ActorIsHuman(Target)
     If (TarIsHuman >= 1) ;target is human tell player they cant tame target.
         OutPut(Player, "You can not tame another player!.", 255, 127, 45)
        Return
     Endif
 
     ;Check if player has a target.
    If (Target = 0)
        OutPut(Player, "You need a target before you can TAME something.", 255, 127, 27)
        Return
     Endif
 
     ;Check If players taming level is lower then targets taming level if so tell player 
    If (TarTamLvl > PTameLvl)
        OutPut(Player, "Your taming level is not high enough to tame " + TName + " You need a taming level of " + TarTamLvl + " or higher.", 255, 127, 27)
        Return
     Endif
     
     If (TarTamLvl <= 0) ;if target has 0 taming then they should not be tamed.
        OutPut(Player, "You can not tame this NPC!.", 255, 127, 45)
        Return
     Endif
     
 
                 TarDistance% = ActorDistance(Player, Target)
                If (TarDistance > 60) ;make sure the target is in range for casting
                    Output(Player, "Your target is to far away!")                 
                    DoEvents(500)
                    Return
                EndIf

    TamingTime% = TarTamLvl + PLvl * Rand(2, 3) / TLvl + Rand(5, 10) - PTameLvl ;Amount of time that will be needed to successfully tame target.

    If (TamingTime < 0) ;if formula amount above if less then 0 then set it to default time.
        TamingTime% = Rand(20, 25)    
    Endif
     
     If (PTameLvl > 35) ; if player is over level 35 taming give a better time amount.
        TamingTime% = Rand(10, 15) 
    Endif
 ;-----------------------------------------------------------------------------------------------------------
;Make casting bar
PBar% = CreateProgressBar(Player, 255, 127, 27, 0.40, 0.82, 0.2, 0.04, TamingTime, TamingTime, "Taming" + TName) ; casting bar
Ticks% = TamingTime ;amount of for ticks also change the max and valve number in the PBar above.


CreateEmitter(Player, "Default", 768, TamingTime * 100) ; casting emitter 
DoEvents(300)

;get speed to reduce it while casting.
PSpeed% = Attribute(Player, "Speed") / 2 + 3 ;take 10 from speed

AddActorEffect(Player, "Taming", "Speed", PSpeed, TamingTime, 768) 
AnimateActor(Player, "Magic", .5, 2) ;Particles and casting animation ;MAGIC needs to be a name of a animation in actors animation set.
SetActorTarget(Target, Player) ;Set target back to player
SetActorAIState(Target, 3) ;3 - Chase and attack target while player is taming

            Repeat           
            Ticks% = Ticks - 1				;take 1 tick 

                    If (Ticks = 3) or  (Ticks = 6) or (Ticks = 10) or  (Ticks = 13) ;restart animation and emitter.
                        CreateEmitter(Player, "Flame", 10, 1800, 0, + 5, 0) ; casting emitter
                        AnimateActor(Player, "Magic", .5, 2) ;Particles and casting animation
                    Endif
                    
                TarDistance% = ActorDistance(Player, Target)
                If (TarDistance > 160) ;make sure the target is still in range for casting
                    Output(Player, "Your target is to far away!")
                    DeleteProgressBar(Player, PBar) ;delete progressbar
                    DoEvents(500)
                    Return
                EndIf


            DoEvents(500) 

            ;updated progress bar has to be before actor hp if dead check. Progress bar will update then be deleted if player is dead.
           
              UpdateProgressBar(Player, PBar, Ticks)   ;update progress bar
             
               Phealth% = Attribute(Player, "Health") ;current player health
                If (Phealth <= 0) ;if players health is less then 0 stop casting since they are dead.
                     DeleteProgressBar(Player, PBar) ;delete progressbar
                     DeleteActorEffect(Player, "Casting")
                     Ticks% = 0
                     Return
                EndIf
                
               Targethealth% = Attribute(Target, "Health") ;current target health
              If (Targethealth < 2) ;if target dies then stop taming
                Ticks% = 0
                 OutPut(Player, "Your Target is dead", 250, 134, 255)                 
                 DeleteProgressBar(Player, PBar) ;delete progressbar
                 DeleteActorEffect(Player, "Casting")
               Return
              EndIf

            Until(Ticks <= 0) 				;end repeat if ticks = 0
        DeleteProgressBar(Player, PBar) ;delete progressbar
;end casting bar
;-----------------------------------------------------------------------------------------------------------
        
  ;-----------------------------------------------------------------------------------------------------------       
        ;Chance to tame pet.
 ;----------------------------------------------------------------------------------------------------------- 
          
         
     TameChance% = PTameLvl + Rand(240, 350) 
    TameMiss% = TarTamLvl  + Rand(165, 650)
        
         
         If (TameChance >= TameMiss) ; if tame chance is greater then miss chance allow player to tame.
            CreateEmitter(Target, "TamingHeart", 766, 4800, 0, + 54, 0) ; casting tamed emitter
            DoEvents(700)
            CreateEmitter(Target, "TamingHeart", 766, 4500, 0, + 54, 0) ; casting tamed emitter
            SetActorTarget(Target, 0) ;Take target from npc
            SetActorTarget(Player, 0) ;Take away players target
            SetHomeFaction(Target, "Pet") ;change npc faction
            SetLeader(Target, Player) ;Set target tamed npc as players pet.
            SetActorAIState(Target, 5)  ;5 - Pet mode - actor will follow leader and attack leader's target (actor MUST have a leader to use this) 
            SetTag(Target, + PName + " s Pet")  ;set a tag on newly got pet.
            SetAttribute(Target, "Taming", 0) ;set target taming to 0 so others cant tame it. 
            SetAttribute(Target, "Speed", Attribute(Player, "Speed")) ;set pet speed.
            
             CheckTamedID% = ActorLeader(Target)            
            SetActorGlobal(Target, 1, CheckTamedID) ;set the actor global of this pet to players leader ID. 
            
              ;-------------------------------------------------------
            ;rotate target so it faces the same way as the player.
            ;-------------------------------------------------------
                A = ActorX(Player)
                B = ActorZ(Player)
                C = ActorX(Player)
                D = ActorZ(Player)
                E = C - A
                F = D - B
                G = ATanII(F, E)
                RotateActor(Target, G)
            ;--------------------------------------------------------
            
  ;-------------------------------------------------------------------------------------------------------------------           
            ;Set new pet stats and level, based on tamin level.
            PLvl% = ActorLevel(Player) ; get player level to set tamed pet level to it.
            SetActorLevel(Target, PLvl) ;Set tamed npc tamed level
            
             GettStrAmount% = Attribute(Player, "Strength") + PTameLvl / 2
            If (GettStrAmount < 0) ;if amount is less or equil to 0 then set stat to taming level.
                GettStrAmount% = PTameLvl
            Endif
            
             GetAgiAmount% = Attribute(Player, "Agility") + PTameLvl / 2
            If (GetAgiAmount < 0) ;if amount is less or equil to 0 then set stat to taming level.
                GetAgiAmount% = PTameLvl
            Endif
            
             GetTouAmount% = Attribute(Player, "Toughness") + PTameLvl / 2
            If (GetTouAmount < 0) ;if amount is less or equil to 0 then set stat to taming level.
                GetTouAmount% = PTameLvl
            Endif
            
             GetDefAmount% = Attribute(Player, "Defence") + PTameLvl / 2
            If (GetDefAmount < 0) ;if amount is less or equil to 0 then set stat to taming level.
                GetDefAmount% = PTameLvl
            Endif
            
             GetMelAmount% = Attribute(Player, "Melee") + PTameLvl / 2
            If (GetMelAmount < 0) ;if amount is less or equil to 0 then set stat to taming level.
                GetMelAmount% = PTameLvl
            Endif
                    Healthmount% = Rand(100, 250) + PTameLvl + PLvl + TarTamLvl * 2 ;amount of health per level picked
                  
                    ;set hp
                    SetMaxAttribute(Target, "Health", Healthmount)
                    SetAttribute(Target, "Health", Healthmount)
                    ;set strength
                    SetMaxAttribute(Target, "Strength", GettStrAmount)
                    SetAttribute(Target, "Strength", GettStrAmount)
                    ;set defence
                    SetMaxAttribute(Target, "Defence", GetDefAmount)
                    SetAttribute(Target, "Defence", GetDefAmount)
                    ;set Agility
                    SetMaxAttribute(Target, "Agility", GetAgiAmount)
                    SetAttribute(Target, "Agility", GetAgiAmount)
                    ;Set Melee
                    SetMaxAttribute(Target, "Melee", GetMelAmount)
                    SetAttribute(Target, "Melee", GetMelAmount)
                    ;Set Toughness
                    SetMaxAttribute(Target, "Toughness", GetTouAmount)
                    SetAttribute(Target, "Toughness", GetTouAmount)                    
    ;end set tamed pet stats        
  ;-------------------------------------------------------------------------------------------------------------------            
            OutPut(Player, "You have successfully tamed " + Tname, 255, 127, 0)
            
            
     ;-----------------------------------------------------------------------------------------------------------  
     ;Store Target ID to be used in pet abilitys and to see if player has a tamed pet.
    ;Set changes to delimiter
    
             HealthStat% = Split(ActorGlobal(Player, 3), 1, "|")
            ManaStat% = Split(ActorGlobal(Player, 3), 2, "|")
            StrStat% = Split(ActorGlobal(Player, 3), 3, "|")
            TouStat% = Split(ActorGlobal(Player, 3), 4, "|")
            DefStat% = Split(ActorGlobal(Player, 3), 5, "|")
            AgiStat% = Split(ActorGlobal(Player, 3), 6, "|")
            WizStat% = Split(ActorGlobal(Player, 3), 7, "|")
            StatsCurr% = Split(ActorGlobal(Player, 3), 8, "|")
            StBak% = Split(ActorGlobal(Player, 3), 9, "|")
            RepCurr% = Split(ActorGlobal(Player, 3), 10, "|")     ;player rep
            Gamble% = Split(ActorGlobal(Player, 3), 11, "|")      ;used in gambling
            ClassStored% = Split(ActorGlobal(Player, 3), 12, "|") ;stores melee, ranging and magic
            InOutCombat% = Split(ActorGlobal(Player, 3), 13, "|")  ;use in tracker in and out of combat
            Extra1% = Split(ActorGlobal(Player, 3), 14, "|")
            Extra2% = Split(ActorGlobal(Player, 3), 15, "|")
            Extra3% = Split(ActorGlobal(Player, 3), 16, "|")
            Extra4% = Split(ActorGlobal(Player, 3), 17, "|")
            Extra5% = Split(ActorGlobal(Player, 3), 18, "|")
            Extra6% = Split(ActorGlobal(Player, 3), 19, "|")
            Extra7% = Split(ActorGlobal(Player, 3), 20, "|")
            Extra8% = Target ;store target ID
            
     
     OtherThingsToStore$ = HealthStat + "|" + ManaStat + "|" + StrStat + "|" + TouStat + "|" +  DefStat + "|" + AgiStat + "|" + WizStat + "|" + StatsCurr + "|" + StBak + "|" + RepCurr + "|" + Gamble + "|" + ClassStored + "|" + InOutCombat + "|" + Extra1 + "|" + Extra2 + "|" + Extra3 + "|" + Extra4 + "|" + Extra5 + "|" + Extra6 + "|" + Extra7 + "|" + Extra8

        SetActorGlobal(Player, 3, OtherThingsToStore) ;set dilimiter to actor global 3
    
 ;-----------------------------------------------------------------------------------------------------------  
;-----------------------------------------------------------------------------------------------------------      
            
             
             
             
             
         Else
              CreateEmitter(Target, "TamingFailed", 767, 4800, 0, + 54, 0) ; Failed taming emitter
             DoEvents(700)
             CreateEmitter(Target, "TamingFailed", 767, 4500, 0, + 54, 0) ; Failed taming emitter
             OutPut(Player, "You have failed to tame " + Tname, 255, 127, 0)
             SetActorTarget(Target, Player) ;Set target back to player
             SetActorAIState(Target, 3) ;Make target attack
             
              HelpChance% = Rand(1, 7) ;chance that npc will call call help if taming fails.
             
                  If (HelpChance = 1) ;if = 1 then allow npc to call for help
                    ActorCallForHelp(Target)
                    OutPut(Player, + TName + " has called for back up.", 145, 34, 234)
                 Endif                
             
         Endif
         
       
 ;--------------------------------------------------------------------------------------------------------------------
;Do exp for taming amount. 
  ;get Herbing xp, add new xp and ccheck if player has a Herbing level              
        MeleeXp% = Split(ActorGlobal(Player, 2), 1, "|")
        RangingXp% = Split(ActorGlobal(Player, 2), 2, "|")
        MagicXp% = Split(ActorGlobal(Player, 2), 3, "|")
        AlchemyXp% = Split(ActorGlobal(Player, 2), 4, "|")
        CraftingXp% = Split(ActorGlobal(Player, 2), 5, "|")
        HerbingXp% = Split(ActorGlobal(Player, 2), 6, "|")
        MiningXp% = Split(ActorGlobal(Player, 2), 7, "|")
        PrayerXp% = Split(ActorGlobal(Player, 2), 8, "|")
        SmeltingXp% = Split(ActorGlobal(Player, 2), 9, "|")
        WoodCuttingXp% = Split(ActorGlobal(Player, 2), 10, "|")
        DodgeXp% = Split(ActorGlobal(Player, 2), 11, "|")
        DexXp% = Split(ActorGlobal(Player, 2), 12, "|")
        ;extra skills for easy adding later.
        NewSkillXp1% = Split(ActorGlobal(Player, 2), 13, "|")
        NewSkillXp2% = Split(ActorGlobal(Player, 2), 14, "|") ;TamingXP
        NewskillXp3% = Split(ActorGlobal(Player, 2), 15, "|")
        NewskillXp4% = Split(ActorGlobal(Player, 2), 16, "|")
        NewskillXp5% = Split(ActorGlobal(Player, 2), 17, "|")
        NewskillXp5% = Split(ActorGlobal(Player, 2), 18, "|")

    If (TameChance >= TameMiss) ;if player was able to tame give more xp
        TamingXpToGive% = Attribute(Player, "Taming") + PTameLvl +  Rand(45, 55) + NewSkillXp2   ;total Taming xp 
    Else
         TamingXpToGive% = Attribute(Player, "Taming") + PTameLvl +  Rand(23, 25) + NewSkillXp2   ;total Taming xp 
    Endif
 		
             ;Send to levelup if Taming level should be given.
             If (TamingXpToGive >= PTameLvl * 750) ;if player has amount of xp need to level send them to level up

                ThreadExecute("LevelUp", "Main", Player, Target, 19)	;parameter for 19 = Taming 
                TamingXpToGive% = 0 ;give 0 xp after level up  
              EndIf
              
               SkillXPToStore$ = MeleeXp + "|" + RangingXp + "|" + MagicXp + "|" + AlchemyXp + "|" +  CraftingXp + "|" + HerbingXp + "|" + MiningXp + "|" + PrayerXp + "|" + SmeltingXp + "|" + WoodCuttingXp + "|" + DodgeXp + "|" + DexXp + "|" + NewSkillXp1 + "|" + TamingXpToGive + "|" + NewSkillXp3 + "|" + NewSkillXp4 + "|" + NewSkillXp5 + "|" + NewSkillXp6
  
      SetActorGlobal(Player, 2, SkillXPToStore) ;set dilimiter to actor global 2 with new melee xp amount
              
  ;-------------------------------------------------------------------------------------------------------------------- 

Return
End Function