Date: 2014/05/26 17:39:55 UTC-07:00
Type: Denizen Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'AIFightingEvents':
type: world
events:
on npc damaged by entity:
- if <context.damage.is[==].to[0]> queue stop
- define status <npc.flag[Pathfind.Status]>
- define attackerType <context.damager.prefix>
- define attacker <context.damager>
- inject s@AIAttackedEvent p:<def[attackerType]>_<def[status]>
'AIAttackedEvent':
type: task
debug: off
script:
- narrate "Herp is a Derp"
player_Wandering:
- flag npc Pathfind.Status:Fighting
- flag npc WorkingSet:!
- flag npc WorkingSet:|:<def[attacker]>|Fighting|<def[status]>
- flag <def[attacker]> Fighting.NPC:<npc>
- flag npc Fighting.PlayerList:<def[attacker]>
- run s@AIAttackResponses as:<npc> id:<npc.id>_AttackResponseQueue
'AIAttackResponses':
type: task
script:
- ^define workingSet <npc.flag[WorkingSet].as_list>
- ^define player <def[workingSet].get[1]>
- ^define task <def[workingSet].get[2]>
- ^define previousStatus <def[workingSet].get[3]>
- ^flag npc WorkingSet:!
- ^flag npc WeightedRandomChoice:35/FightBackWeak|25/CryChat|20/RunAway|10/FightBackStrong|10/Lightning
- ^inject s@WeightedRandomChoice instantly
- ^flag npc WeightedRandomChoice:!
- ^flag npc WorkingSet:|:<def[player]>|<def[result]>|<def[previousStatus]>
- ^run s@PathfindPauseActivity as:<npc> def:<def[previousStatus]> instantly
- ^inject s@AIAttackResponses p:<def[result]>
- ^run s@AIAttackResponses p:StopFighting as:<npc> def:<npc>|<player>
FightBackWeak:
- ^define equipment "hand:<i@wood_sword>"
- ^run s@EquipEscapingArgs "def:<escape:%equipment%>"
- ^execute as_server "npc sel <npc.id>"
- ^execute as_server "npc speed 0.8"
- ^trigger name:proximity state:true cooldown:3 radius:8
- ^follow <def[player]>
- ^wait <util.random.int[10].to[40]>t
- ^look <npc> <player.eye_location> duration:20t
- ^animate <npc> animation:ARM_SWING
- ^hurt <util.random.int[1].to[5]> <def[player]>
- ^execute as_server "npc sel <npc.id>"
- ^execute as_server "npc speed 1.0"
- ^equip <npc> hand:<i@air>
- ^if !<npc.is_spawned> || !<player.is_online> {
- run s@AIAttackResponses p:StopFighting as:<npc> def:<npc>|<player>
- queue clear
}
- ^inject s@AIAttackResponses p:FightBackWeak
'WeightedRandomChoice':
#
# Choose a random number from 1 to 100 and return which category the number is
# within.
#
type: task
script:
- define list <npc.flag[WeightedRandomChoice].as_list>
- define listSize <def[list].size>
- define number <util.random.int[1].to[100]>
- define counter 0
- foreach <def[list].as_list> {
- if <def[counter].is[OR_LESS].than[%listSize%]> {
- define counter <def[counter].add[1]>
- define entry_<def[counter].as_int> <def[list].get[<def[counter].as_int>]>
- define percentChance <def[entry_<def[counter].as_int>].split[/].get[1]>
- define returnValue <def[entry_<def[counter].as_int>].split[/].get[2]>
- define oldValue '<def[oldValue] || 0>'
- define lowValue '<def[oldValue].add[1]>'
- define highValue '<def[oldValue].add[%percentChance%]>'
- define oldValue '<def[highValue]>'
- if <proc[isbetween].context[%number%|%lowValue%|%highValue%]> {
- ^flag npc WeightedRandomChoice:<def[returnValue]>
- ^foreach stop
}
}
}
- define result <npc.flag[WeightedRandomChoice]>