Guest User

Untitled

a guest
Jul 20th, 2011
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.75 KB | None | 0 0
  1. /*  gPositions - Created by Famalamalam - 19/07/2011
  2.  
  3.     gPositions is a feature from my developing game-mode, the
  4.     idea was inspired from GamerX's /l feature. Credits go to:
  5.    
  6.     y_less - sscanf plug-in
  7.     Incognito - Streamer plug-in
  8.     ZeeX - ZCMD
  9.     Creator of Dini
  10.     SA-MP Team
  11.     Myself for creating this awesome shit.
  12.  
  13.     Profile: http://forum.sa-mp.com/member.php?u=126093
  14.  
  15.     All rights reserved. You may edit as needed but you shall not re-release
  16.     this script as your own, or otherwise. Then I'd have to hunt you down
  17.     and kill you..... Just kidding >:D .. or am I?
  18. */
  19.  
  20. // Includes
  21. #include <a_samp>
  22. #include <zcmd>
  23. #include <sscanf2>
  24. #include <streamer>
  25. #include <Dini>
  26.  
  27. // Definitions
  28.  
  29. #define MAX_gPOSITIONS 200
  30. #define gFile_Loc "../gPosition/%i.ini"
  31.  
  32. //Colours and things
  33.  
  34. #define COL_INDIGO         "{8B008B}"
  35. #define Red                 0xFF0000AA
  36. #define White               0xFFFFFFFF
  37. #define AREA_MSG            0xA4A4D2FF
  38.  
  39. // Arrays & Shit
  40.  
  41. new
  42.     gCount,
  43.     gSlots_Left;
  44.  
  45. stock GetgSlotsLeft()
  46. {
  47.     gSlots_Left = MAX_gPOSITIONS - gCount;
  48.     return gSlots_Left;
  49. }
  50.  
  51. enum gPosData
  52. {
  53.     gFileID,
  54.     gInterior,
  55.     gWorld,
  56.     gvAuth,
  57.     gCPID,
  58.     Float:gX,
  59.     Float:gY,
  60.     Float:gZ,
  61.     gName[128],
  62.     Float:gAngle,
  63.     Text3D:g3DLabel
  64. };
  65. new gPosInfo[MAX_gPOSITIONS][gPosData];
  66.  
  67.  
  68. public OnFilterScriptInit()
  69. {
  70.     print("\n--------------------------------------------------------");
  71.     print(" gPositions script is now running - Created by Famalamalam");
  72.     print("---------------------------------------------------------\n");
  73.    
  74.     LoadgPosData();
  75.     return 1;
  76. }
  77.  
  78. public OnFilterScriptExit()
  79. {
  80.     return 1;
  81. }
  82.  
  83. public OnPlayerConnect(playerid)
  84. {
  85.     SendClientMessage(playerid, White, "This server is using gPositions by Famalamalam.");
  86.     SendClientMessage(playerid, White, "Use the command /g for gPositions.");
  87.     return 1;
  88. }
  89.  
  90. CMD:g(playerid, params[])
  91. {
  92.     new string[128], FileID;
  93.     if(!sscanf(params, "d", FileID))
  94.     {
  95.         if(FileID > MAX_gPOSITIONS || FileID < 1) return SendClientMessage(playerid, Red, "The gPosition you entered is out of range.");
  96.         format(string, sizeof(string), gFile_Loc, FileID);
  97.         if(dini_Exists(string))
  98.         {
  99.             if(gPosInfo[FileID][gvAuth] == 1 && IsPlayerInAnyVehicle(playerid))
  100.             {
  101.                 SetVehiclePos(GetPlayerVehicleID(playerid), gPosInfo[FileID][gX], gPosInfo[FileID][gY], gPosInfo[FileID][gZ]);
  102.                 SetVehicleVirtualWorld(GetPlayerVehicleID(playerid), gPosInfo[FileID][gWorld]);
  103.                 SetPlayerVirtualWorld(playerid, gPosInfo[FileID][gWorld]);
  104.                 SetPlayerInterior(playerid, gPosInfo[FileID][gInterior]);
  105.                 LinkVehicleToInterior(GetPlayerVehicleID(playerid), gPosInfo[FileID][gInterior]);
  106.                 GameTextForPlayer(playerid, gPosInfo[FileID][gName], 4000, 4);
  107.                 format(string, sizeof(string), "You have been teleported to %s[%d]", gPosInfo[FileID][gName], FileID);
  108.                 SendClientMessage(playerid, AREA_MSG, string);
  109.             }
  110.             if(gPosInfo[FileID][gvAuth] == 0 && IsPlayerInAnyVehicle(playerid))
  111.             {
  112.                 SetPosAndAngle(playerid, gPosInfo[FileID][gX], gPosInfo[FileID][gY], gPosInfo[FileID][gZ], gPosInfo[FileID][gAngle]);
  113.                 new vID = GetPlayerVehicleID(playerid);
  114.                 RemovePlayerFromVehicle(playerid);
  115.                 SetVehicleToRespawn(vID);
  116.                 SetPlayerVirtualWorld(playerid, gPosInfo[FileID][gWorld]);
  117.                 SetPlayerInterior(playerid, gPosInfo[FileID][gInterior]);
  118.                 GameTextForPlayer(playerid, gPosInfo[FileID][gName], 4000, 4);
  119.                 format(string, sizeof(string), "You have been teleported to %s[%d]", gPosInfo[FileID][gName], FileID);
  120.                 SendClientMessage(playerid, AREA_MSG, string);
  121.             }
  122.             else
  123.             {
  124.                 SetPosAndAngle(playerid, gPosInfo[FileID][gX], gPosInfo[FileID][gY], gPosInfo[FileID][gZ], gPosInfo[FileID][gAngle]);
  125.                 SetPlayerVirtualWorld(playerid, gPosInfo[FileID][gWorld]);
  126.                 SetPlayerInterior(playerid, gPosInfo[FileID][gInterior]);
  127.                 GameTextForPlayer(playerid, gPosInfo[FileID][gName], 4000, 4);
  128.                 format(string, sizeof(string), "You have been teleported to %s[%d]", gPosInfo[FileID][gName], FileID);
  129.                 SendClientMessage(playerid, AREA_MSG, string);
  130.             }
  131.         }
  132.         else
  133.         {
  134.             SendClientMessage(playerid, Red, "That gPosition does not exist, or has not been created yet! [1-200]");
  135.             return 1;
  136.         }
  137.     }
  138.     else
  139.     {
  140.         SendClientMessage(playerid, Red, "USAGE: /g [1-200]");
  141.         return 1;
  142.     }
  143.     return 1;
  144. }
  145.  
  146. CMD:gfillpos(playerid, params[])
  147. {
  148.     new ID, string[128], name[128], vAuth, gID, Float:X, Float:Y, Float:Z, Float:Angle;
  149.     if(IsPlayerAdmin(playerid))
  150.     {
  151.         if(!sscanf(params, "iis[128]",gID, vAuth, name))
  152.         {
  153.             GetPlayerPos(playerid, X, Y, Z);
  154.             GetPlayerFacingAngle(playerid, Angle);
  155.             new pInterior = GetPlayerInterior(playerid);
  156.             new pWorld = GetPlayerVirtualWorld(playerid);
  157.  
  158.             format(string,sizeof(string),gFile_Loc,gID);
  159.             if(!dini_Exists(string))
  160.             {
  161.                 if(vAuth >=0  && vAuth < 2)
  162.                 {
  163.                     dini_Create(string);
  164.                     dini_Set(string, "Name", name);
  165.                     dini_FloatSet(string, "X", X);
  166.                     dini_FloatSet(string, "Y", Y);
  167.                     dini_FloatSet(string, "Z", Z);
  168.                     dini_FloatSet(string, "Angle", Angle);
  169.                     dini_IntSet(string, "Interior", pInterior);
  170.                     dini_IntSet(string, "World", pWorld);
  171.                     dini_IntSet(string, "VehicleAuth", vAuth);
  172.                     format(string, sizeof(string), "Refilled gPosition number %d with name %s. VehicleAuth Status: %d gSlots left: %i", ID, name, vAuth, GetgSlotsLeft());
  173.                     SendClientMessage(playerid, White, string);
  174.                     LoadgPosData();
  175.                 }
  176.                 else
  177.                 {
  178.                     SendClientMessage(playerid, Red, "vAuth - Range between 0 & 1. 0 for no access and 1 for authorized access.");
  179.                 }
  180.             }
  181.             else
  182.             {
  183.                 SendClientMessage(playerid, Red, "ERROR: Selected gPosition is already filled!");
  184.             }
  185.         }
  186.         else
  187.         {
  188.             SendClientMessage(playerid, Red, "USAGE: /gfill [ID 1-200] [vehicles allowed? 0/1] [name]");
  189.         }
  190.     }
  191.     else
  192.     {
  193.         return 0;
  194.     }
  195.     return 1;
  196. }
  197.  
  198. CMD:gcreate(playerid, params[])
  199. {
  200.     new ID, string[128], name[128], vAuth, Float:X, Float:Y, Float:Z, Float:Angle;
  201.     if(IsPlayerAdmin(playerid))
  202.     {
  203.         new FoundID = 0;
  204.  
  205.         if(!sscanf(params, "is[128]", vAuth, name))
  206.         {
  207.             GetPlayerPos(playerid, X, Y, Z);
  208.             GetPlayerFacingAngle(playerid, Angle);
  209.             new pInterior = GetPlayerInterior(playerid);
  210.             new pWorld = GetPlayerVirtualWorld(playerid);
  211.  
  212.             for ( new i = 1; FoundID <= 0 ; i++)
  213.             {
  214.                 format(string,sizeof(string),gFile_Loc,i);
  215.                 if(!dini_Exists(string))
  216.                 {
  217.                     ID = i;
  218.                     FoundID = 1;
  219.                 }
  220.                 if( i > MAX_gPOSITIONS )
  221.                 {
  222.                     return true;
  223.                 }
  224.             }
  225.             if(vAuth >=0  && vAuth < 2)
  226.             {
  227.                 format(string,sizeof(string),gFile_Loc,ID);
  228.                 dini_Create(string);
  229.                 dini_Set(string, "Name", name);
  230.                 dini_FloatSet(string, "X", X);
  231.                 dini_FloatSet(string, "Y", Y);
  232.                 dini_FloatSet(string, "Z", Z);
  233.                 dini_FloatSet(string, "Angle", Angle);
  234.                 dini_IntSet(string, "Interior", pInterior);
  235.                 dini_IntSet(string, "World", pWorld);
  236.                 dini_IntSet(string, "VehicleAuth", vAuth);
  237. /*
  238.                 gPosInfo[ID][gCPID] = CreateDynamicCP(X, Y, Z, 2, pWorld, pInterior, -1, 50);
  239.                 format(string, sizeof(string),"%s\n /g %d",dini_Get(string, "Name"), ID);
  240.                 gPosInfo[ID][g3DLabel] = CreateDynamic3DTextLabel(string, AREA_MSG, X, Y, Z+0.4, 50);
  241.  
  242. */
  243.                 format(string, sizeof(string), "Created gPosition number %d with name %s. Vehicle Auth Status: %d. gSlots left: %i", ID, name, vAuth, GetgSlotsLeft());
  244.                 SendClientMessage(playerid, White, string);
  245.                 LoadgPosData();
  246.             }
  247.             else
  248.             {
  249.                 SendClientMessage(playerid, Red, "vAuth - Range between 0 & 1. 0 for no access and 1 for authorized access.");
  250.             }
  251.         }
  252.         else
  253.         {
  254.             SendClientMessage(playerid, Red, "USAGE: /gcreate [vehicles allowed? 0/1] [name]");
  255.         }
  256.     }
  257.     else
  258.     {
  259.         return 0;
  260.     }
  261.     return 1;
  262. }
  263.  
  264. CMD:gremove(playerid, params[])
  265. {
  266.     if(IsPlayerAdmin(playerid))
  267.     {
  268.         new string[128], gPosID;
  269.         if(!sscanf(params, "i", gPosID))
  270.         {
  271.             if(gPosID > MAX_gPOSITIONS || gPosID < 1) return SendClientMessage(playerid, Red, "The gPosition you entered is out of range.");
  272.             format(string,sizeof(string),gFile_Loc,gPosInfo[gPosID][gFileID]);
  273.             if(dini_Exists(string))
  274.             {
  275.                 dini_Remove(string);
  276.                 if(IsValidDynamicCP(gPosInfo[gPosID][gCPID]))
  277.                 {
  278.                     DestroyDynamicCP(gPosInfo[gPosID][gCPID]); // Destroying exisiting CP's...
  279.                 }
  280.                 if(IsValidDynamic3DTextLabel(gPosInfo[gPosID][g3DLabel]))
  281.                 {
  282.                     DestroyDynamic3DTextLabel(gPosInfo[gPosID][g3DLabel]);
  283.                 }
  284.                 format(string, sizeof(string), ""COL_INDIGO"The gPosition with ID:%i was successfully removed. Don't forget to replace it.", gPosInfo[gPosID][gFileID]);
  285.                 SendClientMessage(playerid, White, string);
  286.                 gCount --;
  287.             }
  288.             else
  289.             {
  290.                 SendClientMessage(playerid, Red, "ERROR: That gPos ID does not exist!");
  291.                 return 1;
  292.             }
  293.         }
  294.         else
  295.         {
  296.             SendClientMessage(playerid, Red, "USAGE: /gremove [1-200]");
  297.         }
  298.     }
  299.     else
  300.     {
  301.         return 0;
  302.     }
  303.     return 1;
  304. }
  305.  
  306. forward LoadgPosData();
  307. public LoadgPosData()
  308. {
  309.     new string[128];
  310.     for(new i = 1; i < MAX_gPOSITIONS; i++)
  311.     {
  312.         format(string,sizeof(string),gFile_Loc,i);
  313.         if(dini_Exists(string))
  314.         {
  315.             if(IsValidDynamicCP(gPosInfo[i][gCPID]))
  316.             {
  317.                 DestroyDynamicCP(gPosInfo[i][gCPID]); // Destroying exisiting CP's...
  318.             }
  319.             if(IsValidDynamic3DTextLabel(gPosInfo[i][g3DLabel]))
  320.             {
  321.                 DestroyDynamic3DTextLabel(gPosInfo[i][g3DLabel]);
  322.             }
  323.             gPosInfo[i][gFileID] = i;
  324.             gPosInfo[i][gWorld] = dini_Int(string, "World");
  325.             gPosInfo[i][gInterior] = dini_Int(string, "Interior");
  326.             gPosInfo[i][gX] = dini_Float(string, "X");
  327.             gPosInfo[i][gY] = dini_Float(string, "Y");
  328.             gPosInfo[i][gZ] = dini_Float(string, "Z");
  329.             gPosInfo[i][gAngle] = dini_Float(string, "Angle");
  330.             gPosInfo[i][gvAuth] = dini_Int(string, "VehicleAccess");
  331.             format(gPosInfo[i][gName], 128, dini_Get(string, "Name"));
  332.             //So we can re-create them without getting doubles ... Hopefully.... O_OCountDynamicMapIcons()
  333.             gPosInfo[i][gCPID] = CreateDynamicCP(gPosInfo[i][gX], gPosInfo[i][gY], gPosInfo[i][gZ], 2, gPosInfo[i][gWorld], gPosInfo[i][gInterior], -1, 50);
  334.             format(string, sizeof(string),"%s\n Use /g %d to teleport here!", gPosInfo[i][gName], i);
  335.             gPosInfo[i][g3DLabel] = CreateDynamic3DTextLabel(string, AREA_MSG, gPosInfo[i][gX], gPosInfo[i][gY], gPosInfo[i][gZ]+0.4, 50);
  336.  
  337.             gCount++;
  338.         }
  339.     }
  340.     printf("\ngPositional Array Loaded. Number of positions: %i \n\nCurrent gPos Limit: %i\n\n gPosition Slots Left: %i", gCount, MAX_gPOSITIONS, GetgSlotsLeft());
  341.     return 1;
  342. }
  343.  
  344. stock SetPosAndAngle(playerid,Float:x,Float:y,Float:z,Float:ang)
  345. {
  346.     SetPlayerPos(playerid, x, y, z);
  347.     SetPlayerFacingAngle(playerid,ang);
  348.     SetCameraBehindPlayer(playerid);
  349. }
Advertisement
Add Comment
Please, Sign In to add comment