-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.lua
92 lines (87 loc) · 3.11 KB
/
events.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
local exports = exports
local addEvent = addEvent
local addEventHandler = addEventHandler
local toggleControl = toggleControl
local collectgarbage = collectgarbage
local root = root
local math = math
local attachment = exports.bone_attach -- https://community.multitheftauto.com/index.php?p=resources&s=details&id=2540
local balls = {}
local goal = function(player)
if player then
attachment:detachElementFromBone(balls[player])
balls[player]:setPosition(player.position.x,player.position.y,player.position.z)
balls[player]:move(500, 2111.1923828125, -1731.693359375, 15.8)
Timer(function(object)
object:move(500, object.position.x,object.position.y,object.position.z-3)
end, 500, 1, balls[player])
Timer(function(element)
element:outputChat('good shot.')
element:setAnimation()
element.frozen = false
end, 500, 1, player)
end
end
local didnt = function(player)
if player then
attachment:detachElementFromBone(balls[player])
balls[player]:setPosition(player.position.x,player.position.y,player.position.z)
balls[player]:move(500, 2111.1923828125+math.random(1,2), -1731.693359375, 15.8)
Timer(function(object)
object:move(500, object.position.x,object.position.y,object.position.z-3)
end, 500, 1, balls[player])
Timer(function(element)
element:outputChat('nope.')
element:setAnimation()
element.frozen = false
end, 500, 1, player)
end
end
addEvent('attach.ball', true)
addEventHandler('attach.ball', root, function()
if source then
if not balls[source] then
balls[source] = Object(2114, 0, 0, 0)
end
attachment:attachElementToBone(balls[source], source, 12, -0.05, 0.02, 0.19, 0, -190, -110)
source.frozen = true
source:setAnimation('bsktball','BBALL_pickup',true,false)
Timer(function(player)
if player then
player:setAnimation()
player.frozen = false
end
end, 1000, 1, source)
end
end)
addEvent('detach.ball', true)
addEventHandler('detach.ball', root, function()
if source then
if balls[source] then
attachment:detachElementFromBone(balls[source])
balls[source]:destroy()
balls[source] = nil
collectgarbage('collect')
end
end
end)
addEvent('shoot.ball', true)
addEventHandler('shoot.ball', root, function(shoot)
if source then
source.frozen = true
source:setAnimation('bsktball','BBALL_Jump_Shot',true,false)
if shoot then
Timer(function(player)
goal(player)
end, 800, 1, source)
else
Timer(function(player)
didnt(player)
end, 800, 1, source)
end
local controls = {{'fire'},{'aim_weapon'},{'enter_exit'},}
for index, value in ipairs(controls) do
toggleControl(source, value[1], true)
end
end
end)