Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MapperData
- {
- Player = null
- Object = null
- SelectingObject = false
- Timer = null
- }
- class ObjectsClass
- {
- ID = null;
- Object = null;
- Model = null;
- PX = null;
- PY = null;
- PZ = null;
- AX = null;
- AY = null;
- AZ = null;
- }
- Mapper <- {
- Users = array( GetMaxPlayers(), null ),
- function LoadSystem()
- {
- 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 )" );
- QuerySQL(OBJ_DB, "CREATE TABLE IF NOT EXISTS Logger ( ID INTEGER, Model INTEGER, Position TEXT, Action TEXT, Mapper TEXT )" );
- Objects <- array( 3001, null );
- ObjectsArray <- array( 3001, null );
- this.LoadObjects();
- print("Mapper System loaded - By Naru^/Maximiliano");
- }
- function LoadObjects()
- {
- local cq = QuerySQL( OBJ_DB, "SELECT COUNT(*) FROM Objects" ), count = GetSQLColumnData( cq, 0 );
- if ( !count )
- {
- print( "Objects Loaded: 0" );
- return false;
- }
- local i = 0;
- local q = QuerySQL( OBJ_DB, "SELECT * FROM Objects" );
- while ( GetSQLColumnData( q, 0 ) != null )
- {
- local ID = GetSQLColumnData( q, 0 );
- this.Objects[ID] = ObjectsClass();
- this.Objects[ID].ID = ID;
- this.Objects[ID].Model = GetSQLColumnData( q, 1 );
- this.Objects[ID].PX = GetSQLColumnData( q, 2 );
- this.Objects[ID].PY = GetSQLColumnData( q, 3 );
- this.Objects[ID].PZ = GetSQLColumnData( q, 4 );
- this.Objects[ID].AX = GetSQLColumnData( q, 5 );
- this.Objects[ID].AY = GetSQLColumnData( q, 6 );
- this.Objects[ID].AZ = GetSQLColumnData( q, 7 );
- local Model = GetSQLColumnData( q, 1 ),
- PX = this.Objects[ID].PX.tofloat(),
- PY = this.Objects[ID].PY.tofloat(),
- PZ = this.Objects[ID].PZ.tofloat(),
- AX = this.Objects[ID].AX.tofloat(),
- AY = this.Objects[ID].AY.tofloat(),
- AZ = this.Objects[ID].AZ.tofloat();
- this.Objects[ID].Object = ::CreateObject( Model, 1, Vector( PX, PY, PZ ), 255 );
- this.Objects[ID].Object.RotateToEuler( Vector( AX, AY, AZ ), 0 );
- this.Objects[ID].Object.TrackingShots = true;
- this.ObjectsArray[ this.Objects[ID].Object.ID ] = ID;
- i++;
- GetSQLNextRow( q );
- }
- FreeSQLQuery( q );
- print( "Objects Loaded: " + i );
- }
- function CreateObject(player, model)
- {
- if ( !this.Users[ player.ID ] )
- {
- this.Users[ player.ID ] = MapperData();
- this.Users[ player.ID ].Player = player;
- this.Users[ player.ID ].Object = ::CreateObject( model.tointeger(), player.World, Vector( player.Pos.x, player.Pos.y, player.Pos.z + 0.5 ), 255 );
- this.Users[ player.ID ].Object.TrackingShots = true;
- this.Information("Object created successfully.", player);
- }
- }
- function DeleteObject( player )
- {
- if ( this.Users[ player.ID ] )
- {
- local obj = this.Users[ player.ID ].Object;
- if ( this.ObjectsArray[ obj.ID ] == null )
- {
- this.Information("Object removed.", player);
- this.Users[ player.ID ].Object.Delete();
- this.Users[ player.ID ] = null;
- }
- else
- {
- local ID = this.ObjectsArray[ obj.ID ];
- if ( this.Objects[ ID ] && this.Objects[ ID ].Object.ID == obj.ID )
- {
- QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + obj.Model + "', '" + obj.Pos + "', 'Delete', '" + player.Name + "' )" );
- QuerySQL( OBJ_DB, "DELETE FROM Objects WHERE ID='" + ID + "'" );
- this.Objects[ID] = null;
- this.Information("Object removed..", player);
- this.ObjectsArray[ obj.ID ] = null;
- this.Users[ player.ID ].Object.Delete();
- this.Users[ player.ID ] = null;
- }
- }
- }
- }
- function SaveObject( player )
- {
- if ( this.Users[ player.ID ] )
- {
- local obj = this.Users[ player.ID ].Object;
- if ( this.ObjectsArray[ obj.ID ] == null )
- {
- local OBJ = this.Users[ player.ID ].Object;
- 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 + "' )" );
- local GetID = QuerySQL( OBJ_DB, "SELECT ID FROM Objects ORDER BY ID DESC LIMIT 1");
- local ID = GetSQLColumnData( GetID, 0 ).tointeger();
- local q = QuerySQL( OBJ_DB, "SELECT * FROM Objects WHERE ID='" + ID + "'" );
- if ( q )
- {
- local ID = GetSQLColumnData( q, 0 );
- this.Objects[ID] = ObjectsClass();
- this.Objects[ID].ID = ID;
- this.Objects[ID].Model = GetSQLColumnData( q, 1 );
- this.Objects[ID].PX = GetSQLColumnData( q, 2 );
- this.Objects[ID].PY = GetSQLColumnData( q, 3 );
- this.Objects[ID].PZ = GetSQLColumnData( q, 4 );
- this.Objects[ID].AX = GetSQLColumnData( q, 5 );
- this.Objects[ID].AY = GetSQLColumnData( q, 6 );
- this.Objects[ID].AZ = GetSQLColumnData( q, 7 );
- local Model = GetSQLColumnData( q, 1 ),
- PX = this.Objects[ID].PX.tofloat(),
- PY = this.Objects[ID].PY.tofloat(),
- PZ = this.Objects[ID].PZ.tofloat(),
- AX = this.Objects[ID].AX.tofloat(),
- AY = this.Objects[ID].AY.tofloat(),
- AZ = this.Objects[ID].AZ.tofloat();
- this.Objects[ID].Object = this.Users[ player.ID ].Object;
- this.Objects[ID].Object.RotateToEuler( Vector( AX, AY, AZ ), 0 );
- this.ObjectsArray[ this.Objects[ID].Object.ID ] = ID;
- this.Users[ player.ID ] = null;
- QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + OBJ.Model + "', '" + OBJ.Pos + "', 'Save', '" + player.Name + "' )" );
- this.Information("Object saved.", player);
- }
- }
- else
- {
- local ID = this.ObjectsArray[ obj.ID ];
- if ( this.Objects[ ID ] && this.Objects[ ID ].Object && this.Objects[ ID ].Object.ID == obj.ID )
- {
- 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 + "'" );
- this.Users[ player.ID ] = null;
- this.Information("Object updated.", player);
- QuerySQL( OBJ_DB, "INSERT INTO Logger ( ID, Model, Position, Action, Mapper ) VALUES ( '" + ID + "', '" + obj.Model + "', '" + obj.Pos + "', 'Update', '" + player.Name + "' )" );
- }
- }
- }
- }
- function Select( player , type, obj)
- {
- switch ( type )
- {
- case 1: //This will put the player in select mode, he can shoot an obj to select it.
- this.Users[ player.ID ] = MapperData();
- this.Users[ player.ID ].SelectingObject = true;
- this.Users[ player.ID ].Timer = ::Timer.Create(this, function(){ Select(player, 2, null);}, 5000, 1);
- this.Information("You have 5 seconds to select the object.", player);
- break;
- case 2: //This cancel the select mode :v
- Timer.Destroy(this.Users[ player.ID ].Timer);
- this.Users[ player.ID ] = null;
- break;
- case 3: //This select the object :v
- if ( this.Users[ player.ID ].Timer ) ::Timer.Destroy(this.Users[ player.ID ].Timer);
- this.Users[ player.ID ] = MapperData();
- this.Users[ player.ID ].Player = player;
- this.Users[ player.ID ].Object = obj;
- this.Information("Object selected correctly.", player);
- break;
- }
- }
- function Copy(player)
- {
- local obj = this.Users[ player.ID ].Object;
- this.SaveObject( player );
- this.Users[ player.ID ] = MapperData();
- this.Users[ player.ID ].Player = player;
- this.Users[ player.ID ].Object = ::CreateObject( obj.Model, player.World, Vector( obj.Pos.x, obj.Pos.y, obj.Pos.z ), 255 );
- this.Users[ player.ID ].Object.RotateTo( obj.Rotation,100);
- this.Users[ player.ID ].Object.TrackingShots = true;
- this.Information("Object copied successfully.", player);
- }
- function Mov( player, sign, movsign, amount ) //sign = +/- , movsign = z,x,y
- {
- if ( this.Users[ player.ID ] )
- {
- local OBJ = this.Users[ player.ID ].Object;
- switch( sign )
- {
- case "+":
- {
- switch ( movsign )
- {
- case "x":
- {
- OBJ.MoveTo( Vector( OBJ.Pos.x + amount.tofloat(), OBJ.Pos.y, OBJ.Pos.z ), 1500 );
- this.Information( "Object Moved...", player );
- }
- break;
- case "y":
- {
- OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y + amount.tofloat(), OBJ.Pos.z ), 1500 );
- this.Information( "Object Moved...", player );
- }
- break;
- case "z":
- {
- OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y, OBJ.Pos.z + amount.tofloat() ), 1500 );
- this.Information( "Object Moved...", player );
- }
- break;
- }
- }
- break;
- case "-":
- {
- switch ( movsign )
- {
- case "x":
- {
- OBJ.MoveTo( Vector( OBJ.Pos.x - amount.tofloat(), OBJ.Pos.y, OBJ.Pos.z ), 1500 );
- this.Information( "Object Moved...", player );
- }
- break;
- case "y":
- {
- OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y - amount.tofloat(), OBJ.Pos.z ), 1500 );
- this.Information( "Object Moved...", player );
- }
- break;
- case "z":
- {
- OBJ.MoveTo( Vector( OBJ.Pos.x , OBJ.Pos.y, OBJ.Pos.z - amount.tofloat() ), 1500 );
- this.Information( "Object Moved...", player );
- }
- break;
- }
- }
- break;
- }
- }
- }
- function Rot( player, sign, rotsign, amount ) //sign = +/- , rotsign = z,x,y
- {
- if ( this.Users[ player.ID ] )
- {
- local OBJ = this.Users[ player.ID ].Object;
- switch( sign )
- {
- case "+":
- {
- switch ( rotsign )
- {
- case "x":
- {
- OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x + amount.tofloat(), OBJ.RotationEuler.y, OBJ.RotationEuler.z ), 1500 );
- this.Information( "Rotated Object...", player );
- }
- break;
- case "y":
- {
- OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y + amount.tofloat(), OBJ.RotationEuler.z ), 1500 );
- this.Information( "Rotated Object...", player );
- }
- break;
- case "z":
- {
- OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y, OBJ.RotationEuler.z + amount.tofloat() ), 1500 );
- this.Information( "Rotated Object...", player );
- }
- break;
- }
- }
- break;
- case "-":
- {
- switch ( rotsign )
- {
- case "x":
- {
- OBJ.RotateToEuler( Vector( (OBJ.RotationEuler.x - amount.tofloat()), OBJ.RotationEuler.y, OBJ.RotationEuler.z ), 1500 );
- this.Information( "Rotated Object...", player );
- }
- break;
- case "y":
- {
- OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, (OBJ.RotationEuler.y - amount.tofloat()), OBJ.RotationEuler.z ), 1500 );
- this.Information( "Rotated Object...", player );
- }
- break;
- case "z":
- {
- OBJ.RotateToEuler( Vector( OBJ.RotationEuler.x, OBJ.RotationEuler.y, (OBJ.RotationEuler.z - amount.tofloat() )), 1500 );
- this.Information( "Rotated Object...", player );
- }
- break;
- }
- }
- break;
- }
- }
- }
- function CountObjects()
- {
- try
- {
- local a = 0, q = QuerySQL( OBJ_DB, "SELECT * FROM Objects" );
- while ( GetSQLColumnData( q, 0 ) )
- {
- a ++;
- GetSQLNextRow( q );
- }
- return a;
- FreeSQLQuery( q );
- } catch(e) print( "[Error] CountObjects - " + e );
- }
- /*
- OTHERS FUNCTIONS
- */
- function Sintax( text, player )
- {
- ::MessagePlayer( "[#FF00FF][SINTAX][#FFFFFF] " + text, player );
- }
- function Error( text, player )
- {
- ::MessagePlayer( "[#FF4500][ERROR][#FF0000] " + text, player );
- }
- function Information( text, player )
- {
- ::MessagePlayer( "[#FF00FF][INFO][#FFFFFF] " + text, player );
- }
- function Message( text )
- {
- ::Message( "[#FFB533][[#FFE633]MAPPER SYSTEM[#FFB533]][#FBFF8A] " + text );
- }
- function onObjectShot(player, object)
- {
- if ( Mapper.Users[ player.ID ] && Mapper.Users[ player.ID ].SelectingObject == true)
- {
- ::Mapper.Select(player, 3, object);
- }
- }
- function onCommand( player, cmd, text )
- {
- if ( cmd == "createobj" || cmd == "obj" )
- {
- if ( Mapper.Users[ player.ID ] != null ) this.Error("You already have created an object.", player);
- else if (!text) this.Sintax("/"+ cmd + " modelo", player)
- else
- {
- Mapper.CreateObject(player, text.tointeger());
- }
- }
- else if ( cmd == "save" )
- {
- if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
- else
- {
- Mapper.SaveObject( player );
- }
- }
- else if ( cmd == "copy" )
- {
- if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
- else
- {
- Mapper.Copy( player );
- }
- }
- else if ( cmd == "objdel" )
- {
- if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
- else
- {
- Mapper.DeleteObject( player );
- }
- }
- else if ( cmd == "objselect" )
- {
- if ( Mapper.Users[ player.ID ] ) this.Error("You already has an object.", player);
- else if (!text) this.Error("/objselect mouse/id", player)
- else
- {
- if (text == "mouse") Mapper.Select(player, 1, null);
- else if ( !IsNum(text)) this.Error("/objselect mouse/id", player)
- else
- {
- if ( FindObject(text.tointeger()) )
- {
- if ( Mapper.Users[ player.ID ] && Mapper.Users[ player.ID ].Timer ) ::Timer.Destroy(Mapper.Users[ player.ID ].Timer);
- Mapper.Users[ player.ID ] = MapperData();
- Mapper.Users[ player.ID ].Player = player;
- Mapper.Users[ player.ID ].Object = FindObject(text.tointeger());
- this.Information("Object selected correctly.", player);
- }
- else this.Error("Object not found.", player);
- }
- }
- }
- else if ( cmd == "mov" )
- {
- if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
- else if (!GetTok( text, " ", 1) || !GetTok( text, " ", 2) || !GetTok( text, " ", 3)) this.Sintax("/mov x/y/z +/- amount")
- else
- {
- local movsign = GetTok( text, " ", 1), sign = GetTok( text, " ", 2), amount = GetTok( text, " ", 3);
- Mapper.Mov( player, sign, movsign, amount );
- }
- }
- else if ( cmd == "rot" )
- {
- if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
- else if (!GetTok( text, " ", 1) || !GetTok( text, " ", 2) || !GetTok( text, " ", 3)) this.Sintax("/rot x/y/z +/- amount")
- else
- {
- try
- {
- local rotsign = GetTok( text, " ", 1), sign = GetTok( text, " ", 2), amount = GetTok( text, " ", 3);
- Mapper.Rot( player, sign, rotsign, amount );
- } catch (e) this.Message(e);
- }
- }
- else if ( cmd == "gotomyobj" )
- {
- if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
- else player.Pos = Mapper.Users[ player.ID ].Object.Pos;
- }
- else if ( cmd == "objinfo" )
- {
- if ( !Mapper.Users[ player.ID ] ) this.Error("You have not created an object.", player);
- else
- {
- this.Message( Mapper.Users[ player.ID ].Object.Pos + " " + Mapper.Users[ player.ID ].Object.RotationEuler);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement