Advertisement
Guest User

Mapper System - VCMP 0.4

a guest
Mar 1st, 2021
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.40 KB | None | 0 0
  1. class MapperData
  2. {
  3. Player = null
  4. Object = null
  5. SelectingObject = false
  6. Timer = null
  7. }
  8.  
  9. class ObjectsClass
  10. {
  11. ID = null;
  12. Object = null;
  13. Model = null;
  14.  
  15. PX = null;
  16. PY = null;
  17. PZ = null;
  18.  
  19. AX = null;
  20. AY = null;
  21. AZ = null;
  22.  
  23. }
  24.  
  25.  
  26. Mapper <- {
  27.  
  28. Users = array( GetMaxPlayers(), null ),
  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. Objects <- array( 3001, null );
  36. ObjectsArray <- array( 3001, null );
  37.  
  38. this.LoadObjects();
  39. print("Mapper System loaded - By Naru^/Maximiliano");
  40. }
  41.  
  42. function LoadObjects()
  43. {
  44. local cq = QuerySQL( OBJ_DB, "SELECT COUNT(*) FROM Objects" ), count = GetSQLColumnData( cq, 0 );
  45.  
  46. if ( !count )
  47. {
  48. print( "Objects Loaded: 0" );
  49. return false;
  50. }
  51.  
  52. local i = 0;
  53. local q = QuerySQL( OBJ_DB, "SELECT * FROM Objects" );
  54. while ( GetSQLColumnData( q, 0 ) != null )
  55. {
  56. local ID = GetSQLColumnData( q, 0 );
  57. this.Objects[ID] = ObjectsClass();
  58. this.Objects[ID].ID = ID;
  59. this.Objects[ID].Model = GetSQLColumnData( q, 1 );
  60. this.Objects[ID].PX = GetSQLColumnData( q, 2 );
  61. this.Objects[ID].PY = GetSQLColumnData( q, 3 );
  62. this.Objects[ID].PZ = GetSQLColumnData( q, 4 );
  63. this.Objects[ID].AX = GetSQLColumnData( q, 5 );
  64. this.Objects[ID].AY = GetSQLColumnData( q, 6 );
  65. this.Objects[ID].AZ = GetSQLColumnData( q, 7 );
  66.  
  67. local Model = GetSQLColumnData( q, 1 ),
  68. PX = this.Objects[ID].PX.tofloat(),
  69. PY = this.Objects[ID].PY.tofloat(),
  70. PZ = this.Objects[ID].PZ.tofloat(),
  71. AX = this.Objects[ID].AX.tofloat(),
  72. AY = this.Objects[ID].AY.tofloat(),
  73. AZ = this.Objects[ID].AZ.tofloat();
  74.  
  75. this.Objects[ID].Object = ::CreateObject( Model, 1, Vector( PX, PY, PZ ), 255 );
  76. this.Objects[ID].Object.RotateToEuler( Vector( AX, AY, AZ ), 0 );
  77. this.Objects[ID].Object.TrackingShots = true;
  78.  
  79. this.ObjectsArray[ this.Objects[ID].Object.ID ] = ID;
  80. i++;
  81. GetSQLNextRow( q );
  82. }
  83. FreeSQLQuery( q );
  84. print( "Objects Loaded: " + i );
  85. }
  86.  
  87.  
  88. function CreateObject(player, model)
  89. {
  90. if ( !this.Users[ player.ID ] )
  91. {
  92. this.Users[ player.ID ] = MapperData();
  93. this.Users[ player.ID ].Player = player;
  94. this.Users[ player.ID ].Object = ::CreateObject( model.tointeger(), player.World, Vector( player.Pos.x, player.Pos.y, player.Pos.z + 0.5 ), 255 );
  95. this.Users[ player.ID ].Object.TrackingShots = true;
  96. this.Information("Object created successfully.", player);
  97. }
  98. }
  99.  
  100. function DeleteObject( player )
  101. {
  102. if ( this.Users[ player.ID ] )
  103. {
  104. local obj = this.Users[ player.ID ].Object;
  105. if ( this.ObjectsArray[ obj.ID ] == null )
  106. {
  107. this.Information("Object removed.", player);
  108. this.Users[ player.ID ].Object.Delete();
  109. this.Users[ player.ID ] = null;
  110. }
  111. else
  112. {
  113.  
  114. local ID = this.ObjectsArray[ obj.ID ];
  115. if ( this.Objects[ ID ] && this.Objects[ ID ].Object.ID == obj.ID )
  116. {
  117. QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + obj.Model + "', '" + obj.Pos + "', 'Delete', '" + player.Name + "' )" );
  118.  
  119. QuerySQL( OBJ_DB, "DELETE FROM Objects WHERE ID='" + ID + "'" );
  120. this.Objects[ID] = null;
  121. this.Information("Object removed..", player);
  122. this.ObjectsArray[ obj.ID ] = null;
  123. this.Users[ player.ID ].Object.Delete();
  124. this.Users[ player.ID ] = null;
  125.  
  126.  
  127. }
  128. }
  129.  
  130. }
  131. }
  132.  
  133. function SaveObject( player )
  134. {
  135. if ( this.Users[ player.ID ] )
  136. {
  137. local obj = this.Users[ player.ID ].Object;
  138. if ( this.ObjectsArray[ obj.ID ] == null )
  139. {
  140. local OBJ = this.Users[ player.ID ].Object;
  141. 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 + "' )" );
  142.  
  143.  
  144. local GetID = QuerySQL( OBJ_DB, "SELECT ID FROM Objects ORDER BY ID DESC LIMIT 1");
  145. local ID = GetSQLColumnData( GetID, 0 ).tointeger();
  146.  
  147. local q = QuerySQL( OBJ_DB, "SELECT * FROM Objects WHERE ID='" + ID + "'" );
  148. if ( q )
  149. {
  150. local ID = GetSQLColumnData( q, 0 );
  151. this.Objects[ID] = ObjectsClass();
  152. this.Objects[ID].ID = ID;
  153. this.Objects[ID].Model = GetSQLColumnData( q, 1 );
  154. this.Objects[ID].PX = GetSQLColumnData( q, 2 );
  155. this.Objects[ID].PY = GetSQLColumnData( q, 3 );
  156. this.Objects[ID].PZ = GetSQLColumnData( q, 4 );
  157. this.Objects[ID].AX = GetSQLColumnData( q, 5 );
  158. this.Objects[ID].AY = GetSQLColumnData( q, 6 );
  159. this.Objects[ID].AZ = GetSQLColumnData( q, 7 );
  160.  
  161. local Model = GetSQLColumnData( q, 1 ),
  162. PX = this.Objects[ID].PX.tofloat(),
  163. PY = this.Objects[ID].PY.tofloat(),
  164. PZ = this.Objects[ID].PZ.tofloat(),
  165. AX = this.Objects[ID].AX.tofloat(),
  166. AY = this.Objects[ID].AY.tofloat(),
  167. AZ = this.Objects[ID].AZ.tofloat();
  168.  
  169. this.Objects[ID].Object = this.Users[ player.ID ].Object;
  170. this.Objects[ID].Object.RotateToEuler( Vector( AX, AY, AZ ), 0 );
  171.  
  172. this.ObjectsArray[ this.Objects[ID].Object.ID ] = ID;
  173. this.Users[ player.ID ] = null;
  174. QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + OBJ.Model + "', '" + OBJ.Pos + "', 'Save', '" + player.Name + "' )" );
  175. this.Information("Object saved.", player);
  176. }
  177. }
  178. else
  179. {
  180.  
  181. local ID = this.ObjectsArray[ obj.ID ];
  182.  
  183. if ( this.Objects[ ID ] && this.Objects[ ID ].Object && this.Objects[ ID ].Object.ID == obj.ID )
  184. {
  185. 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 + "'" );
  186. this.Users[ player.ID ] = null;
  187. this.Information("Object updated.", player);
  188. QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + obj.Model + "', '" + obj.Pos + "', 'Update', '" + player.Name + "' )" );
  189. }
  190. }
  191. }
  192. }
  193.  
  194. function Select( player , type, obj)
  195. {
  196. switch ( type )
  197. {
  198. case 1: //This will put the player in select mode, he can shoot an obj to select it.
  199. this.Users[ player.ID ] = MapperData();
  200. this.Users[ player.ID ].SelectingObject = true;
  201. this.Users[ player.ID ].Timer = ::Timer.Create(this, function(){ Select(player, 2, null);}, 5000, 1);
  202. this.Information("You have 5 seconds to select the object.", player);
  203. break;
  204.  
  205. case 2: //This cancel the select mode :v
  206. Timer.Destroy(this.Users[ player.ID ].Timer);
  207. this.Users[ player.ID ] = null;
  208. break;
  209.  
  210. case 3: //This select the object :v
  211. if ( this.Users[ player.ID ].Timer ) ::Timer.Destroy(this.Users[ player.ID ].Timer);
  212. this.Users[ player.ID ] = MapperData();
  213. this.Users[ player.ID ].Player = player;
  214. this.Users[ player.ID ].Object = obj;
  215. this.Information("Object selected correctly.", player);
  216.  
  217. break;
  218. }
  219. }
  220.  
  221. function Copy(player)
  222. {
  223. local obj = this.Users[ player.ID ].Object;
  224. this.SaveObject( player );
  225. this.Users[ player.ID ] = MapperData();
  226. this.Users[ player.ID ].Player = player;
  227. this.Users[ player.ID ].Object = ::CreateObject( obj.Model, player.World, Vector( obj.Pos.x, obj.Pos.y, obj.Pos.z ), 255 );
  228. this.Users[ player.ID ].Object.RotateTo( obj.Rotation,100);
  229. this.Users[ player.ID ].Object.TrackingShots = true;
  230. this.Information("Object copied successfully.", player);
  231. }
  232.  
  233. function Mov( player, sign, movsign, amount ) //sign = +/- , movsign = z,x,y
  234. {
  235. if ( this.Users[ player.ID ] )
  236. {
  237. local OBJ = this.Users[ player.ID ].Object;
  238.  
  239. switch( sign )
  240. {
  241.  
  242. case "+":
  243. {
  244. switch ( movsign )
  245. {
  246. case "x":
  247. {
  248. OBJ.MoveTo( Vector( OBJ.Pos.x + amount.tofloat(), OBJ.Pos.y, OBJ.Pos.z ), 1500 );
  249. this.Information( "Object Moved...", player );
  250. }
  251. break;
  252.  
  253. case "y":
  254. {
  255. OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y + amount.tofloat(), OBJ.Pos.z ), 1500 );
  256. this.Information( "Object Moved...", player );
  257. }
  258. break;
  259.  
  260. case "z":
  261. {
  262. OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y, OBJ.Pos.z + amount.tofloat() ), 1500 );
  263. this.Information( "Object Moved...", player );
  264. }
  265. break;
  266. }
  267. }
  268. break;
  269.  
  270. case "-":
  271. {
  272. switch ( movsign )
  273. {
  274. case "x":
  275. {
  276. OBJ.MoveTo( Vector( OBJ.Pos.x - amount.tofloat(), OBJ.Pos.y, OBJ.Pos.z ), 1500 );
  277. this.Information( "Object Moved...", player );
  278. }
  279. break;
  280.  
  281. case "y":
  282. {
  283. OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y - amount.tofloat(), OBJ.Pos.z ), 1500 );
  284. this.Information( "Object Moved...", player );
  285. }
  286. break;
  287.  
  288. case "z":
  289. {
  290. OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y, OBJ.Pos.z - amount.tofloat() ), 1500 );
  291. this.Information( "Object Moved...", player );
  292. }
  293. break;
  294. }
  295. }
  296. break;
  297.  
  298. }
  299.  
  300. }
  301. }
  302.  
  303. function Rot( player, sign, rotsign, amount ) //sign = +/- , rotsign = z,x,y
  304. {
  305. if ( this.Users[ player.ID ] )
  306. {
  307. local OBJ = this.Users[ player.ID ].Object;
  308.  
  309. switch( sign )
  310. {
  311.  
  312. case "+":
  313. {
  314. switch ( rotsign )
  315. {
  316. case "x":
  317. {
  318. OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x + amount.tofloat(), OBJ.RotationEuler.y, OBJ.RotationEuler.z ), 1500 );
  319. this.Information( "Rotated Object...", player );
  320. }
  321. break;
  322.  
  323. case "y":
  324. {
  325. OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y + amount.tofloat(), OBJ.RotationEuler.z ), 1500 );
  326. this.Information( "Rotated Object...", player );
  327. }
  328. break;
  329.  
  330. case "z":
  331. {
  332. OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y, OBJ.RotationEuler.z + amount.tofloat() ), 1500 );
  333. this.Information( "Rotated Object...", player );
  334. }
  335. break;
  336. }
  337. }
  338. break;
  339.  
  340. case "-":
  341. {
  342. switch ( rotsign )
  343. {
  344. case "x":
  345. {
  346. OBJ.RotateToEuler( Vector( (OBJ.RotationEuler.x - amount.tofloat()), OBJ.RotationEuler.y, OBJ.RotationEuler.z ), 1500 );
  347. this.Information( "Rotated Object...", player );
  348. }
  349. break;
  350.  
  351. case "y":
  352. {
  353. OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, (OBJ.RotationEuler.y - amount.tofloat()), OBJ.RotationEuler.z ), 1500 );
  354. this.Information( "Rotated Object...", player );
  355. }
  356. break;
  357.  
  358. case "z":
  359. {
  360. OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y, (OBJ.RotationEuler.z - amount.tofloat() )), 1500 );
  361. this.Information( "Rotated Object...", player );
  362. }
  363. break;
  364. }
  365. }
  366. break;
  367.  
  368. }
  369.  
  370. }
  371. }
  372.  
  373.  
  374.  
  375. function CountObjects()
  376. {
  377. try
  378. {
  379. local a = 0, q = QuerySQL( OBJ_DB, "SELECT * FROM Objects" );
  380. while ( GetSQLColumnData( q, 0 ) )
  381. {
  382. a ++;
  383. GetSQLNextRow( q );
  384. }
  385. return a;
  386. FreeSQLQuery( q );
  387. } catch(e) print( "[Error] CountObjects - " + e );
  388. }
  389.  
  390. /*
  391.  
  392. OTHERS FUNCTIONS
  393.  
  394. */
  395.  
  396. function Sintax( text, player )
  397. {
  398. ::MessagePlayer( "[#FF00FF][SINTAX][#FFFFFF] " + text, player );
  399. }
  400.  
  401. function Error( text, player )
  402. {
  403. ::MessagePlayer( "[#FF4500][ERROR][#FF0000] " + text, player );
  404. }
  405.  
  406. function Information( text, player )
  407. {
  408. ::MessagePlayer( "[#FF00FF][INFO][#FFFFFF] " + text, player );
  409. }
  410.  
  411. function Message( text )
  412. {
  413. ::Message( "[#FFB533][[#FFE633]MAPPER SYSTEM[#FFB533]][#FBFF8A] " + text );
  414. }
  415.  
  416. function onObjectShot(player, object)
  417. {
  418. if ( Mapper.Users[ player.ID ] && Mapper.Users[ player.ID ].SelectingObject == true)
  419. {
  420. ::Mapper.Select(player, 3, object);
  421. }
  422. }
  423.  
  424. function onCommand( player, cmd, text )
  425. {
  426. if ( cmd == "createobj" || cmd == "obj" )
  427. {
  428. if ( Mapper.Users[ player.ID ] != null ) this.Error("You already have created an object.", player);
  429. else if (!text) this.Sintax("/"+ cmd + " modelo", player)
  430. else
  431. {
  432. Mapper.CreateObject(player, text.tointeger());
  433. }
  434. }
  435.  
  436. else if ( cmd == "save" )
  437. {
  438. if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
  439. else
  440. {
  441. Mapper.SaveObject( player );
  442. }
  443. }
  444.  
  445. else if ( cmd == "copy" )
  446. {
  447. if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
  448. else
  449. {
  450. Mapper.Copy( player );
  451. }
  452. }
  453.  
  454. else if ( cmd == "objdel" )
  455. {
  456. if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
  457. else
  458. {
  459. Mapper.DeleteObject( player );
  460. }
  461. }
  462.  
  463. else if ( cmd == "objselect" )
  464. {
  465. if ( Mapper.Users[ player.ID ] ) this.Error("You already has an object.", player);
  466. else if (!text) this.Error("/objselect mouse/id", player)
  467. else
  468. {
  469. if (text == "mouse") Mapper.Select(player, 1, null);
  470. else if ( !IsNum(text)) this.Error("/objselect mouse/id", player)
  471. else
  472. {
  473. if ( FindObject(text.tointeger()) )
  474. {
  475. if ( Mapper.Users[ player.ID ] && Mapper.Users[ player.ID ].Timer ) ::Timer.Destroy(Mapper.Users[ player.ID ].Timer);
  476. Mapper.Users[ player.ID ] = MapperData();
  477. Mapper.Users[ player.ID ].Player = player;
  478. Mapper.Users[ player.ID ].Object = FindObject(text.tointeger());
  479. this.Information("Object selected correctly.", player);
  480. }
  481. else this.Error("Object not found.", player);
  482. }
  483. }
  484. }
  485.  
  486. else if ( cmd == "mov" )
  487. {
  488. if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
  489. else if (!GetTok( text, " ", 1) || !GetTok( text, " ", 2) || !GetTok( text, " ", 3)) this.Sintax("/mov x/y/z +/- amount")
  490. else
  491. {
  492. local movsign = GetTok( text, " ", 1), sign = GetTok( text, " ", 2), amount = GetTok( text, " ", 3);
  493. Mapper.Mov( player, sign, movsign, amount );
  494. }
  495. }
  496.  
  497. else if ( cmd == "rot" )
  498. {
  499. if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
  500. else if (!GetTok( text, " ", 1) || !GetTok( text, " ", 2) || !GetTok( text, " ", 3)) this.Sintax("/rot x/y/z +/- amount")
  501. else
  502. {
  503. try
  504. {
  505. local rotsign = GetTok( text, " ", 1), sign = GetTok( text, " ", 2), amount = GetTok( text, " ", 3);
  506. Mapper.Rot( player, sign, rotsign, amount );
  507. } catch (e) this.Message(e);
  508. }
  509. }
  510.  
  511. else if ( cmd == "gotomyobj" )
  512. {
  513. if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
  514. else player.Pos = Mapper.Users[ player.ID ].Object.Pos;
  515. }
  516.  
  517.  
  518. else if ( cmd == "objinfo" )
  519. {
  520. if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
  521. else
  522. {
  523. this.Message( Mapper.Users[ player.ID ].Object.Pos + " " + Mapper.Users[ player.ID ].Object.RotationEuler);
  524.  
  525. }
  526. }
  527. }
  528. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement