-
Notifications
You must be signed in to change notification settings - Fork 3
/
opengloves.lua
114 lines (85 loc) · 3.32 KB
/
opengloves.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
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
require "utils.class"
require "utils.library"
require "utils.vscriptinit"
require "core.coreinit"
require "utils.utilsinit"
require "framework.frameworkinit"
require "framework.entities.entitiesinit"
require "game.globalsystems.timeofday_init"
require "game.gameinit"
--local socket = require("socket")
--host = host or "localhost"
--port = port or 8080
local LEFT_ID = 1
local RIGHT_ID = 2
local fingerPos = {
{0, 0, 0, 0, 0}, --left
{0, 0, 0, 0, 0} --right
}
local questOrbs = {
fireOrb = true,
waterOrb = false,
windOrb = true
}
local handPositions = {
default = {500,500,500,500,500},
none = {0, 0, 0, 0, 0},
propphysics = {500, 500, 500, 500, 500}
}
local function logDebug(line)
Msg("[OpenGlovesDebug] "..line .. "\n")
end
function outputData(attachment)
line = table.concat(fingerPos[attachment], ", ")
if attachment == LEFT_ID then
Msg("[OpenGlovesParse]{Left} ("..line..")\n")
elseif attachment == RIGHT_ID then
Msg("[OpenGlovesParse]{Right} ("..line..")\n")
else
Msg("[OpenGlovesError] Invalid attachment \n")
end
--local file = io.open("openglovesdata.json", "w")
--io.output(file)
--io.write(line)
--io.close(file)
end
function OnItemPickup (param)
local attachment = param["vr_tip_attachment"]
logDebug(" Attachment: " .. tostring(attachment))
logDebug("Item picked up: " .. tostring(param["item"])..tostring(param["item_name"])..tostring(attachment) .. "\n")
fingerPos[attachment] = handPositions.default
outputData(attachment)
end
function OnItemReleased (param)
local attachment = param["vr_tip_attachment"]
logDebug(" Attachment: " .. tostring(attachment))
logDebug("Item released: " .. tostring(param["item"]) .. tostring(attachment) .. "\n")
fingerPos[attachment] = handPositions.none
outputData(attachment)
end
ListenToGameEvent('player_spawn', function(info)
logDebug("OPNG------------> Player spawned: " .. tostring(info["userid"]) .. "\n")
--if arg then
-- host = arg[1] or host
-- port = arg[2] or port
--end
--print("Attempting connection to host '" ..host.. "' and port " ..port.. "...")
--c = assert(socket.connect(host, port))
--assert(c:send("Sent from Lua in Half Life Alyx!\n"))
end, nil)
if IsServer() then
-- Stop listening to the events if we're already listening to them (this is so we can safely reload the script)
if onplayershoot_handle ~= nil then
StopListeningToGameEvent( onitem_pickup_handle )
StopListeningToGameEvent( onitem_released_handle )
end
if onitem_pickup_handle == nil then onitem_pickup_handle=ListenToGameEvent("item_pickup",OnItemPickup, nil) end
if onitem_released_handle == nil then onitem_released_handle=ListenToGameEvent("item_released",OnItemReleased, nil) end
else
if onplayer_opened_game_menu_handle ~= nil then
StopListeningToGameEvent( onplayer_opened_game_menu_handle )
StopListeningToGameEvent( onplayer_closed_game_menu_handle )
end
if onplayer_opened_game_menu_handle == nil then onplayer_opened_game_menu_handle=ListenToGameEvent("player_opened_game_menu",OnPlayerOpenedGameMenu, nil) end
if onplayer_closed_game_menu_handle == nil then onplayer_closed_game_menu_handle=ListenToGameEvent("player_closed_game_menu",OnPlayerClosedGameMenu, nil) end
end