; THIS SCRIPT IS COPYRIGHT(c) 2009 Reality Crafters LLC. ALL RIGHTS RESERVER.
; Written By: Robert 'UUICEO' Quackenbush
;
; This is the BASE
Script which Script Crafters Workshop Attack Tab will be based off.
; You
are not permitted to share this script with ANYONE including other owners of
; Script Crafters Workshop.
Using "RC_Core.rcm"
Dim AIData%(1,
10)
Dim EffectData%(1, 17)
Dim Moral%(1)
Dim NonWeaponDMG%(1, 1) ;
The min/max amount of damage the mob can do for the attack type
Dim
AnimType$(1) ; The animation the mob will use this combat round
Dim
MaxAbilitiesKnown(1) ; Total # of abilities the mob knows
Dim
AbilityNames$(1, 20) ; Up to 20 abilities per mob
Dim AbilityData%(1, 20, 1)
; If ability has range requirements they will be here
Function Main()
Attacker = Actor()
Target = Contextactor()
MaxLevelDiff% = 10
LevelDiff% = CheckLevelDiff%(Attacker, Target,
MaxLevelDiff%)
If LevelDiff% = -1 Then
If
ActorLevel(Attacker) > ActorLevel(Target) Then
Output(Attacker, "You are too high a level to attack that.")
Else
Output(Attacker, "You are too low a level to attack that.")
EndIf
Return
EndIf
AttackerHealth% =
Attribute(Attacker, "Health")
TargetHealth% = Attribute(Target,
"Health")
AddActorEffect(Attacker, "Combat", "", 0, 2, 232)
AddActorEffect(Target, "Combat", "", 0, 2, 232)
AttackerHasEffect% =
CheckEffect%(Attacker, 0)
TargetHasEffect% = CheckEffect%(Target, 1)
AIState% = CheckAI%(Attacker, Target)
CombatActive% =
CheckCombatActive%(Attacker, Target)
InRange% = CheckDistance%(Attacker,
Target)
AttWeapon$ = ItemName(ActorWeapon(Attacker))
TarWeapon$
= ItemName(ActorWeapon(Target))
GetCombatAnimation(AttWeapon$,
TarWeapon$, Attacker, Target)
Retreating = UpdateAI%(Attacker,
Target, AIState%) ; Increase or Decrease the combat
;
effectiveness according to the
;
position the AI is in.
AttackerDefence% = CalculateDefenceValue%(Attacker, CombatActive%)
TargetDefence% = CalculateDefenceValue%(Target, CombatActive%)
Attacker_AttackValue% = CalculateAttackValue%(Attacker) + Moral%(0)
Target_AttackValue% = CalculateAttackValue%(Target) + Moral%(1)
Attacker_AdjustedAttackValue% = (Attacker_AttackValue% - (TargetDefence% / 4)) +
Rand(-15, 15)
Target_AdjustedAttackValue% = (Target_AttackValue% -
(AttackerDefence% / 4)) + Rand(-15, 15)
If Attacker_AdjustedAttackValue%
> TargetDefence% Then
AttackerHit% = 1
If AIState% =
2 Or AIState% = 3
CheckClass(Attacker, 0)
EndIf
Else
AttackerHit% = 0
EndIf
If AttackerHit%
= 1 And (AIState% = 2 Or AIState% = 3) And Retreating <> 1 Then
If Rand(1, 100) < 51 Then
AUsingAbility =
UseAbility%(Attacker, Target, AIState%, 0)
EndIf
EndIf
If Target_AdjustedAttackValue% > AttackerDefence% Then
TargetHit% = 1
If AIState% = 1 Or AIState% = 3
CheckClass(Target, 1)
EndIf
Else
TargetHit% = 0
EndIf
If TargetHit% = 1 And (AIState% = 1 Or AIState% = 3) And
Retreating <> 11 Then
If Rand(1, 100) < 51 Then
TUsingAbility = UseAbility%(Attacker, Target, AIState%, 1)
EndIf
EndIf
If AttackerHit% = 1 And AUsingAbility = 0 Then
MaxDmg% = ItemDamage(ActorWeapon(Attacker)) + NonWeaponDMG%(0, 1) + Moral%(0) +
Int(Attribute(Attacker, "Strength") / 4)
MinDmg% = 1
If
NonWeaponDMG%(0, 0) > 0 Then
MinDmg% = NonWeaponDMG%(0, 0)
EndIf
AnimateActor(Attacker, AnimType$(0), 1.0)
DamageDealt% = Rand(MinDmg%, MaxDmg%)
If DamageDealt% > 0
Then
CreateFloatingNumber(Target, -DamageDealt%, 25, 200, 200)
Output(Attacker, "You hit " + Name(Target) + " for " +
DamageDealt% + " Damage.", 20, 250, 10)
Output(Target, "You were
hit by " + Name(Attacker) + " for " + DamageDealt% + " Damage.", 20, 250, 10)
If TargetHealth% <= DamageDealt% Then
TargetKilled% = 1
Else
TargetKilled% = 0
SetAttribute(Target, "Health", Attribute(Target, "Health") -
DamageDealt)
EndIf
Else
Output(Attacker, "You missed.")
EndIf
Else
;
AnimateActor(Attacker, AnimType$(0), 1.0)
; Output(Attacker, "You
missed.")
EndIf
If TargetHit% = 1 And CombatActive% = 1 And
TUsingAbility = 0 Then
MaxDmg% = ItemDamage(ActorWeapon(Target)) +
NonWeaponDMG%(1, 1) + Moral%(1) + Int(Attribute(Target, "Strength") / 4)
MinDmg% = 1
If NonWeaponDMG%(1, 0) > 0 Then
MinDmg% = NonWeaponDMG%(1, 0)
EndIf
AnimateActor(Target,
AnimType$(1), 1.0)
DamageDealt% = Rand(MinDmg%, MaxDmg%)
If DamageDealt% > 0 Then
CreateFloatingNumber(Attacker,
-DamageDealt%, 25, 200, 200)
Output(Target, "You hit " +
Name(Attacker) + " for " + DamageDealt% + " Damage.", 20, 250, 10)
Output(Attacker, "You were hit by " + Name(Target) + " for " + DamageDealt% +
" Damage.", 20, 250, 10)
If AttackerHealth% <= DamageDealt%
Then
AttackerKilled% = 1
Else
AttackerKilled% = 0
SetAttribute(Attacker, "Health",
Attribute(Attacker, "Health") - DamageDealt)
EndIf
Else
Output(Target, "You missed.")
EndIf
Else
; AnimateActor(Target, AnimType$(1), 1.0)
;
Output(Target, "You missed.")
EndIf
If TargetKilled% = 1 Then
; Output(Attacker, "You killed " + Name(Target) + "!", 25, 150, 100)
Output(Target, "You were killed by " + Name(Attacker) + "!", 25,
200, 50)
GiveKillXP(Target, Attacker)
LootDrop(Attacker,
Target, 1, Attacker)
KillActor(Target, Attacker)
EndIf
If AttackerKilled% = 1 Then
; Output(Target, "You killed " +
Name(Attacker) + "!", 25, 150, 100)
Output(Attacker, "You were
killed by " + Name(Target) + "!", 25, 200, 50)
GiveKillXP(Attacker,
Target)
LootDrop(Attacker, Target, 0, Target)
KillActor(Attacker, Target)
EndIf
End Function
;
Determine which animation the actors will use when in combat
Function
GetCombatAnimation(AttWeapon$, TarWeapon$, fAttacker, fTarget)
Pass
= -1
Repeat
Pass = Pass + 1
If Pass = 1 Then
Check = ItemWeaponType(TarWeapon$)
Else
Check = ItemWeaponType(AttWeapon$)
EndIf
Select
Check
Case 0
AnimType$(Pass)
= "Default attack"
Case 1
AnimType$(Pass) = "Right hand attack"
Case 2
AnimType$(Pass) = "Two hand attack"
Case 3
AnimType$(Pass) = "Bow attack"
End Select
Until Pass = 1
End Function
;
Determine what class each actor is and get any special info for that class
Function CheckClass(fCurrentActor, WHO%)
AC$ =
Lower(Class(fCurrentActor))
Select AC$
Case "dog"
AIData%(WHO%, 0) = 1 ; Treasure type
1 (small furry animals)
AnimType$(WHO%) = "Bite"
If Name(fCurrentActor) = "Attack Dog" Then
NonWeaponDMG%(WHO%, 0) = 3
NonWeaponDMG%(WHO%, 1) = 10
EndIf
Case "spider"
MaxAbilitiesKnown(WHO%) = 1
AIData%(WHO%, 0) = 2 ; Treasure type
2 (Arachnid)
AnimType$(WHO%) = "Bite"
If
Name(fCurrentActor) = "Spider" Then
NonWeaponDMG%(WHO%, 0) =
5
NonWeaponDMG%(WHO%, 1) = 15
EndIf
; Only add actual 'ACTOR EFFECTS' here. Those are things that give
an effect to the actor
; from some other item or spell. These things
usually give an Effect Icon on the players
; screen. Such items would
include drinking a 'Strength' Potion or getting a 'Blessing'
; spell cast on
you. These should be things that have an extended duration like a potion
;
to increase your Dexterity for 5 minutes rather than an immediate effect that
goes away
; right away (such as a heal potion).
; *** PLEASE NOTE
***
; Anything lised below should not be automatically handled by the Effect
(Such as a
; Strength Effect). If your strength effect does more than
increase the strength of the
; effected person then it is OK to add it in..
but if it only effects the strength of the
; effected person then there is
no need to add it in here because the addeffect command
; will handle adding
and removing the bonus to the effected player and nothing else need
; be
done. But, If you wanted to increase a players attack as well as their strength
; with a Strength potion/spell then you would need to add it in here and
also add
; everything but the Strength part that the effect is going to
imbue to the effected.
; Check to ensure the levels of
Attacker and Target are within the allowed range
Function
CheckLevelDiff%(fAttacker, fTarget, MaxLevelDiff)
If
Abs(ActorLevel(fAttacker) - ActorLevel(fTarget)) > MaxLevelDiff Then
Return(-1)
Else
Return(Abs(ActorLevel(fAttacker) -
ActorLevel(fTarget)))
EndIf
End Function
; Check to see
if Target and Attacker have targeted each other. If so then combat is active
Function CheckCombatActive%(fAttacker, fTarget)
; If Target has
targeted the attacker and vise-versa
; then we can assume the combat is
active.
If ActorTarget(fTarget) = fAttacker And
ActorTarget(fAttacker) = fTarget Then
Return(True)
Else
Return(False)
EndIf
End Function
; Check the
distance between Attacker and Target to determine if they are within weapons
range
Function CheckDistance%(fAttacker, fTarget)
ActualDistance% = ActorDistance(fAttacker, fTarget) ; Actual distance between
attacker and defender
AttackRange% =
ItemRange(ActorWeapon(fAttacker)) ; Weapon range of attacker
DefenderRange% = ItemRange(ActorWeapon(fTarget)) ; Weapon range of defender
If AttackerRange% <= ActualDistance% Then
Amin%
= 1 ; Attacker Weapon is in range
Else
Amin% = 0 ;
Attacker Weapon is not in range
EndIf
If DefenderRange%
<= ActualDistance% Then
If Amin% = 1 Then
Return(3) ; Both Attacker and Target weapons are in range
Else
Return(2) ; Only Defender weapon is in range
EndIf
Else
Return(Amin%)
EndIf
End Function
; Determin Base defence value based on current
actors 'speed', defence, dexterity
; + (amulet & ring values) + all
armor values
Function CalculateDefenceValue%(fCurrentActor, fCombatActive%)
; Determine
which (if any) combatants are NPC's
Function CheckAI%(fAttacker, fTarget)
If ActorIsHuman(fAttacker)
RtnValue% = 1 ; Only
Attacker is Human
EndIf
If ActorIsHuman(fTarget) And
RtnValue% = 1 Then
Return(0) ; Both Attacker and Target are
Human
ElseIf ActorIsHuman(fTarget) And RtnValue% = 0 Then
RtnValue% = 2 ; Only Target is Human
ElseIf RtnValue% = 0 And
ActorIsHuman(fTarget) = False Then
RtnValue% = 3 ; Neither
Attacker or Target are Human
EndIf
Return(RtnValue%)
End Function
; Calculate Retreat values and strength positions
in the fight
Function UpdateAI%(fAttacker, fTarget, AIState%)
If
AIState% = 0 Then
Return(0)
EndIf
If AIState% =
1 Or AIState% = 3 Then ; Target is AI or Both are AI
If
Attribute(fTarget, "Intelligence") < 10 Then
TPosition =
TPosition - 2
TRetreat = TRetreat - 3
EndIf
If Attribute(fTarget, "Intelligence") < 6 Then
TPosition
= TPosition - 2
TRetreat = TRetreat - 5
EndIf
If Attribute(fTarget, "Intelligence") > 9 Then
TPosition = TPosition + 2
EndIf
If Attribute(fTarget,
"Intelligence") > 14 Then
TPosition = TPosition + 1
EndIf
If Attribute(fTarget, "Intelligence") > 19 Then
TPosition = TPosition + 1
EndIf
If
Attribute(fTarget, "Intelligence") > 24 Then
TPosition =
TPosition + 1
EndIf
If Attribute(fTarget, "Health") <
(MaxAttribute(fTarget, "Health") / 3) Then
TRetreat = TRetreat +
3
TPosition = TPosition - 1
EndIf
If
Attribute(fTarget, "Health") < (MaxAttribute(fTarget, "Health") / 2) Then
TRetreat = TRetreat + 2
TPosition = TPosition -
1
EndIf
If Attribute(fAttacker, "Health") <
(MaxAttribute(fAttacker, "Health") / 3) Then
TRetreat = TRetreat
- 3
TPosition = TPosition + 1
EndIf
If
Attribute(fAttacker, "Health") < (MaxAttribute(fAttacker, "Health") / 2) Then
TRetreat = TRetreat - 2
TPosition = TPosition +
1
EndIf
Moral%(1) = TPosition
EndIf
If AIState% = 2 Or AIState% = 3 Then ; Attacker is AI Or Both are AI
If Attribute(fAttacker, "Intelligence") < 10 Then
APosition = APosition - 2
ARetreat = ARetreat - 3
EndIf
If Attribute(fAttacker, "Intelligence") < 6 Then
APosition = APosition - 2
ARetreat = ARetreat - 5
EndIf
If Attribute(fAttacker, "Intelligence") < 10 Then
APosition = APosition - 2
EndIf
If
Attribute(fAttacker, "Intelligence") > 9 Then
APosition =
APosition + 2
EndIf
If Attribute(fAttacker,
"Intelligence") > 14 Then
APosition = APosition + 1
EndIf
If Attribute(fAttacker, "Intelligence") > 19 Then
APosition = APosition + 1
EndIf
If
Attribute(fAttacker, "Intelligence") > 24 Then
APosition =
APosition + 1
EndIf
If Attribute(fAttacker, "Health")
< (MaxAttribute(fAttacker, "Health") / 3) Then
ARetreat =
ARetreat + 3
APosition = APosition - 1
EndIf
If Attribute(fAttacker, "Health") < (MaxAttribute(fAttacker, "Health") /
2) Then
ARetreat = ARetreat + 2
APosition =
APosition - 1
EndIf
If Attribute(fTarget, "Health") <
(MaxAttribute(fTarget, "Health") / 3) Then
ARetreat = ARetreat -
3
APosition = APosition + 1
EndIf
If
Attribute(fTarget, "Health") < (MaxAttribute(fTarget, "Health") / 2) Then
ARetreat = ARetreat - 2
APosition = APosition +
1
EndIf
Moral%(0) = APosition
EndIf
If
AIState% = 3 Then
If TRetreat <= ARetreat Then
If
TRetreat < 0 Then
needed = 5
EndIf
If TRetreat < -1 Then
needed = needed + 4
EndIf
If TRetreat < -2 Then
needed = needed + 3
EndIf
If TRetreat < -3
Then
needed = needed + 2
EndIf
If TRetreat < -4 Then
needed = needed + 1
EndIf
If TRetreat < -5 Then
needed =
needed + 1
EndIf
If TRetreat < -6 Then
needed = needed + 1
EndIf
If
TRetreat < -7 Then
needed = needed + 1
EndIf
If TRetreat < -8 Then
needed =
needed + 1
EndIf
If TRetreat < -9 Then
needed = needed + 1
EndIf
If
(Rand(1, 20) + TPosition) < needed Then
If
ActorAggressiveness(fTarget) <> 2 Then
TRetreating
= True
Else
TRetreating = False
EndIf
Else
TRetreating =
False
EndIf
Else
If ARetreat < 0
Then
needed = 5
EndIf
If
ARetreat < -1 Then
needed = needed + 4
EndIf
If ARetreat < -2 Then
needed =
needed + 3
EndIf
If ARetreat < -3 Then
needed = needed + 2
EndIf
If
ARetreat < -4 Then
needed = needed + 1
EndIf
If ARetreat < -5 Then
needed =
needed + 1
EndIf
If ARetreat < -6 Then
needed = needed + 1
EndIf
If
ARetreat < -7 Then
needed = needed + 1
EndIf
If ARetreat < -8 Then
needed =
needed + 1
EndIf
If ARetreat < -9 Then
needed = needed + 1
EndIf
If
(Rand(1, 20) + APosition) < needed Then
If
ActorAggressiveness(fAttacker) <> 2 Then
ARetreating = True
Else
ARetreating
= False
EndIf
Else
ARetreating = False
EndIf
EndIf
ElseIf
AIState% = 2 Then
If ARetreat < 0 Then
needed = 5
EndIf
If ARetreat < -1 Then
needed = needed + 4
EndIf
If
ARetreat < -2 Then
needed = needed + 3
EndIf
If ARetreat < -3 Then
needed =
needed + 2
EndIf
If ARetreat < -4 Then
needed = needed + 1
EndIf
If
ARetreat < -5 Then
needed = needed + 1
EndIf
If ARetreat < -6 Then
needed =
needed + 1
EndIf
If ARetreat < -7 Then
needed = needed + 1
EndIf
If
ARetreat < -8 Then
needed = needed + 1
EndIf
If ARetreat < -9 Then
needed =
needed + 1
EndIf
If Rand(1, 25) < needed Then
ARetreating = True
If (Rand(1, 20) +
APosition) < needed
If ActorAggressiveness(fAttacker)
<> 2 Then
ARetreating = True
Else
ARetreating = False
EndIf
Else
ARetreating = False
EndIf
Else
ARetreating =
False
EndIf
ElseIf AIState% = 1 Then
If TRetreat < 0 Then
needed = 5
EndIf
If TRetreat < -1 Then
needed = needed + 4
EndIf
If TRetreat < -2 Then
needed = needed + 3
EndIf
If TRetreat < -3
Then
needed = needed + 2
EndIf
If TRetreat < -4 Then
needed = needed + 1
EndIf
If TRetreat < -5 Then
needed =
needed + 1
EndIf
If TRetreat < -6 Then
needed = needed + 1
EndIf
If
TRetreat < -7 Then
needed = needed + 1
EndIf
If TRetreat < -8 Then
needed =
needed + 1
EndIf
If TRetreat < -9 Then
needed = needed + 1
EndIf
If
Rand(1, 25) < needed Then
If (Rand(1, 20) + TPosition)
< needed Then
If ActorAggressiveness(fTarget)
<> 2 Then
TRetreating = True
Else
TRetreating = False
EndIf
Else
TRetreating = False
EndIf
Else
TRetreating =
False
EndIf
EndIf
If TRetreating = True Then
Output(fAttacker, Name(fTarget) + " is fleeing!")
X =
ActorX(fTarget) + Rand(-250, 250)
Z = ActorZ(fTarget) + Rand(-250,
250)
SetActorTarget(fTarget)
SetActorDestination(fTarget, X, Z)
SetActorAIState(fTarget, 2)
DoEvents(1500)
EndIf
If ARetreating = True Then
Output(fTarget, Name(fAttacker) + " is fleeing!")
X =
ActorX(fAttacker) + Rand(-250, 250)
Z = ActorZ(fAttacker) +
Rand(-250, 250)
SetActorTarget(fAttacker)
SetActorDestination(fAttacker, X, Z)
SetActorAIState(fAttacker, 2)
DoEvents(1500)
EndIf
If ARetreating = True Then
Return(1)
ElseIf TRetreating = True Then
Return(11)
Else
Return(0)
EndIf
End Function
; Allows an NPC to use an ability if they have one to use
Function
UseAbility%(fAttacker, fTarget, AIState%, WHO%)
; WHO% 0 = Attacker
; WHO% 1 = Target
AB = Rand(1, MaxAbilitiesKnown(WHO%))
Select WHO%
Case 0
AbilityUsed = 1
Case 1
AbilityUsed = 1
End Select
If AB > 0 And AbilityUsed = 1 Then
ThreadExecute(AbilityNames$(WHO%, AB), "Main", fAttacker, fTarget)
Return(1)
Else
Return(0)
EndIf
End Function
; Determine loot dropped for Victor after combat is over
Function
LootDrop(fAttacker, fTarget, WHO%, Victor%)