SHOW:
|
|
- or go back to the newest paste.
1 | ||
2 | - | builder = "Username" -- REPLACE WITH YOUR OWN USERNAME (EG "Jamesqwartz") |
2 | + | |
3 | builder = "Username" -- REPLACE THIS WITH YOUR USERNAME | |
4 | ||
5 | look = 0 | |
6 | ||
7 | --[[ | |
8 | 0 = wood | |
9 | 1 = ice | |
10 | 2 = tramp | |
11 | 3 = lava | |
12 | 4 = choc | |
13 | ]] | |
14 | custom = false | |
15 | ||
16 | fric = 0.3 -- friction | |
17 | res = 0.2 -- restitution | |
18 | col = nil -- color | |
19 | hei = 10 -- height | |
20 | ||
21 | fric_stored = 0 | |
22 | res_stored = 0 | |
23 | col_stored = nil | |
24 | ||
25 | point_x=nil | |
26 | point_y=nil | |
27 | ||
28 | gNum = 0 | |
29 | ||
30 | system.bindMouse(builder, true) | |
31 | ||
32 | for _,v in pairs({32, 8, 49, 50, 51, 52, 53, 54}) do | |
33 | tfm.exec.bindKeyboard(builder, v, true, true) | |
34 | end | |
35 | ||
36 | system.disableChatCommandDisplay("height", true) | |
37 | system.disableChatCommandDisplay("custom", true) | |
38 | ||
39 | function eventMouse(name, x, y) | |
40 | tfm.exec.displayParticle(9, x, y, 0, 0, 0, 0) | |
41 | if point_x == nil then | |
42 | point_x = x | |
43 | point_y = y | |
44 | else | |
45 | makeGround(x,y,length(point_x,point_y,x,y), angle(point_x, point_y,x,y)) | |
46 | end | |
47 | end | |
48 | ||
49 | function eventNewGame() | |
50 | gNum = 0 | |
51 | point_x=nil | |
52 | point_y=nil | |
53 | end | |
54 | ||
55 | function eventChatCommand(name, cmd) | |
56 | local args = {} | |
57 | for arg in cmd:gmatch("%S+") do | |
58 | table.insert(args, arg) | |
59 | end | |
60 | if args[1] == "custom" then | |
61 | ui.addPopup(1, 2, "Restitution:", name, 726, 20, 70) | |
62 | system.bindMouse(builder, false) | |
63 | point_x=nil | |
64 | point_y=nil | |
65 | col=nil | |
66 | look = 12 | |
67 | elseif args[1] == "height" then | |
68 | if args[2] then | |
69 | hei = tonumber(args[2]) or 0 | |
70 | end | |
71 | end | |
72 | end | |
73 | ||
74 | function eventPopupAnswer(id, name, answer) | |
75 | if id == 1 then | |
76 | res = tonumber(answer) | |
77 | ui.addPopup(2, 2, "Friction:", name, 726, 20, 70) | |
78 | elseif id == 2 then | |
79 | - | ui.addPopup(3, 2, "Colour eg. FF0000 (if left blank it will be invisible):", name, 700, 20) |
79 | + | |
80 | ui.addPopup(3, 2, "Colour eg. FF0000 (if left blank it will be invisible):", name, 646, 20, 150) | |
81 | elseif id == 3 then | |
82 | if answer:len() > 5 then | |
83 | col = '0x'..answer | |
84 | end | |
85 | - | ui.addPopup(4, 1, "Would you like to add this to a hotkey (6)?", name, 700, 20) |
85 | + | ui.addPopup(4, 1, "Would you like to add this to a hotkey (6)?", name, 551, 20, 245) |
86 | elseif id == 4 then | |
87 | if answer == "yes" then | |
88 | fric_stored = fric | |
89 | res_stored = res | |
90 | col_stored = col | |
91 | custom = true | |
92 | end | |
93 | system.bindMouse(builder, true) | |
94 | end | |
95 | end | |
96 | ||
97 | function eventKeyboard(name, key, down, x, y) | |
98 | if key == 32 then | |
99 | for i=1, gNum do | |
100 | tfm.exec.removePhysicObject(i) | |
101 | end | |
102 | gNum = 0 | |
103 | elseif key == 8 then | |
104 | tfm.exec.removePhysicObject(gNum) | |
105 | gNum = gNum - 1 | |
106 | elseif key == 49 then | |
107 | look = 0 | |
108 | fric = 0.3 | |
109 | res = 0.2 | |
110 | col = nil | |
111 | elseif key == 50 then | |
112 | look = 1 | |
113 | fric = 0 | |
114 | res = 0.2 | |
115 | col = nil | |
116 | elseif key == 51 then | |
117 | look = 2 | |
118 | fric = 0 | |
119 | res = 1.2 | |
120 | col = nil | |
121 | elseif key == 52 then | |
122 | look = 3 | |
123 | fric = 0 | |
124 | res = 20 | |
125 | col = nil | |
126 | elseif key == 53 then | |
127 | look = 4 | |
128 | fric = 20 | |
129 | res = 0.2 | |
130 | col = nil | |
131 | elseif key == 54 then | |
132 | if custom then | |
133 | look = 12 | |
134 | fric = fric_stored | |
135 | res = res_stored | |
136 | col = col_stored | |
137 | end | |
138 | end | |
139 | end | |
140 | ||
141 | function makeGround(x,y,length,ang) | |
142 | gNum = gNum + 1 | |
143 | final_x = ((x + point_x)/2) | |
144 | final_y = ((y + point_y)/2) | |
145 | tfm.exec.addPhysicObject(gNum, final_x, final_y, {type=look or 0, width=length, height = hei, angle=ang, color = col ,friction=fric or 0.3, restitution=res or 0.2}) | |
146 | point_x=nil | |
147 | point_y=nil | |
148 | end | |
149 | ||
150 | function length(x1, y1, x2, y2) | |
151 | lx = (x2 - x1)^2 | |
152 | ly = (y2 - y1)^2 | |
153 | return math.sqrt(lx+ly) | |
154 | end | |
155 | ||
156 | function angle(x1, y1, x2, y2) | |
157 | lx = x2 - x1 | |
158 | ly = y2 - y1 | |
159 | return math.deg(math.atan2(ly,lx)) | |
160 | end |