-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cs
More file actions
278 lines (222 loc) · 8.43 KB
/
server.cs
File metadata and controls
278 lines (222 loc) · 8.43 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// _____ _______ _____ _____ _____
// /\ \ /::\ \ /\ \ /\ \ /\ \
// /::\ \ /::::\ \ /::\ \ /::\ \ /::\ \
// /::::\ \ /::::::\ \ /::::\ \ /::::\ \ /::::\ \
// /::::::\ \ /::::::::\ \ /::::::\ \ /::::::\ \ /::::::\ \
// /:::/\:::\ \ /:::/~~\:::\ \ /:::/\:::\ \ /:::/\:::\ \ /:::/\:::\ \
// /:::/__\:::\ \ /:::/ \:::\ \ /:::/__\:::\ \ /:::/__\:::\ \ /:::/__\:::\ \
// /::::\ \:::\ \ /:::/ / \:::\ \ /::::\ \:::\ \ /::::\ \:::\ \ \:::\ \:::\ \
// /::::::\ \:::\ \ /:::/____/ \:::\____\ /::::::\ \:::\ \ /::::::\ \:::\ \ ___\:::\ \:::\ \
// /:::/\:::\ \:::\____\ |:::| | |:::| | /:::/\:::\ \:::\____\ /:::/\:::\ \:::\ \ /\ \:::\ \:::\ \
///:::/ \:::\ \:::| ||:::|____| |:::| |/:::/ \:::\ \:::| |/:::/__\:::\ \:::\____\/::\ \:::\ \:::\____\
//\::/ |::::\ /:::|____| \:::\ \ /:::/ / \::/ \:::\ /:::|____|\:::\ \:::\ \::/ /\:::\ \:::\ \::/ /
// \/____|:::::\/:::/ / \:::\ \ /:::/ / \/_____/\:::\/:::/ / \:::\ \:::\ \/____/ \:::\ \:::\ \/____/
// |:::::::::/ / \:::\ /:::/ / \::::::/ / \:::\ \:::\ \ \:::\ \:::\ \
// |::|\::::/ / \:::\__/:::/ / \::::/ / \:::\ \:::\____\ \:::\ \:::\____\
// |::| \::/____/ \::::::::/ / \::/____/ \:::\ \::/ / \:::\ /:::/ /
// |::| ~| \::::::/ / ~~ \:::\ \/____/ \:::\/:::/ /
// |::| | \::::/ / \:::\ \ \::::::/ /
// \::| | \::/____/ \:::\____\ \::::/ /
// \:| | ~~ \::/ / \::/ /
// \|___| \/____/ \/____/
//
// Author: Zapk
// Version: 3.0.0 (November 2017)
// URL: https://github.com/zapk/Server_Ropes
if(!isObject(MainRopeGroup))
{
new ScriptGroup(MainRopeGroup);
}
if(isFile("Add-Ons/System_ReturnToBlockland/server.cs") && !$RTB::Hooks::ServerControl)
{
exec("Add-Ons/System_ReturnToBlockland/hooks/serverControl.cs");
}
RTB_registerPref("Slacked Rope Shapes", "Ropes", "Pref::Server::Ropes::Iterations", "int 2 40", "Server_Ropes", 10, 0, 0);
RTB_registerPref("Rope Tool Admin Only", "Ropes", "Pref::Server::Ropes::ToolAdminOnly", "bool", "Server_Ropes", true, 0, 0);
RTB_registerPref("Max Ropes for Non-Admins", "Ropes", "Pref::Server::Ropes::MaxPlayerRopes", "int 1 1000", "Server_Ropes", 64, 0, 0);
RTB_registerPref("Rope Vertices", "Ropes", "Pref::Server::Ropes::Vertices", "int 4 8", "Server_Ropes", 8, 0, 0);
exec("./math.cs");
exec("./manager.cs");
exec("./ropetool.cs");
exec("./commands.cs");
exec("./datablocks.cs");
function clearRopes(%bl_id)
{
%c = 0;
%useID = (%bl_id !$= "");
for(%i = MainRopeGroup.getCount() - 1; %i >= 0; %i--)
{
%rg = MainRopeGroup.getObject(%i);
if(!%useID || %rg.bl_id $= %bl_id)
{
%c++;
%rg.delete();
}
}
return mFloor(%c);
}
function getRopeCount(%bl_id)
{
%c = 0;
%useID = (%bl_id !$= "");
for(%i = MainRopeGroup.getCount() - 1; %i >= 0; %i--)
{
%rg = MainRopeGroup.getObject(%i);
if(!%useID || %rg.bl_id $= %bl_id)
%c++;
}
return mFloor(%c);
}
function _removeRopeGroup(%creationData)
{
for(%i = MainRopeGroup.getCount() - 1; %i >= 0; %i--)
{
%sg = MainRopeGroup.getObject(%i);
if(%sg.creationData $= %creationData)
{
%sg.delete();
}
}
}
function _getRopeGroup(%group, %bl_id, %creationData)
{
for(%i = 0; %i < MainRopeGroup.getCount(); %i++)
{
%sg = MainRopeGroup.getObject(%i);
if(%sg.gn $= %group)
{
return %sg.getID();
}
}
%new = new ScriptGroup()
{
gn = %group;
bl_id = %bl_id;
creationData = %creationData;
};
MainRopeGroup.add(%new);
return %new;
}
function _getNewRope(%diameter, %color, %group, %isNoCol)
{
%dbName = "Rope" @ mClamp($Pref::Server::Ropes::Vertices, 4, 8) @ (%isNoCol ? "Ghost" : "");
%rope = new StaticShape()
{
position = "0 0 0";
rotation = "0 0 0";
scale = %diameter SPC %diameter SPC %diameter;
dataBlock = %dbName;
canSetIFLs = false;
diameter = %diameter;
isRope = true;
};
%rope.setNodeColor("ALL", getColorIDTable(%color));
if (isObject(%group))
%group.add(%rope);
else
MissionCleanup.add(%rope);
return %rope;
}
function createRope(%posA, %posB, %color, %diameter, %slack, %group)
{
if(%slack < 0.01 && %slack > -0.01)
{
%rope = _getNewRope( %diameter, %color, %group );
_aimRope( %rope, %posA, %posB );
return;
}
%vec = vectorNormalize( vectorSub(%posB, %posA) );
%dist = vectorDist( %posB, %posA );
for(%i = 0; %i < $Pref::Server::Ropes::Iterations; %i++)
{
%j = %i + 1;
%subPosA = solveRopeDrop( %posA, %vec, %dist, %i, %slack, %diameter, $Pref::Server::Ropes::Iterations );
%subPosB = solveRopeDrop( %posA, %vec, %dist, %j, %slack, %diameter, $Pref::Server::Ropes::Iterations );
%rope = _getNewRope( %diameter, %color, %group );
_aimRope( %rope, %subPosA, %subPosB );
}
}
registerOutputEvent("fxDTSBrick", "ropeClearAll");
function fxDTSBrick::ropeClearAll(%this)
{
for(%i = 0; %i < getWordCount(%this.ropeGroups); %i++)
{
%g = getWord(%this.ropeGroups, %i);
if(isObject(%g))
{
%g.delete();
}
}
%this.ropeGroups = "";
}
function hReturnNamedBrick(%brickGroup,%name)
{
%name = "_" @ %name;
for(%a = 0; %a < %brickGroup.NTNameCount; %a++)
{
if(%brickGroup.NTName[%a] !$= %name || %brickGroup.NTObjectCount[%name] < 0)
continue;
%n = %brickGroup.NTObjectCount[%name];
return %brickGroup.NTObject[%name,getRandom(0,%n-1)];
}
return 0;
}
registerOutputEvent("fxDTSBrick", "ropeToBricks", "string 200 100" TAB "paintColor 0" TAB "float 0.1 1 0.01 0.2" TAB "float 0 50 0.01 2");
function fxDTSBrick::ropeToBricks(%this, %toNames, %color, %diameter, %slack)
{
for(%i = 0; %i < getWordCount(%toNames); %i++)
{
%this.schedule((%i + 1) * 50, _ropeToBrick, getWord(%toNames, %i), %color, %diameter, %slack);
}
}
function fxDTSBrick::_ropeToBrick(%this, %toName, %color, %diameter, %slack)
{
%toBrick = hReturnNamedBrick(%this.getGroup(), %toName);
if(!isObject(%toBrick)) return;
%creationData = %this SPC %toBrick SPC %color SPC %diameter SPC %slack;
_removeRopeGroup(%creationData);
%group = _getRopeGroup(getSimTime(), %this.getGroup().bl_id, %creationData);
%group.brickGroup = %this.getGroup();
createRope(%this.getPosition(), %toBrick.getPosition(), %color, %diameter, %slack, %group);
%this.ropeGroups = trim(%this.ropeGroups SPC %group);
%toBrick.ropeGroups = trim(%toBrick.ropeGroups SPC %group);
}
if(isPackage(RopePackage))
{
deactivatePackage(RopePackage);
}
package RopePackage
{
function fxDTSBrick::onRemove(%this)
{
%this.ropeClearAll();
Parent::onRemove(%this);
}
function WandImage::onHitObject(%this, %player, %slot, %hitObj, %hitPos, %hitNormal)
{
Parent::onHitObject(%this, %player, %slot, %hitObj, %hitPos, %hitNormal);
if (!isObject(%player.client) || !isObject(%hitObj) || !%hitObj.isRope)
return;
if (%player.client.getBLID() !$= (%bl_id = %hitObj.getGroup().bl_id))
{
if (isObject("BrickGroup_" @ %bl_id))
%player.client.sendTrustFailureMessage("BrickGroup_" @ %bl_id);
else
commandToClient(%player.client, 'CenterPrint', "\c1BL_ID: " @ %bl_id @ "\c0 does not trust you enough to do that", 1);
}
else
{
serverPlay3D("BrickBreakSound", %hitPos);
%hitObj.getGroup().delete();
}
}
function AdminWandImage::onHitObject(%this, %player, %slot, %hitObj, %hitPos, %hitNormal)
{
Parent::onHitObject(%this, %player, %slot, %hitObj, %hitPos, %hitNormal);
if (!isObject(%player.client) || !isObject(%hitObj) || !%hitObj.isRope || %hitObj.getGroup().gn $= "")
return;
serverPlay3D("BrickBreakSound", %hitPos);
%hitObj.getGroup().delete();
}
};
activatePackage(RopePackage);