-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquests.lua
More file actions
executable file
·190 lines (149 loc) · 6.19 KB
/
quests.lua
File metadata and controls
executable file
·190 lines (149 loc) · 6.19 KB
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
189
190
--updated, hopefully 1.8 works :/
PLUGIN.Title = "Quests"
PLUGIN.Description = "Basic Quest Plugin"
function PLUGIN:Init()
econ_mod = plugins.Find("econ")
if (not econ_mod) then
self.econ = false
else
self.econ = true
end
self.autojoin = true
-- self.DataFile = util.GetDatafile( "quests" )
-- local txt = self.DataFile:GetText()
-- if (txt ~= "") then
-- self.Quests = json.decode( txt )
-- else
self.Quests = {}
-- end
self.Zombies = {}
self:addZombieQuest("Zombies", "2", "Can of Tuna", "1")
self:addZombieQuest("MoreZombies", "20", "M4", "1")
-- self:addZombieQuest("So Many Zombies", "200", "Supply Signal", "1")
if (self.econ) then
local questname = "ZombiesMoney"
local killcount = "10"
local rewardcount = "50"
table.insert(self.Zombies, questname)
self:addQuest( questname,
"kill " .. killcount .. " zombies to get ".. rewardcount .. econ_mod.CurrencySymbol,
(function(x) return (x >= tonumber(killcount)) end),
(function(user) econ_mod:giveMoneyTo(user, tonumber(rewardcount)) end)
)
end
self:AddChatCommand("quest", self.cmdQuest)
self:AddChatCommand("qhelp", self.cmdQhelp)
end
function PLUGIN:addZombieQuest(questname, killcount, questreward, rewardcount)
table.insert(self.Zombies, questname)
self:addQuest( questname,
"kill " .. killcount .. " zombies to get ".. rewardcount .. " " .. questreward,
(function(x) return (x >= tonumber(killcount)) end),
(function(user) rust.RunServerCommand("inv.giveplayer \"" .. util.QuoteSafe( user.displayName ) .. "\" \"" .. questreward .. "\" " .. rewardcount ) end)
)
end
function PLUGIN:addQuest(idString, description, objective, reward)
local userentry = self.Quests[ idString ]
if (not userentry) then
userentry = {}
userentry.ID = idString
userentry.Desc = description
userentry.Objective = objective
userentry.Reward = reward
userentry.Players = {}
self.Quests[ idString ] = userentry
--self:Save()
end
end
function PLUGIN:addPlayerToQuest(netuser, idString)
local userentry = self.Quests[ idString ]
if (not userentry) then
rust.Notice( netuser, "No quest found with name " .. idString .. " !" )
return false
end
local userID = rust.GetUserID( netuser )
local player = {}
player.ID = userID
player.Name = netuser.displayName
player.Value = nil
self.Quests[idString].Players[userID] = player
return true
end
-- function PLUGIN:Save()
-- self.DataFile:SetText( json.encode( self.Quests ) )
-- self.DataFile:Save()
-- end
function PLUGIN:cmdQuest( netuser, cmd, args )
if (not(args[1])) then
return
end
if (args[1] == "list") then
rust.SendChatToUser( netuser, "Available Quests:" )
for key,value in pairs(self.Quests) do
rust.SendChatToUser( netuser, util.QuoteSafe(value.ID) .. ": " .. util.QuoteSafe(value.Desc) )
end
return
end
if (args[1] == "done") then
local userID = rust.GetUserID( netuser )
for key,value in pairs(self.Quests) do
if ((value.Players[userID]) and (value.Players[userID].Value)) then
if (value.Objective(value.Players[userID].Value)) then
value.Reward(netuser)
rust.SendChatToUser( netuser, "Completed quest " .. util.QuoteSafe(value.ID) )
value.Players[userID] = nil
else
rust.SendChatToUser( netuser, "Status of " .. util.QuoteSafe(value.ID) .. ": " .. tostring(value.Players[userID].Value) )
end
else
rust.SendChatToUser( netuser, "Status of " .. util.QuoteSafe(value.ID) .. ": not joined")
end
end
return
end
if ((args[1] == "join") and (args[2])) then
if (self:addPlayerToQuest(netuser, args[2])) then
rust.SendChatToUser( netuser, "Joined quest " .. util.QuoteSafe(args[2]) )
return
else
rust.Notice( netuser, "/quest join error!" )
end
return
end
rust.Notice( netuser, "/quest error!" )
end
function PLUGIN:OnKilled ( takedamage, event )
if (takedamage:GetComponent( "ZombieController" )) then
local player = dmg.attacker.client.netUser
local userID = rust.GetUserID(player)
for key,value in pairs(self.Zombies) do
local quest = self.Quests[value]
if (quest.Players[userID]) then
if (not(quest.Players[userID].Value)) then
quest.Players[userID].Value = 0
end
quest.Players[userID].Value = quest.Players[userID].Value + 1
if (quest.Objective(quest.Players[userID].Value)) then
rust.SendChatToUser( player, "Completed quest " .. util.QuoteSafe(quest.ID) )
quest.Reward(player)
quest.Players[userID] = nil
else
rust.SendChatToUser( player, "Status of " .. util.QuoteSafe(quest.ID) .. ": " .. tostring(quest.Players[userID].Value) )
end
end
end
end
end
function PLUGIN:SendHelpText( netuser )
rust.SendChatToUser( netuser, "Use /qhelp to show Quests commands" )
end
function PLUGIN:cmdQhelp( netuser )
rust.SendChatToUser( netuser, "--------------------------------------------------------------------------------" )
rust.SendChatToUser( netuser, "------------------- Greyhawk's Quests Plugin -------------------------" )
rust.SendChatToUser( netuser, "Use /quest list to list available quests" )
rust.SendChatToUser( netuser, "Use /quest join name to join a quest" )
rust.SendChatToUser( netuser, "Use /quest done to check completed quests" )
rust.SendChatToUser( netuser, "--------------------------------------------------------------------------------" )
end
-- economy interaction : load economy.txt, find user, give user, save economy.txt
-- REWARDS : money, items