· 4 years ago · Feb 11, 2021, 12:00 AM
1class MapperData
2{
3 Player = nullclass MapperData
4{
5 Player = null
6 Object = null
7 SelectingObject = false
8 Timer = null
9}
10
11class ObjectsClass
12{
13 ID = null;
14 Object = null;
15 Model = null;
16
17 PX = null;
18 PY = null;
19 PZ = null;
20
21 AX = null;
22 AY = null;
23 AZ = null;
24
25}
26
27
28Mapper <- {
29
30 function LoadSystem()
31 {
32 QuerySQL(OBJ_DB, "CREATE TABLE IF NOT EXISTS Objects ( ID INTEGER PRIMARY KEY AUTOINCREMENT, Model NUMERIC, PX FLOAT, PY FLOAT, PZ FLOAT, AX FLOAT, AY FLOAT, AZ FLOAT, MappedBy TEXT )" );
33 QuerySQL(OBJ_DB, "CREATE TABLE IF NOT EXISTS Logger ( ID INTEGER, Model INTEGER, Position TEXT, Action TEXT, Mapper TEXT )" );
34
35 this.Users <- array( GetMaxPlayers(), null );
36 Objects <- array( 3001, null );
37 ObjectsArray <- array( 3001, null );
38
39 this.LoadObjects();
40 print("Mapper System loaded - By Naru^/Maximiliano");
41 }
42
43 function LoadObjects()
44 {
45 local cq = QuerySQL( OBJ_DB, "SELECT COUNT(*) FROM Objects" ), count = GetSQLColumnData( cq, 0 );
46
47 if ( !count )
48 {
49 print( "Objects Loaded: 0" );
50 return false;
51 }
52
53 local i = 0;
54 local q = QuerySQL( OBJ_DB, "SELECT * FROM Objects" );
55 while ( GetSQLColumnData( q, 0 ) != null )
56 {
57 local ID = GetSQLColumnData( q, 0 );
58 this.Objects[ID] = ObjectsClass();
59 this.Objects[ID].ID = ID;
60 this.Objects[ID].Model = GetSQLColumnData( q, 1 );
61 this.Objects[ID].PX = GetSQLColumnData( q, 2 );
62 this.Objects[ID].PY = GetSQLColumnData( q, 3 );
63 this.Objects[ID].PZ = GetSQLColumnData( q, 4 );
64 this.Objects[ID].AX = GetSQLColumnData( q, 5 );
65 this.Objects[ID].AY = GetSQLColumnData( q, 6 );
66 this.Objects[ID].AZ = GetSQLColumnData( q, 7 );
67
68 local Model = GetSQLColumnData( q, 1 ),
69 PX = this.Objects[ID].PX.tofloat(),
70 PY = this.Objects[ID].PY.tofloat(),
71 PZ = this.Objects[ID].PZ.tofloat(),
72 AX = this.Objects[ID].AX.tofloat(),
73 AY = this.Objects[ID].AY.tofloat(),
74 AZ = this.Objects[ID].AZ.tofloat();
75
76 this.Objects[ID].Object = ::CreateObject( Model, 1, Vector( PX, PY, PZ ), 255 );
77 this.Objects[ID].Object.RotateToEuler( Vector( AX, AY, AZ ), 0 );
78 this.Objects[ID].Object.TrackingShots = true;
79
80 this.ObjectsArray[ this.Objects[ID].Object.ID ] = ID;
81 i++;
82 GetSQLNextRow( q );
83 }
84 FreeSQLQuery( q );
85 print( "Objects Loaded: " + i );
86 }
87
88
89 function CreateObject(player, model)
90 {
91 if ( !this.Users[ player.ID ] )
92 {
93 this.Users[ player.ID ] = MapperData();
94 this.Users[ player.ID ].Player = player;
95 this.Users[ player.ID ].Object = ::CreateObject( model.tointeger(), player.World, Vector( player.Pos.x, player.Pos.y, player.Pos.z + 0.5 ), 255 );
96 this.Users[ player.ID ].Object.TrackingShots = true;
97 this.Information("Object created successfully.", player);
98 }
99 }
100
101 function DeleteObject( player )
102 {
103 if ( this.Users[ player.ID ] )
104 {
105 local obj = this.Users[ player.ID ].Object;
106 if ( this.ObjectsArray[ obj.ID ] == null )
107 {
108 this.Information("Object removed.", player);
109 this.Users[ player.ID ].Object.Delete();
110 this.Users[ player.ID ] = null;
111 }
112 else
113 {
114
115 local ID = this.ObjectsArray[ obj.ID ];
116 if ( this.Objects[ ID ] && this.Objects[ ID ].Object.ID == obj.ID )
117 {
118 QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + obj.Model + "', '" + obj.Pos + "', 'Delete', '" + player.Name + "' )" );
119
120 QuerySQL( OBJ_DB, "DELETE FROM Objects WHERE ID='" + ID + "'" );
121 this.Objects[ID] = null;
122 this.Information("Object removed..", player);
123 this.ObjectsArray[ obj.ID ] = null;
124 this.Users[ player.ID ].Object.Delete();
125 this.Users[ player.ID ] = null;
126
127
128 }
129 }
130
131 }
132 }
133
134 function SaveObject( player )
135 {
136 if ( this.Users[ player.ID ] )
137 {
138 local obj = this.Users[ player.ID ].Object;
139 if ( this.ObjectsArray[ obj.ID ] == null )
140 {
141 local OBJ = this.Users[ player.ID ].Object;
142 QuerySQL( OBJ_DB, "INSERT INTO Objects ( Model, PX, PY, PZ, AX, AY, AZ, MappedBy ) VALUES ( '" + OBJ.Model + "', '" + OBJ.Pos.x + "', '" + OBJ.Pos.y + "', '" + OBJ.Pos.z + "', '" + OBJ.RotationEuler.x + "', '" + OBJ.RotationEuler.y + "', '" + OBJ.RotationEuler.z + "', '" + player.Name + "' )" );
143
144
145 local GetID = QuerySQL( OBJ_DB, "SELECT ID FROM Objects ORDER BY ID DESC LIMIT 1");
146 local ID = GetSQLColumnData( GetID, 0 ).tointeger();
147
148 local q = QuerySQL( OBJ_DB, "SELECT * FROM Objects WHERE ID='" + ID + "'" );
149 if ( q )
150 {
151 local ID = GetSQLColumnData( q, 0 );
152 this.Objects[ID] = ObjectsClass();
153 this.Objects[ID].ID = ID;
154 this.Objects[ID].Model = GetSQLColumnData( q, 1 );
155 this.Objects[ID].PX = GetSQLColumnData( q, 2 );
156 this.Objects[ID].PY = GetSQLColumnData( q, 3 );
157 this.Objects[ID].PZ = GetSQLColumnData( q, 4 );
158 this.Objects[ID].AX = GetSQLColumnData( q, 5 );
159 this.Objects[ID].AY = GetSQLColumnData( q, 6 );
160 this.Objects[ID].AZ = GetSQLColumnData( q, 7 );
161
162 local Model = GetSQLColumnData( q, 1 ),
163 PX = this.Objects[ID].PX.tofloat(),
164 PY = this.Objects[ID].PY.tofloat(),
165 PZ = this.Objects[ID].PZ.tofloat(),
166 AX = this.Objects[ID].AX.tofloat(),
167 AY = this.Objects[ID].AY.tofloat(),
168 AZ = this.Objects[ID].AZ.tofloat();
169
170 this.Objects[ID].Object = this.Users[ player.ID ].Object;
171 this.Objects[ID].Object.RotateToEuler( Vector( AX, AY, AZ ), 0 );
172
173 this.ObjectsArray[ this.Objects[ID].Object.ID ] = ID;
174 this.Users[ player.ID ] = null;
175 QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + OBJ.Model + "', '" + OBJ.Pos + "', 'Save', '" + player.Name + "' )" );
176 this.Information("Object saved.", player);
177 }
178 }
179 else
180 {
181
182 local ID = this.ObjectsArray[ obj.ID ];
183
184 if ( this.Objects[ ID ] && this.Objects[ ID ].Object && this.Objects[ ID ].Object.ID == obj.ID )
185 {
186 QuerySQL( OBJ_DB, "UPDATE Objects SET PX='" + obj.Pos.x + "', PY='" + obj.Pos.y + "', PZ='" + obj.Pos.z + "', AX='" + obj.RotationEuler.x + "', AY='" + obj.RotationEuler.y + "', AZ='" + obj.RotationEuler.z + "' WHERE ID='" + ID + "'" );
187 this.Users[ player.ID ] = null;
188 this.Information("Object updated.", player);
189 QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + obj.Model + "', '" + obj.Pos + "', 'Update', '" + player.Name + "' )" );
190 }
191 }
192 }
193 }
194
195 function Select( player , type, obj)
196 {
197 switch ( type )
198 {
199 case 1: //This will put the player in select mode, he can shoot an obj to select it.
200 this.Users[ player.ID ] = MapperData();
201 this.Users[ player.ID ].SelectingObject = true;
202 this.Users[ player.ID ].Timer = ::Timer.Create(this, function(){ Select(player, 2, null);}, 5000, 1);
203 this.Information("You have 5 seconds to select the object.", player);
204 break;
205
206 case 2: //This cancel the select mode :v
207 Timer.Destroy(this.Users[ player.ID ].Timer);
208 this.Users[ player.ID ] = null;
209 break;
210
211 case 3: //This select the object :v
212 if ( this.Users[ player.ID ].Timer ) ::Timer.Destroy(this.Users[ player.ID ].Timer);
213 this.Users[ player.ID ] = MapperData();
214 this.Users[ player.ID ].Player = player;
215 this.Users[ player.ID ].Object = obj;
216 this.Information("Object selected correctly.", player);
217
218 break;
219 }
220 }
221
222 function Copy(player)
223 {
224 local obj = this.Users[ player.ID ].Object;
225 this.SaveObject( player );
226 this.Users[ player.ID ] = MapperData();
227 this.Users[ player.ID ].Player = player;
228 this.Users[ player.ID ].Object = ::CreateObject( obj.Model, player.World, Vector( obj.Pos.x, obj.Pos.y, obj.Pos.z ), 255 );
229 this.Users[ player.ID ].Object.RotateTo( obj.Rotation,100);
230 this.Users[ player.ID ].Object.TrackingShots = true;
231 this.Information("Object copied successfully.", player);
232 }
233
234 function Mov( player, sign, movsign, amount ) //sign = +/- , movsign = z,x,y
235 {
236 if ( this.Users[ player.ID ] )
237 {
238 local OBJ = this.Users[ player.ID ].Object;
239
240 switch( sign )
241 {
242
243 case "+":
244 {
245 switch ( movsign )
246 {
247 case "x":
248 {
249 OBJ.MoveTo( Vector( OBJ.Pos.x + amount.tofloat(), OBJ.Pos.y, OBJ.Pos.z ), 1500 );
250 this.Information( "Object Moved...", player );
251 }
252 break;
253
254 case "y":
255 {
256 OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y + amount.tofloat(), OBJ.Pos.z ), 1500 );
257 this.Information( "Object Moved...", player );
258 }
259 break;
260
261 case "z":
262 {
263 OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y, OBJ.Pos.z + amount.tofloat() ), 1500 );
264 this.Information( "Object Moved...", player );
265 }
266 break;
267 }
268 }
269 break;
270
271 case "-":
272 {
273 switch ( movsign )
274 {
275 case "x":
276 {
277 OBJ.MoveTo( Vector( OBJ.Pos.x - amount.tofloat(), OBJ.Pos.y, OBJ.Pos.z ), 1500 );
278 this.Information( "Object Moved...", player );
279 }
280 break;
281
282 case "y":
283 {
284 OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y - amount.tofloat(), OBJ.Pos.z ), 1500 );
285 this.Information( "Object Moved...", player );
286 }
287 break;
288
289 case "z":
290 {
291 OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y, OBJ.Pos.z - amount.tofloat() ), 1500 );
292 this.Information( "Object Moved...", player );
293 }
294 break;
295 }
296 }
297 break;
298
299 }
300
301 }
302 }
303
304 function Rot( player, sign, rotsign, amount ) //sign = +/- , rotsign = z,x,y
305 {
306 if ( this.Users[ player.ID ] )
307 {
308 local OBJ = this.Users[ player.ID ].Object;
309
310 switch( sign )
311 {
312
313 case "+":
314 {
315 switch ( rotsign )
316 {
317 case "x":
318 {
319 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x + amount.tofloat(), OBJ.RotationEuler.y, OBJ.RotationEuler.z ), 1500 );
320 this.Information( "Rotated Object...", player );
321 }
322 break;
323
324 case "y":
325 {
326 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y + amount.tofloat(), OBJ.RotationEuler.z ), 1500 );
327 this.Information( "Rotated Object...", player );
328 }
329 break;
330
331 case "z":
332 {
333 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y, OBJ.RotationEuler.z + amount.tofloat() ), 1500 );
334 this.Information( "Rotated Object...", player );
335 }
336 break;
337 }
338 }
339 break;
340
341 case "-":
342 {
343 switch ( rotsign )
344 {
345 case "x":
346 {
347 OBJ.RotateToEuler( Vector( (OBJ.RotationEuler.x - amount.tofloat()), OBJ.RotationEuler.y, OBJ.RotationEuler.z ), 1500 );
348 this.Information( "Rotated Object...", player );
349 }
350 break;
351
352 case "y":
353 {
354 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, (OBJ.RotationEuler.y - amount.tofloat()), OBJ.RotationEuler.z ), 1500 );
355 this.Information( "Rotated Object...", player );
356 }
357 break;
358
359 case "z":
360 {
361 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y, (OBJ.RotationEuler.z - amount.tofloat() )), 1500 );
362 this.Information( "Rotated Object...", player );
363 }
364 break;
365 }
366 }
367 break;
368
369 }
370
371 }
372 }
373
374
375
376 function CountObjects()
377 {
378 try
379 {
380 local a = 0, q = QuerySQL( OBJ_DB, "SELECT * FROM Objects" );
381 while ( GetSQLColumnData( q, 0 ) )
382 {
383 a ++;
384 GetSQLNextRow( q );
385 }
386 return a;
387 FreeSQLQuery( q );
388 } catch(e) print( "[Error] CountObjects - " + e );
389 }
390
391 /*
392
393 OTHERS FUNCTIONS
394
395 */
396
397 function Sintax( text, player )
398 {
399 ::MessagePlayer( "[#FF00FF][SINTAX][#FFFFFF] " + text, player );
400 }
401
402 function Error( text, player )
403 {
404 ::MessagePlayer( "[#FF4500][ERROR][#FF0000] " + text, player );
405 }
406
407 function Information( text, player )
408 {
409 ::MessagePlayer( "[#FF00FF][INFO][#FFFFFF] " + text, player );
410 }
411
412 function Message( text )
413 {
414 ::Message( "[#FFB533][[#FFE633]MAPPER SYSTEM[#FFB533]][#FBFF8A] " + text );
415 }
416
417 function onObjectShot(player, object)
418 {
419 if ( Mapper.Users[ player.ID ] && Mapper.Users[ player.ID ].SelectingObject == true)
420 {
421 ::Mapper.Select(player, 3, object);
422 }
423 }
424
425 function onCommand( player, cmd, text )
426 {
427 if ( cmd == "createobj" || cmd == "obj" )
428 {
429 if ( Mapper.Users[ player.ID ] != null ) this.Error("You already have created an object.", player);
430 else if (!text) this.Sintax("/"+ cmd + " modelo", player)
431 else
432 {
433 Mapper.CreateObject(player, text.tointeger());
434 }
435 }
436
437 else if ( cmd == "save" )
438 {
439 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
440 else
441 {
442 Mapper.SaveObject( player );
443 }
444 }
445
446 else if ( cmd == "copy" )
447 {
448 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
449 else
450 {
451 Mapper.Copy( player );
452 }
453 }
454
455 else if ( cmd == "objdel" )
456 {
457 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
458 else
459 {
460 Mapper.DeleteObject( player );
461 }
462 }
463
464 else if ( cmd == "objselect" )
465 {
466 if ( Mapper.Users[ player.ID ] ) this.Error("You already has an object.", player);
467 else if (!text) this.Error("/objselect mouse/id", player)
468 else
469 {
470 if (text == "mouse") Mapper.Select(player, 1, null);
471 else if ( !IsNum(text)) this.Error("/objselect mouse/id", player)
472 else
473 {
474 if ( FindObject(text.tointeger()) )
475 {
476 if ( Mapper.Users[ player.ID ] && Mapper.Users[ player.ID ].Timer ) ::Timer.Destroy(Mapper.Users[ player.ID ].Timer);
477 Mapper.Users[ player.ID ] = MapperData();
478 Mapper.Users[ player.ID ].Player = player;
479 Mapper.Users[ player.ID ].Object = FindObject(text.tointeger());
480 this.Information("Object selected correctly.", player);
481 }
482 else this.Error("Object not found.", player);
483 }
484 }
485 }
486
487 else if ( cmd == "mov" )
488 {
489 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
490 else if (!GetTok( text, " ", 1) || !GetTok( text, " ", 2) || !GetTok( text, " ", 3)) this.Sintax("/mov x/y/z +/- amount")
491 else
492 {
493 local movsign = GetTok( text, " ", 1), sign = GetTok( text, " ", 2), amount = GetTok( text, " ", 3);
494 Mapper.Mov( player, sign, movsign, amount );
495 }
496 }
497
498 else if ( cmd == "rot" )
499 {
500 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
501 else if (!GetTok( text, " ", 1) || !GetTok( text, " ", 2) || !GetTok( text, " ", 3)) this.Sintax("/rot x/y/z +/- amount")
502 else
503 {
504 try
505 {
506 local rotsign = GetTok( text, " ", 1), sign = GetTok( text, " ", 2), amount = GetTok( text, " ", 3);
507 Mapper.Rot( player, sign, rotsign, amount );
508 } catch (e) this.Message(e);
509 }
510 }
511
512 else if ( cmd == "gotomyobj" )
513 {
514 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
515 else player.Pos = Mapper.Users[ player.ID ].Object.Pos;
516 }
517
518
519 else if ( cmd == "objinfo" )
520 {
521 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
522 else
523 {
524 this.Message( Mapper.Users[ player.ID ].Object.Pos + " " + Mapper.Users[ player.ID ].Object.RotationEuler);
525 this.Message( Mapper.Users[ player.ID ].Object.Rotation.x + " " + Mapper.Users[ player.ID ].Object.Rotation.y + " " + Mapper.Users[ player.ID ].Object.Rotation.z);
526 }
527 }
528 }
529}
530 Object = null
531 SelectingObject = false
532 Timer = null
533}
534
535class ObjectsClass
536{
537 ID = null;
538 Object = null;
539 Model = null;
540
541 PX = null;
542 PY = null;
543 PZ = null;
544
545 AX = null;
546 AY = null;
547 AZ = null;
548
549}
550
551
552Mapper <- {
553
554 function LoadSystem()
555 {
556 QuerySQL(OBJ_DB, "CREATE TABLE IF NOT EXISTS Objects ( ID INTEGER PRIMARY KEY AUTOINCREMENT, Model NUMERIC, PX FLOAT, PY FLOAT, PZ FLOAT, AX FLOAT, AY FLOAT, AZ FLOAT, MappedBy TEXT )" );
557 QuerySQL(OBJ_DB, "CREATE TABLE IF NOT EXISTS Logger ( ID INTEGER, Model INTEGER, Position TEXT, Action TEXT, Mapper TEXT )" );
558
559 this.Users <- array( GetMaxPlayers(), null );
560 Objects <- array( 3001, null );
561 ObjectsArray <- array( 3001, null );
562
563 this.LoadObjects();
564 print("Mapper System loaded - By Naru^/Maximiliano");
565 }
566
567 function LoadObjects()
568 {
569 local cq = QuerySQL( OBJ_DB, "SELECT COUNT(*) FROM Objects" ), count = GetSQLColumnData( cq, 0 );
570
571 if ( !count )
572 {
573 print( "Objects Loaded: 0" );
574 return false;
575 }
576
577 local i = 0;
578 local q = QuerySQL( OBJ_DB, "SELECT * FROM Objects" );
579 while ( GetSQLColumnData( q, 0 ) != null )
580 {
581 local ID = GetSQLColumnData( q, 0 );
582 this.Objects[ID] = ObjectsClass();
583 this.Objects[ID].ID = ID;
584 this.Objects[ID].Model = GetSQLColumnData( q, 1 );
585 this.Objects[ID].PX = GetSQLColumnData( q, 2 );
586 this.Objects[ID].PY = GetSQLColumnData( q, 3 );
587 this.Objects[ID].PZ = GetSQLColumnData( q, 4 );
588 this.Objects[ID].AX = GetSQLColumnData( q, 5 );
589 this.Objects[ID].AY = GetSQLColumnData( q, 6 );
590 this.Objects[ID].AZ = GetSQLColumnData( q, 7 );
591
592 local Model = GetSQLColumnData( q, 1 ),
593 PX = this.Objects[ID].PX.tofloat(),
594 PY = this.Objects[ID].PY.tofloat(),
595 PZ = this.Objects[ID].PZ.tofloat(),
596 AX = this.Objects[ID].AX.tofloat(),
597 AY = this.Objects[ID].AY.tofloat(),
598 AZ = this.Objects[ID].AZ.tofloat();
599
600 this.Objects[ID].Object = ::CreateObject( Model, 1, Vector( PX, PY, PZ ), 255 );
601 this.Objects[ID].Object.RotateToEuler( Vector( AX, AY, AZ ), 0 );
602 this.Objects[ID].Object.TrackingShots = true;
603
604 this.ObjectsArray[ this.Objects[ID].Object.ID ] = ID;
605 i++;
606 GetSQLNextRow( q );
607 }
608 FreeSQLQuery( q );
609 print( "Objects Loaded: " + i );
610 }
611
612
613 function CreateObject(player, model)
614 {
615 if ( !this.Users[ player.ID ] )
616 {
617 this.Users[ player.ID ] = MapperData();
618 this.Users[ player.ID ].Player = player;
619 this.Users[ player.ID ].Object = ::CreateObject( model.tointeger(), player.World, Vector( player.Pos.x, player.Pos.y, player.Pos.z + 0.5 ), 255 );
620 this.Users[ player.ID ].Object.TrackingShots = true;
621 this.Information("Object created successfully.", player);
622 }
623 }
624
625 function DeleteObject( player )
626 {
627 if ( this.Users[ player.ID ] )
628 {
629 local obj = this.Users[ player.ID ].Object;
630 if ( this.ObjectsArray[ obj.ID ] == null )
631 {
632 this.Information("Object removed.", player);
633 this.Users[ player.ID ].Object.Delete();
634 this.Users[ player.ID ] = null;
635 }
636 else
637 {
638
639 local ID = this.ObjectsArray[ obj.ID ];
640 if ( this.Objects[ ID ] && this.Objects[ ID ].Object.ID == obj.ID )
641 {
642 QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + obj.Model + "', '" + obj.Pos + "', 'Delete', '" + player.Name + "' )" );
643
644 QuerySQL( OBJ_DB, "DELETE FROM Objects WHERE ID='" + ID + "'" );
645 this.Objects[ID] = null;
646 this.Information("Object removed..", player);
647 this.ObjectsArray[ obj.ID ] = null;
648 this.Users[ player.ID ].Object.Delete();
649 this.Users[ player.ID ] = null;
650
651
652 }
653 }
654
655 }
656 }
657
658 function SaveObject( player )
659 {
660 if ( this.Users[ player.ID ] )
661 {
662 local obj = this.Users[ player.ID ].Object;
663 if ( this.ObjectsArray[ obj.ID ] == null )
664 {
665 local OBJ = this.Users[ player.ID ].Object;
666 QuerySQL( OBJ_DB, "INSERT INTO Objects ( Model, PX, PY, PZ, AX, AY, AZ, MappedBy ) VALUES ( '" + OBJ.Model + "', '" + OBJ.Pos.x + "', '" + OBJ.Pos.y + "', '" + OBJ.Pos.z + "', '" + OBJ.RotationEuler.x + "', '" + OBJ.RotationEuler.y + "', '" + OBJ.RotationEuler.z + "', '" + player.Name + "' )" );
667
668
669 local GetID = QuerySQL( OBJ_DB, "SELECT ID FROM Objects ORDER BY ID DESC LIMIT 1");
670 local ID = GetSQLColumnData( GetID, 0 ).tointeger();
671
672 local q = QuerySQL( OBJ_DB, "SELECT * FROM Objects WHERE ID='" + ID + "'" );
673 if ( q )
674 {
675 local ID = GetSQLColumnData( q, 0 );
676 this.Objects[ID] = ObjectsClass();
677 this.Objects[ID].ID = ID;
678 this.Objects[ID].Model = GetSQLColumnData( q, 1 );
679 this.Objects[ID].PX = GetSQLColumnData( q, 2 );
680 this.Objects[ID].PY = GetSQLColumnData( q, 3 );
681 this.Objects[ID].PZ = GetSQLColumnData( q, 4 );
682 this.Objects[ID].AX = GetSQLColumnData( q, 5 );
683 this.Objects[ID].AY = GetSQLColumnData( q, 6 );
684 this.Objects[ID].AZ = GetSQLColumnData( q, 7 );
685
686 local Model = GetSQLColumnData( q, 1 ),
687 PX = this.Objects[ID].PX.tofloat(),
688 PY = this.Objects[ID].PY.tofloat(),
689 PZ = this.Objects[ID].PZ.tofloat(),
690 AX = this.Objects[ID].AX.tofloat(),
691 AY = this.Objects[ID].AY.tofloat(),
692 AZ = this.Objects[ID].AZ.tofloat();
693
694 this.Objects[ID].Object = this.Users[ player.ID ].Object;
695 this.Objects[ID].Object.RotateToEuler( Vector( AX, AY, AZ ), 0 );
696
697 this.ObjectsArray[ this.Objects[ID].Object.ID ] = ID;
698 this.Users[ player.ID ] = null;
699 QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + OBJ.Model + "', '" + OBJ.Pos + "', 'Save', '" + player.Name + "' )" );
700 this.Information("Object saved.", player);
701 }
702 }
703 else
704 {
705
706 local ID = this.ObjectsArray[ obj.ID ];
707
708 if ( this.Objects[ ID ] && this.Objects[ ID ].Object && this.Objects[ ID ].Object.ID == obj.ID )
709 {
710 QuerySQL( OBJ_DB, "UPDATE Objects SET PX='" + obj.Pos.x + "', PY='" + obj.Pos.y + "', PZ='" + obj.Pos.z + "', AX='" + obj.RotationEuler.x + "', AY='" + obj.RotationEuler.y + "', AZ='" + obj.RotationEuler.z + "' WHERE ID='" + ID + "'" );
711 this.Users[ player.ID ] = null;
712 this.Information("Object updated.", player);
713 QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + obj.Model + "', '" + obj.Pos + "', 'Update', '" + player.Name + "' )" );
714 }
715 }
716 }
717 }
718
719 function Select( player , type, obj)
720 {
721 switch ( type )
722 {
723 case 1: //This will put the player in select mode, he can shoot an obj to select it.
724 this.Users[ player.ID ] = MapperData();
725 this.Users[ player.ID ].SelectingObject = true;
726 this.Users[ player.ID ].Timer = ::Timer.Create(this, function(){ Select(player, 2, null);}, 5000, 1);
727 this.Information("You have 5 seconds to select the object.", player);
728 break;
729
730 case 2: //This cancel the select mode :v
731 Timer.Destroy(this.Users[ player.ID ].Timer);
732 this.Users[ player.ID ] = null;
733 break;
734
735 case 3: //This select the object :v
736 if ( this.Users[ player.ID ].Timer ) ::Timer.Destroy(this.Users[ player.ID ].Timer);
737 this.Users[ player.ID ] = MapperData();
738 this.Users[ player.ID ].Player = player;
739 this.Users[ player.ID ].Object = obj;
740 this.Information("Object selected correctly.", player);
741
742 break;
743 }
744 }
745
746 function Copy(player)
747 {
748 local obj = this.Users[ player.ID ].Object;
749 this.SaveObject( player );
750 this.Users[ player.ID ] = MapperData();
751 this.Users[ player.ID ].Player = player;
752 this.Users[ player.ID ].Object = ::CreateObject( obj.Model, player.World, Vector( obj.Pos.x, obj.Pos.y, obj.Pos.z ), 255 );
753 this.Users[ player.ID ].Object.RotateTo( obj.Rotation,100);
754 this.Users[ player.ID ].Object.TrackingShots = true;
755 this.Information("Object copied successfully.", player);
756 }
757
758 function Mov( player, sign, movsign, amount ) //sign = +/- , movsign = z,x,y
759 {
760 if ( this.Users[ player.ID ] )
761 {
762 local OBJ = this.Users[ player.ID ].Object;
763
764 switch( sign )
765 {
766
767 case "+":
768 {
769 switch ( movsign )
770 {
771 case "x":
772 {
773 OBJ.MoveTo( Vector( OBJ.Pos.x + amount.tofloat(), OBJ.Pos.y, OBJ.Pos.z ), 1500 );
774 this.Information( "Object Moved...", player );
775 }
776 break;
777
778 case "y":
779 {
780 OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y + amount.tofloat(), OBJ.Pos.z ), 1500 );
781 this.Information( "Object Moved...", player );
782 }
783 break;
784
785 case "z":
786 {
787 OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y, OBJ.Pos.z + amount.tofloat() ), 1500 );
788 this.Information( "Object Moved...", player );
789 }
790 break;
791 }
792 }
793 break;
794
795 case "-":
796 {
797 switch ( movsign )
798 {
799 case "x":
800 {
801 OBJ.MoveTo( Vector( OBJ.Pos.x - amount.tofloat(), OBJ.Pos.y, OBJ.Pos.z ), 1500 );
802 this.Information( "Object Moved...", player );
803 }
804 break;
805
806 case "y":
807 {
808 OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y - amount.tofloat(), OBJ.Pos.z ), 1500 );
809 this.Information( "Object Moved...", player );
810 }
811 break;
812
813 case "z":
814 {
815 OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y, OBJ.Pos.z - amount.tofloat() ), 1500 );
816 this.Information( "Object Moved...", player );
817 }
818 break;
819 }
820 }
821 break;
822
823 }
824
825 }
826 }
827
828 function Rot( player, sign, rotsign, amount ) //sign = +/- , rotsign = z,x,y
829 {
830 if ( this.Users[ player.ID ] )
831 {
832 local OBJ = this.Users[ player.ID ].Object;
833
834 switch( sign )
835 {
836
837 case "+":
838 {
839 switch ( rotsign )
840 {
841 case "x":
842 {
843 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x + amount.tofloat(), OBJ.RotationEuler.y, OBJ.RotationEuler.z ), 1500 );
844 this.Information( "Rotated Object...", player );
845 }
846 break;
847
848 case "y":
849 {
850 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y + amount.tofloat(), OBJ.RotationEuler.z ), 1500 );
851 this.Information( "Rotated Object...", player );
852 }
853 break;
854
855 case "z":
856 {
857 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y, OBJ.RotationEuler.z + amount.tofloat() ), 1500 );
858 this.Information( "Rotated Object...", player );
859 }
860 break;
861 }
862 }
863 break;
864
865 case "-":
866 {
867 switch ( rotsign )
868 {
869 case "x":
870 {
871 OBJ.RotateToEuler( Vector( (OBJ.RotationEuler.x - amount.tofloat()), OBJ.RotationEuler.y, OBJ.RotationEuler.z ), 1500 );
872 this.Information( "Rotated Object...", player );
873 }
874 break;
875
876 case "y":
877 {
878 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, (OBJ.RotationEuler.y - amount.tofloat()), OBJ.RotationEuler.z ), 1500 );
879 this.Information( "Rotated Object...", player );
880 }
881 break;
882
883 case "z":
884 {
885 OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y, (OBJ.RotationEuler.z - amount.tofloat() )), 1500 );
886 this.Information( "Rotated Object...", player );
887 }
888 break;
889 }
890 }
891 break;
892
893 }
894
895 }
896 }
897
898
899
900 function CountObjects()
901 {
902 try
903 {
904 local a = 0, q = QuerySQL( OBJ_DB, "SELECT * FROM Objects" );
905 while ( GetSQLColumnData( q, 0 ) )
906 {
907 a ++;
908 GetSQLNextRow( q );
909 }
910 return a;
911 FreeSQLQuery( q );
912 } catch(e) print( "[Error] CountObjects - " + e );
913 }
914
915 /*
916
917 OTHERS FUNCTIONS
918
919 */
920
921 function Sintax( text, player )
922 {
923 ::MessagePlayer( "[#FF00FF][SINTAX][#FFFFFF] " + text, player );
924 }
925
926 function Error( text, player )
927 {
928 ::MessagePlayer( "[#FF4500][ERROR][#FF0000] " + text, player );
929 }
930
931 function Information( text, player )
932 {
933 ::MessagePlayer( "[#FF00FF][INFO][#FFFFFF] " + text, player );
934 }
935
936 function Message( text )
937 {
938 ::Message( "[#FFB533][[#FFE633]MAPPER SYSTEM[#FFB533]][#FBFF8A] " + text );
939 }
940
941 function onObjectShot(player, object)
942 {
943 if ( Mapper.Users[ player.ID ] && Mapper.Users[ player.ID ].SelectingObject == true)
944 {
945 ::Mapper.Select(player, 3, object);
946 }
947 }
948
949 function onCommand( player, cmd, text )
950 {
951 if ( cmd == "createobj" || cmd == "obj" )
952 {
953 if ( Mapper.Users[ player.ID ] != null ) this.Error("You already have created an object.", player);
954 else if (!text) this.Sintax("/"+ cmd + " modelo", player)
955 else
956 {
957 Mapper.CreateObject(player, text.tointeger());
958 }
959 }
960
961 else if ( cmd == "save" )
962 {
963 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
964 else
965 {
966 Mapper.SaveObject( player );
967 }
968 }
969
970 else if ( cmd == "copy" )
971 {
972 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
973 else
974 {
975 Mapper.Copy( player );
976 }
977 }
978
979 else if ( cmd == "objdel" )
980 {
981 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
982 else
983 {
984 Mapper.DeleteObject( player );
985 }
986 }
987
988 else if ( cmd == "objselect" )
989 {
990 if ( Mapper.Users[ player.ID ] ) this.Error("You already has an object.", player);
991 else if (!text) this.Error("/objselect mouse/id", player)
992 else
993 {
994 if (text == "mouse") Mapper.Select(player, 1, null);
995 else if ( !IsNum(text)) this.Error("/objselect mouse/id", player)
996 else
997 {
998 if ( FindObject(text.tointeger()) )
999 {
1000 if ( Mapper.Users[ player.ID ] && Mapper.Users[ player.ID ].Timer ) ::Timer.Destroy(Mapper.Users[ player.ID ].Timer);
1001 Mapper.Users[ player.ID ] = MapperData();
1002 Mapper.Users[ player.ID ].Player = player;
1003 Mapper.Users[ player.ID ].Object = FindObject(text.tointeger());
1004 this.Information("Object selected correctly.", player);
1005 }
1006 else this.Error("Object not found.", player);
1007 }
1008 }
1009 }
1010
1011 else if ( cmd == "mov" )
1012 {
1013 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
1014 else if (!GetTok( text, " ", 1) || !GetTok( text, " ", 2) || !GetTok( text, " ", 3)) this.Sintax("/mov x/y/z +/- amount")
1015 else
1016 {
1017 local movsign = GetTok( text, " ", 1), sign = GetTok( text, " ", 2), amount = GetTok( text, " ", 3);
1018 Mapper.Mov( player, sign, movsign, amount );
1019 }
1020 }
1021
1022 else if ( cmd == "rot" )
1023 {
1024 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
1025 else if (!GetTok( text, " ", 1) || !GetTok( text, " ", 2) || !GetTok( text, " ", 3)) this.Sintax("/rot x/y/z +/- amount")
1026 else
1027 {
1028 try
1029 {
1030 local rotsign = GetTok( text, " ", 1), sign = GetTok( text, " ", 2), amount = GetTok( text, " ", 3);
1031 Mapper.Rot( player, sign, rotsign, amount );
1032 } catch (e) this.Message(e);
1033 }
1034 }
1035
1036 else if ( cmd == "gotomyobj" )
1037 {
1038 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
1039 else player.Pos = Mapper.Users[ player.ID ].Object.Pos;
1040 }
1041
1042
1043 else if ( cmd == "objinfo" )
1044 {
1045 if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
1046 else
1047 {
1048 this.Message( Mapper.Users[ player.ID ].Object.Pos + " " + Mapper.Users[ player.ID ].Object.RotationEuler);
1049 this.Message( Mapper.Users[ player.ID ].Object.Rotation.x + " " + Mapper.Users[ player.ID ].Object.Rotation.y + " " + Mapper.Users[ player.ID ].Object.Rotation.z);
1050 }
1051 }
1052 }
1053}