-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenSystem.lua
More file actions
48 lines (37 loc) · 1.14 KB
/
TokenSystem.lua
File metadata and controls
48 lines (37 loc) · 1.14 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
-- TokenSystem.lua
-- Token spawning, collection, and energy restoration system
-- Table to hold the tokens
local tokens = {}
-- Function to spawn tokens
local function spawnToken(x, y)
local token = {x = x, y = y, collected = false}
table.insert(tokens, token)
end
-- Function to collect tokens
local function collectToken(player, token)
if not token.collected then
token.collected = true
player.energy = player.energy + 10 -- Restore 10 energy
print("Token collected! Energy restored.")
else
print("Token already collected.")
end
end
-- Function to restore energy periodically
local function restoreEnergy(player)
while true do
wait(30) -- Wait for 30 seconds
player.energy = player.energy + 1 -- Restore 1 energy
print("Energy restored! Current energy: " .. player.energy)
end
end
-- Example usage
-- Spawn a token at coordinates (10, 15)
spawnToken(10, 15)
-- Simulating a player
local player = {energy = 50}
-- Collect the first token
collectToken(player, tokens[1])
-- Start energy restoration in a separate thread
restoreEnergy(player)
return tokens, player