Advertisement
Chaoz

In Game Teleport Maker v2.1

Nov 8th, 2011
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.19 KB | None | 0 0
  1. /*
  2. ||===========Credits============||
  3. ||The_Chaoz Scripting           ||
  4. ||Wheelmandts main idea         ||
  5. ||Y_Less y_ini, sscanf plugin   ||
  6. ||Zeex zcmd                     ||
  7. ||                              ||
  8. ||==============================||*/
  9.  
  10. #include <a_samp>
  11. #include <YSI\y_ini>
  12. #include <sscanf2>
  13. #include <zcmd>
  14.  
  15. #define PUBLIC:%0(%1)   forward %0(%1); public %0(%1)
  16.  
  17. #define MAX_TELEPORTS   (1000)
  18. #define DIALOG_LIST     (9864)
  19.  
  20. //#define HELP//comment this line to disable help on cmds
  21. #define PATH "/TeleportsIG.sav"
  22.  
  23. enum DD{
  24.     bool:Exist=false,
  25.     Float:PP[4],
  26.     Int,
  27.     Vw,
  28.     wCar,
  29.     Priv,
  30.     Name[11],
  31.     Owner[MAX_PLAYER_NAME],
  32.     Frace[55]
  33. };
  34.  
  35. new Tp[MAX_TELEPORTS][DD];
  36. new bool:Full = false;
  37.  
  38. public OnFilterScriptInit()
  39. {
  40.     if(!fexist("/TeleportsIG.sav")){
  41.         new File:Fhnd;
  42.         Fhnd = fopen(PATH, io_write);
  43.         if(Fhnd)fclose(Fhnd);
  44.     }
  45.     for(new i; i<MAX_TELEPORTS; i++)Tp[i][Name] = "a\0\0\0\0\0\0\0\0\0";
  46.     INI_ParseFile(PATH, "LoadTeleports", .bPassTag=true);
  47.     print("\n----------------------------------------");
  48.     print("    In Game Teleport Maker v2.1.0 Loaded");
  49.     return print("----------------------------------------\n");
  50. }
  51.  
  52. public OnFilterScriptExit()
  53. {
  54.     print("\n------------------------------------------");
  55.     print("    In Game Teleport Maker v2.1.0 Unloaded");
  56.     return print("------------------------------------------\n");
  57. }
  58.  
  59. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  60. {
  61.     if(dialogid == DIALOG_LIST && response)return CallLocalFunction("ExecuteTeleport", "si", inputtext, playerid);
  62.     return 0;
  63. }
  64.  
  65. public OnPlayerCommandReceived(playerid, cmdtext[])
  66. {
  67.     if(strcmp(cmdtext, "/tcrear", true, 6) && strcmp(cmdtext, "/tlista", true, 6) && strcmp(cmdtext, "/tborrar", true, 7))
  68.         return CallLocalFunction("ExecuteTeleport", "si", cmdtext[1], playerid);
  69.     return 1;
  70. }
  71.  
  72. public OnPlayerCommandPerformed(playerid, cmdtext[], success)
  73.      return (success) ? (1) : (0);
  74.  
  75. CMD:tcrear(playerid, params[]){
  76.     if(Full)return SendClientMessage(playerid, 0xFF0000FF, "Error: Ya no se pueden crear mas teleports.");
  77.     new name[11], Opt[2], fr[55];
  78.     if(sscanf(params, "s[11]I(0)I(0)S()[55]", name, Opt[0], Opt[1], fr)){
  79.         SendClientMessage(playerid, 0xFFFFFFFF, "Uso: /{FFFF00}tcrear {FFFF00}<nombre> {FFFFFF}(opcional){FFFF00}<auto> {FFFFFF}(opcional){FFFF00}<privado> {FFFFFF}(opcional){FFFF00}<mensaje>");
  80.         #if defined HELP
  81.             SendClientMessage(playerid, 0xFFFF00FF, "Parametros:");
  82.             SendClientMessage(playerid, 0xFFFF00FF, " #Auto: {FFFFFF}permite el teleport con o sin auto ({00FF00}1{FFFFFF}={00FF00}si{FFFFFF}/{FF0000}0{FFFFFF}={FF0000}no).");
  83.             SendClientMessage(playerid, 0xFFFF00FF, " #Privado: {FFFFFF}No figura en la lista del comando tlista({00FF00}1{FFFFFF}={00FF00}privado{FFFFFF}/{FF0000}0{FFFFFF}={FF0000}publico).");
  84.             return SendClientMessage(playerid, 0xFFFF00FF, " #Mensaje: {FFFFFF}se enviara este mensaje cada vez q alguien llegue al teleport.");
  85.         #else
  86.             return 1;
  87.         #endif
  88.     }
  89.     if(strlen(name) < 3)return SendClientMessage(playerid, 0xFF0000FF, "Error: El largo del nombre debe ser mayor a 3 caracteres.");
  90.     new i;
  91.     for(; i<MAX_TELEPORTS; i++)if(!strcmp(Tp[i][Name], name, true) && Tp[i][Exist])return SendClientMessage(playerid, 0xFF0000FF, "Error: El nombre ya ha sido utilizado.");
  92.     for(i=0; i<=MAX_TELEPORTS; i++)if(!Tp[i][Exist])break;
  93.     if(i==MAX_TELEPORTS){
  94.         Full=true;
  95.         if(Tp[i][Exist])return SendClientMessage(playerid, 0xFF0000FF, "Error: Ya no se pueden crear mas teleports.");
  96.     }
  97.     new str[66];
  98.     new INI:Fhnd;
  99.     GetPlayerPos(playerid, Tp[i][PP][0], Tp[i][PP][1], Tp[i][PP][2]);
  100.     GetPlayerFacingAngle(playerid, Tp[i][PP][3]);
  101.     Tp[i][Vw] = GetPlayerVirtualWorld(playerid);
  102.     Tp[i][Int] = GetPlayerInterior(playerid);
  103.     Fhnd = INI_Open(PATH);
  104.     INI_SetTag(Fhnd, numstr(i));
  105.     INI_WriteString(Fhnd, "Name", name);
  106.     INI_WriteString(Fhnd, "Owner", pName(playerid));
  107.     INI_WriteString(Fhnd, "Frace", fr);
  108.     INI_WriteInt(Fhnd, "Car", Opt[0]);
  109.     INI_WriteInt(Fhnd, "Priv", Opt[1]);
  110.     INI_WriteFloat(Fhnd, "X", Tp[i][PP][0]);
  111.     INI_WriteFloat(Fhnd, "Y", Tp[i][PP][1]);
  112.     INI_WriteFloat(Fhnd, "Z", Tp[i][PP][2]);
  113.     INI_WriteFloat(Fhnd, "A", Tp[i][PP][3]);
  114.     INI_WriteInt(Fhnd, "vW", Tp[i][Vw]);
  115.     INI_WriteInt(Fhnd, "Int", Tp[i][Int]);
  116.     INI_Close(Fhnd);
  117.     Tp[i][Exist] = true;
  118.     Tp[i][Name] = name;
  119.     Tp[i][Owner] = pName(playerid);
  120.     Tp[i][Frace] = fr;
  121.     Tp[i][wCar] = Opt[0];
  122.     Tp[i][Priv] = Opt[1];
  123.     format(str, sizeof(str), "Has creado un nuevo teleport, usa \"/%s\" para ir a el.", name);
  124.     return SendClientMessage(playerid, 0xFFFF00FF, str);
  125. }
  126.  
  127. CMD:tlista(playerid, params[]){
  128.     new str[1024], X, bool:first=true;
  129.     for(new i; i<MAX_TELEPORTS; i++)if(Tp[i][Exist] && !Tp[i][Priv]){
  130.         X++;
  131.         if(first){
  132.             format(str, 1024, "%s", Tp[i][Name]);
  133.             first = false;
  134.         }
  135.         else format(str, 1024, "%s\n%s", str, Tp[i][Name]);
  136.     }
  137.     if(X)return ShowPlayerDialog(playerid, DIALOG_LIST, 2, "Teleports List", str, "Select", "Cancel");
  138.     return SendClientMessage(playerid, 0xFFFFFFFF, "--No existen teleports--");
  139. }
  140.  
  141. CMD:tborrar(playerid, params[])
  142. {
  143.     new name[11];
  144.     if(sscanf(params, "s[11]", name))return SendClientMessage(playerid, 0xFFFFFFFF, "Uso: /{FFFF00}tborrar <nombre>");
  145.     new i;
  146.     for(; i<MAX_TELEPORTS; i++)if(!strcmp(Tp[i][Name], name, true))break;
  147.     if(strcmp(Tp[i][Owner], pName(playerid), false) && !IsPlayerAdmin(playerid))return SendClientMessage(playerid, 0xFF0000FF, "Error: No puedes eliminar el teleport");
  148.     if(!Tp[i][Exist])return SendClientMessage(playerid, 0xFF0000FF, "Error: El teleport no existe.");
  149.     DeleteTp(i);
  150.     return SendClientMessage(playerid, 0x00FF00FF, "Server: Teleport borrado con exito.");
  151. }
  152.  
  153. PUBLIC:ExecuteTeleport(name[], forplayer)
  154. {
  155.     new str[128], i;
  156.     for(; i<MAX_TELEPORTS; i++)if(!strcmp(Tp[i][Name], name, true))break;
  157.     if(!Tp[i][Exist])return SendClientMessage(forplayer, 0xFF0000FF, "Error: El teleport no existe.");
  158.     if(!IsPlayerInAnyVehicle(forplayer)){
  159.         SetPlayerPos(forplayer, Tp[i][PP][0], Tp[i][PP][1], Tp[i][PP][2]);
  160.         SetPlayerFacingAngle(forplayer, Tp[i][PP][3]);
  161.         SetPlayerInterior(forplayer, Tp[i][Int]);
  162.         SetPlayerVirtualWorld(forplayer, Tp[i][Vw]);
  163.         SetCameraBehindPlayer(forplayer);
  164.     }
  165.     else{
  166.         if(!Tp[i][wCar]){
  167.             SetPlayerPos(forplayer, Tp[i][PP][0], Tp[i][PP][1], Tp[i][PP][2]);
  168.             SetPlayerFacingAngle(forplayer, Tp[i][PP][3]);
  169.             SetPlayerInterior(forplayer, Tp[i][Int]);
  170.             SetPlayerVirtualWorld(forplayer, Tp[i][Vw]);
  171.             SetCameraBehindPlayer(forplayer);
  172.         }
  173.         else{
  174.             new Veh = GetPlayerVehicleID(forplayer);
  175.             SetVehiclePos(Veh, Tp[i][PP][0], Tp[i][PP][1], Tp[i][PP][2]);
  176.             SetVehicleZAngle(Veh, Tp[i][PP][3]);
  177.             PutPlayerInVehicle(forplayer, Veh, 0);
  178.             SetVehicleVirtualWorld(Veh, Tp[i][Vw]);
  179.             LinkVehicleToInterior(Veh, Tp[i][Int]);
  180.             SetCameraBehindPlayer(forplayer);
  181.         }
  182.     }
  183.     if(!strlen(Tp[i][Frace]))format(str, 128, "Has ido a \"%s\" creado por %s.", Tp[i][Name], Tp[i][Owner]);
  184.     else format(str, 128, "\"%s\" por %s.", Tp[i][Frace], Tp[i][Owner]);
  185.     return SendClientMessage(forplayer, 0xFFFF00FF, str);
  186. }
  187.  
  188. PUBLIC:LoadTeleports(tag[], name[], value[])
  189. {
  190.     new ID=strval(tag);
  191.     Tp[ID][Exist] = true;
  192.     if(!strcmp(name, "Name", true))format(Tp[ID][Name], 11, "%s", value);
  193.     if(!strcmp(name, "Owner", true))format(Tp[ID][Owner], MAX_PLAYER_NAME, "%s", value);
  194.     if(!strcmp(name, "Car", true))Tp[ID][wCar] = strval(value);
  195.     if(!strcmp(name, "Priv", true))Tp[ID][Priv] = strval(value);
  196.     if(!strcmp(name, "X", true))Tp[ID][PP][0] = floatstr(value);
  197.     if(!strcmp(name, "Y", true))Tp[ID][PP][1] = floatstr(value);
  198.     if(!strcmp(name, "Z", true))Tp[ID][PP][2] = floatstr(value);
  199.     if(!strcmp(name, "A", true))Tp[ID][PP][3] = floatstr(value);
  200.     if(!strcmp(name, "Vw", true))Tp[ID][Vw] = strval(value);
  201.     if(!strcmp(name, "Int", true))Tp[ID][Int] = strval(value);
  202.     if(ID==MAX_TELEPORTS)Full = true;
  203. }
  204.  
  205. pName(playerid)
  206. {
  207.     new name[MAX_PLAYER_NAME] = "INVALID PLAYER";
  208.     if(!IsPlayerConnected(playerid))return name;
  209.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  210.     return name;
  211. }
  212.  
  213. DeleteTp(T_id)
  214. {
  215.     Tp[T_id][Exist] = false;
  216.     new INI:Fhnd;
  217.     Fhnd = INI_Open(PATH);
  218.     INI_DeleteTag(Fhnd, numstr(T_id));
  219.     INI_Close(Fhnd);
  220. }
  221.  
  222. numstr(num)
  223. {
  224.     new str[32];
  225.     format(str, sizeof (str), "%d", num);
  226.     return str;
  227. }
  228.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement