forked from ckaysone380/qbcore-db-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfind-vehicle.rb
More file actions
executable file
·73 lines (56 loc) · 1.46 KB
/
find-vehicle.rb
File metadata and controls
executable file
·73 lines (56 loc) · 1.46 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
#!/usr/bin/env ruby
require 'mysql2'
require 'pp'
require 'json'
require 'time'
#############
# Variables #
#############
stashmap = Hash.new
wheremap = Hash.new { |hash, key| hash[key] = [] }
charinfomap = Hash.new
#############
# Functions #
#############
def valid_json?(json)
JSON.parse(json)
return true
rescue JSON::ParserError => e
return false
end
########
# Main #
########
if ARGV[0] == nil or ARGV[0] == "" then
printf "You must enter in an vehicle like: ./find-item.rb models\n"
exit
end
model = ARGV[0]
client = Mysql2::Client.new(:default_file => "/etc/.db.cnf")
players = client.query('SELECT * from players')
printf("%-30s %-15s %-15s %-15s\n", "Person", "CID", "Plate", "Last Used (days)")
players.each do |row|
if valid_json?(row["charinfo"]) then
charinfo = JSON.parse(row["charinfo"])
cid = row["citizenid"]
charinfomap[cid] = charinfo["charname"]
end
end
vehicles = client.query("SELECT * from player_vehicles WHERE vehicle = '#{model}' ORDER BY epoch DESC")
vehicles.each do |row|
stashmap[row["plate"]] = row["citizenid"]
cid = row["citizenid"]
epoch = row["epoch"]
plate = row["plate"]
person = "unknown"
if charinfomap[cid] then
person = charinfomap[cid]
end
now = Time.now.to_i
delta = now - epoch.to_i
days = delta / 86400
if days == 0 then
days = "today"
end
printf("%-30s %-15s %-15s %-15s\n", "#{person}", cid, plate, days)
end