-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot2.ix
188 lines (163 loc) · 5.36 KB
/
chatbot2.ix
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
;(load "https://phunanon.github.io/InsituxScripts/chatbot2.ix")
(var cmds "Examples: \"heal XxPlayerxX\" or \"heal Xx\"
\"team security\" or \"team insurgent\" - switch to either team
\"heal\" or \"heal [player]\" - heal you or a player fully
\"drone\" or \"drone [player]\" - drone strike on your or player
\"brrr [player]\" - airstrike on player
\"flare\" or \"flare [player]\" - fire a flare above yourself or player
\"boom [player]\" - kill player with an explosion
\"boom near [player]\" - explosion near the player (non-lethal)
\"tp [player] here\" or \"tp to [player]\" or \"tp [player1] to [player2]\"
\"plant\" - plant claymore where you stand")
(function rand-circle-point position radius
(var r radius)
(-> (rand (* 2 PI))
(fn a [(cos a) 0 (sin a)])
(map (* r))
@(map + position)))
(function is-near? x0 y0 z0 x1 y1 z1 dist
(> dist (sqrt
(+ (** (- x0 x1))
(** (- y0 y1))
(** (- z0 z1))))))
(function n. name
(var n name)
(find (fn p (.. starts? (map lower-case [n p])))
(alive-players)))
(function alive-players
(filter #((str "dl.players." % ".is_alive"))
(dl.list_players)))
(function grenade pos
(dl.util.explosion pos "TestGrenade"))
(var props {:pos "position" :team "team" :hp "health"})
(function plr who key value
(let prop (props key)
evar (str "dl.players." who))
(if (= key :alive?)
(return ((str "dl.players." who ".is_alive"))))
(catch
(if value
(do ((str "$" evar "." prop) value) :success)
(prop evar))
(print "plr errors: " errors)))
(function monologue messages delay
(var d (or delay 1))
(map (fn msg (dl.util.fmessage msg)
(wait d))
messages))
(function teleport from to
(let pos (plr to :pos))
(if! pos (return))
(if (plr from :pos pos)
(str from " teleported to " to)))
(function heal who
(if (plr who :hp 100)
(str "Healed " who)))
(function team-cmd who team-name
(let name ((starts? "i" team-name) "insurgent" "security"))
(if (plr who :team name)
(str who " now " name)))
(function boom who is-near
(let pos (plr who :pos))
(if! pos (return))
(-> (is-near (rand-circle-point pos 48) pos)
#(dl.util.explosion % "TestGrenade"))
(str "Exploded " (if is-near "near " "") who))
(function flare who
(-> (plr who :pos)
@(map + [0 100 0])
(fn pos (dl.util.explosion pos "TestGrenade")))
(str "Fired flare above " who))
(function brrr who
(if! (plr who :alive?) (return))
(monologue [
(str "Airstrike target locked: " who)
"Coming in hot in 5" "4" "3" "2..."])
(wait 1)
(let pos (plr who :pos))
(let i 0)
(while (< i 100)
(let! i inc)
(wait .01)
(-> [(rand 10) 0 (rand 10)]
@(map + [(- (* i 2) 100) 0 0] pos)
grenade))
(str who " has been brrr'd."))
(function drone who
(if! (plr who :alive?) (return))
(let pos (plr who :pos))
(monologue [
(str "Position locked: " who)
"Drone strike in 4" "3" "2..."
])
(wait 1)
(let i 0 lim (rand 5 10))
(while (< i lim)
(let! i inc)
(wait .25)
(-> [(rand -50 50) 30 (rand -50 50)]
@(map + pos)
grenade))
"Drone strike complete.")
;;;;; claymores
; (monologue (map plant (alive-players)) .1)
;{[x y z] {:team name :by name}}
(if! ((symbols) "plants")
(var plants {}))
(function plant who
(let pos (plr who :pos))
(if! pos (return))
(var! plants into {pos {:team (plr who :team) :by who}})
(str "Claymore planted by " who ". " (len plants) " set."))
(function player-claymore player claymore
(let [plant-pos info] claymore
player-pos (plr player :pos)
player-team (plr player :team)
plant-team (:team info))
(when (and (.. is-near? plant-pos player-pos 30)
(!= player-team plant-team))
(var! plants push plant-pos)
(grenade plant-pos)
(var p player b (:by info))
(-> (str (len plants) " left.")
@(str p " tripped " b "'s claymore! ")
fmessage)))
(function on-tick
;check for players near claymores
(for player-claymore (alive-players) plants))
(ticked.kill)
(ticked.connect on-tick)
;;;;;
(function command sender msg
(var parts (split " " (lower-case msg))
[_ b c d] parts)
(match parts
["cmds"] cmds
["heal"] (heal sender)
["heal" _] (heal (n. b))
["team" _] (team-cmd sender b)
["team"] (str sender " is " (plr sender :team))
["tp" _ "here"] (teleport (n. b) sender)
["tp" _ "to" _] (teleport (n. b) (n. d))
["tp" "to" _] (teleport sender (n. c))
["boom" "near" _] (boom (n. c) true)
["boom" _] (boom (n. b) false)
["flare"] (flare sender)
["flare" _] (flare (n. b))
["brrr" _] (brrr (n. b))
["drone"] (drone sender)
["drone" _] (drone (n. b))
["plant"] (plant sender)
:not-a-command))
(function fmessage m (print m) (dl.util.fmessage m))
(function on-message sender _ msg
(let result (command sender msg))
(when (!= result :not-a-command)
(fmessage
(if (starts? "(" msg)
(catch (eval msg) errors)
(or result "Didn't work, maybe player is dead.")))))
(dl.events.on_chat_message.kill)
(dl.events.on_chat_message.connect on-message)
(dl.util.fmessage "Loaded Insitux chatbot! Chat \"cmds\" to see list of available commands.
Note: this is a CHAT bot, you send the commands in the chat.")