-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathport_sv.lua
81 lines (70 loc) · 2.3 KB
/
port_sv.lua
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
-- Helper function for getting player money
function getMoney(source)
-- Add framework API's here (return large number by default)
return 1000000
end
-- Helper function for removing player money
function removeMoney(source, amount)
-- Add framework API's here
end
-- Helper function for adding player money
function addMoney(source, amount)
-- Add framework API's here
end
-- Helper function for getting player name
function getName(source)
-- Add framework API's here
return GetPlayerName(source)
end
-- Helper function for notifying players
function notifyPlayer(source, msg)
-- Add custom notification here (use chat by default)
TriggerClientEvent('chatMessage', source, "[StreetRaces]", {255, 0, 0}, msg)
end
-- Saved player data and file
local playersData = nil
local playersDataFile = "./StreetRaces_saveData.txt"
-- Helper function for loading saved player data
function loadPlayerData(source)
-- Load data from file if not already initialized
if playersData == nil then
playersData = {}
local file = io.open(playersDataFile, "r")
if file then
local contents = file:read("*a")
playersData = json.decode(contents);
io.close(file)
end
end
-- Get player steamID from source and use as key to get player data
local playerId = string.sub(GetPlayerIdentifier(source, 0), 7, -1)
local playerData = playersData[playerId]
-- Return saved player data
if playerData == nil then
playerData = {}
end
return playerData
end
-- Helper function for saving player data
function savePlayerData(source, data)
-- Load data from file if not already initialized
if playersData == nil then
playersData = {}
local file = io.open(playersDataFile, "r")
if file then
local contents = file:read("*a")
playersData = json.decode(contents);
io.close(file)
end
end
-- Get player steamID from source and use as key to save player data
local playerId = string.sub(GetPlayerIdentifier(source, 0), 7, -1)
playersData[playerId] = data
-- Save file
local file = io.open(playersDataFile, "w+")
if file then
local contents = json.encode(playersData)
file:write(contents)
io.close(file)
end
end