Advertisement
Guest User

Untitled

a guest
Nov 18th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.86 KB | None | 0 0
  1. #include    <a_samp>
  2. #include    <a_mysql>
  3. #include    <ocmd>
  4. #include    <sscanf2>
  5.  
  6. #define     COLOR_WHITE             0xFFFFFFFF
  7. #define     COLOR_YELLOW            0xFFC300FF
  8. #define     COLOR_BLUE              0x0037FFFF
  9. #define     COLOR_GREEN             0x008900FF
  10. #define     COLOR_RED               0xFF000FFF
  11. #define     COLOR_PINK              0xFA00FFFF
  12. #define     COLOR_LIGHTBLUE         0x0091FFFF
  13.  
  14. #define     COLOR_BLUE_HTML         "{0037FF}"
  15. #define     COLOR_RED_HTML          "{FF000F}"
  16. #define     COLOR_GREEN_HTML        "{008900}"
  17. #define     COLOR_YELLOW_HTML       "{FFC300}"
  18. #define     COLOR_PURPLE_HTML       "{653AFF}"
  19. #define     COLOR_LIGHTBLUE_HTML    "{0091FF}"
  20. #define     COLOR_WHITE_HTML        "{FFFFFF}"
  21.  
  22. #define     MAX_PORTS               30
  23.  
  24. #define     Adminrank               GetPVarInt(playerid, "AdminPortRank")
  25.  
  26. enum PortEnum {
  27.     pID,
  28.     pName[15],
  29.     pAdmin,
  30.     Float:pX,
  31.     Float:pY,
  32.     Float:pZ,
  33.     Float:pA,
  34.     pInt
  35. };
  36.  
  37. new Port[MAX_PORTS][PortEnum];
  38.  
  39. stock needAdmin(playerid) {
  40.     return SendClientMessage(playerid, COLOR_RED, "[ Unsuccessful ] "COLOR_WHITE_HTML"Du bist kein Administrator!");
  41. }
  42.  
  43. stock illegalParameters(playerid, parameters[]) {
  44.     new strSCM[128];
  45.     format(strSCM, 128, "[ Unsuccessful ] "COLOR_WHITE_HTML"%s", parameters);
  46.     return SendClientMessage(playerid, COLOR_RED, strSCM);
  47. }
  48.  
  49. stock getMaxPorts() {
  50.     new varCount = 0;
  51.     mysql_query("SELECT * FROM `portStations`");
  52.     mysql_store_result();
  53.     varCount = mysql_num_rows();
  54.     mysql_free_result();
  55.     return varCount;
  56. }
  57.  
  58. stock loadPort(portID) {
  59.     new strQuery[150],
  60.         Result[300];
  61.     format(strQuery, 200, "SELECT * FROM `portStations` WHERE `id` = %d", portID);
  62.     mysql_query(strQuery);
  63.     mysql_store_result();
  64.     mysql_fetch_row(Result);
  65.     if(mysql_num_rows() > 0) {
  66.         sscanf(Result, "p<|>ds[15]dffffd", Port[portID][pID],
  67.                                            Port[portID][pName],
  68.                                            Port[portID][pAdmin],
  69.                                            Port[portID][pX],
  70.                                            Port[portID][pY],
  71.                                            Port[portID][pZ],
  72.                                            Port[portID][pA],
  73.                                            Port[portID][pInt]);
  74.         printf(" Portstation %d geladen!", portID);
  75.     }
  76.     mysql_free_result();
  77. }
  78.  
  79. stock getNearestPort(playerid) {
  80.     for(new p; p <= getMaxPorts(); p++) {
  81.         if(IsPlayerInRangeOfPoint(playerid, 7.0, Port[p][pX], Port[p][pY], Port[p][pZ])) {
  82.             return p;
  83.         }
  84.     }
  85.     return 0;
  86. }
  87.  
  88. stock loadAllPorts() {
  89.     for(new p; p <= getMaxPorts(); p++) {
  90.         loadPort(p);
  91.     }
  92. }
  93.  
  94. stock setNewPort(playerid, portName[], portAdmin) {
  95.     new strQuery[200],
  96.         Float:x,
  97.         Float:y,
  98.         Float:z,
  99.         Float:a;
  100.     GetPlayerPos(playerid, x, y, z);
  101.     GetPlayerFacingAngle(playerid, a);
  102.     format(strQuery, 200, "INSERT INTO `portStations` (`portName`, `portRank`, `portX`, `portY`, `portZ`, `portA`, `portInt`) \
  103.                            VALUES ('%s', %d, '%f', '%f', '%f', '%f', %d)", portName, portAdmin, x, y, z, a, GetPlayerInterior(playerid));
  104.     mysql_query(strQuery);
  105.     loadAllPorts();
  106.     return mysql_errno();
  107. }
  108.  
  109. stock editPortPosition(portID, Float:x, Float:y, Float:z, Float:a, interiorID) {
  110.     new strQuery[400];
  111.     format(strQuery, 400, "UPDATE `portStations` SET `portX` = '%f', `portY` = '%f', `portZ` = '%f', `portA` = '%f', `portInt` = %d WHERE `id` = %d", x, y, z, a, interiorID, portID);
  112.     mysql_query(strQuery);
  113.     return mysql_errno();
  114. }
  115.  
  116. stock editPortAdminLevel(portID, portAdmin) {
  117.     new strQuery[200];
  118.     format(strQuery, 200, "UPDATE `portStations` SET `portRank` = %d WHERE `id` = %d", portAdmin, portID);
  119.     mysql_query(strQuery);
  120.     return mysql_errno();
  121. }
  122.  
  123. stock deletePort(portID) {
  124.     new strQuery[100];
  125.     format(strQuery, 100, "DELETE FROM `portStations` WHERE `id` = %d", portID);
  126.     mysql_query(strQuery);
  127.     return mysql_errno();
  128. }
  129.  
  130. ocmd:setport(playerid, params[]) {
  131.     new PortStationName[15],
  132.         PortStationAdminRank;
  133.     if(!IsPlayerAdmin(playerid))
  134.         return needAdmin(playerid);
  135.     if(sscanf(params, "s[15]d", PortStationName, PortStationAdminRank))
  136.         return illegalParameters(playerid, "/setport [Portname (max. 15 Buchstaben)] [Ab welchem Adminrank]");
  137.     if(!setNewPort(playerid, PortStationName, PortStationAdminRank)) {
  138.         SendClientMessage(playerid, COLOR_GREEN, "[ Successful ] Neuer Port wurde gesetzt!");
  139.     }
  140.     else {
  141.         SendClientMessage(playerid, COLOR_RED, "[ Unsuccessful ] Neuer Port konnte nicht gesetzt werden - überprüfe die Logs!");
  142.     }
  143.     return 1;
  144. }
  145.  
  146. ocmd:ports(playerid, params[]) {
  147.     #pragma unused params
  148.     if(!IsPlayerAdmin(playerid))
  149.         return needAdmin(playerid);
  150.     new strPorts[1000],
  151.         strTeilPort[100];
  152.     for(new p; p <= getMaxPorts(); p++) {
  153.         if(strlen(Port[p][pName]) > 0) {
  154.             format(strTeilPort, 100, "%02d | ab Rank: %d | %s\n", Port[p][pID], Port[p][pAdmin], Port[p][pName]);
  155.             strcat(strPorts, strTeilPort);
  156.         }
  157.     }
  158.     ShowPlayerDialog(playerid, 1337, DIALOG_STYLE_LIST, "Portstationen", strPorts, "Ok", "");
  159.     return 1;
  160. }
  161.  
  162. ocmd:setportadmin(playerid, params[]) {
  163.     new uID,
  164.         aRank;
  165.     if(!IsPlayerAdmin(playerid))
  166.         return needAdmin(playerid);
  167.     if(sscanf(params, "ud", uID, aRank))
  168.         return illegalParameters(playerid, "/setportadmin [playerid] [Rank]");
  169.     SetPVarInt(uID, "AdminPortRank", aRank);
  170.     return 1;
  171. }
  172.  
  173. ocmd:setportstation(playerid, params[]) {
  174.     if(!GetPVarInt(playerid, "portLocationChange"))
  175.         return SendClientMessage(playerid, COLOR_RED, "[ Portsystem ] Du hast keine Portstation ausgewählt!");
  176.     if(Adminrank < Port[GetPVarInt(playerid, "portLocationChange")][pAdmin])
  177.         return needAdmin(playerid);
  178.     new strSCM[128],
  179.         Float:x,
  180.         Float:y,
  181.         Float:z,
  182.         Float:a;
  183.     GetPlayerPos(playerid, x, y, z);
  184.     GetPlayerFacingAngle(playerid, a);
  185.     if(!editPortPosition(GetPVarInt(playerid, "portLocationChange"), x, y, z, a, GetPlayerInterior(playerid))) {
  186.         format(strSCM, 128, "[ Portsystem ] Portstation %s wurde erfolgreich bearbeitet (neue Portposition)!", Port[GetPVarInt(playerid, "portLocationChange")][pName]);
  187.         SendClientMessage(playerid, COLOR_GREEN, strSCM);
  188.         loadPort(GetPVarInt(playerid, "portLocationChange"));
  189.     }
  190.     else {
  191.         SendClientMessage(playerid, COLOR_RED, "[ Portsystem ] Portstation konnte nicht bearbeitet werden - schaue im Log!");
  192.     }
  193.     return 1;
  194. }
  195.    
  196.  
  197. public OnFilterScriptInit()
  198. {
  199.     print("\n [LOADED] Dynamisches Portsystem (von TutNichts)\n");
  200.     for(new p = 1; p <= getMaxPorts(); p++) {
  201.         loadPort(p);
  202.     }
  203.     return 1;
  204. }
  205.  
  206. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  207. {
  208.     if(dialogid == 1337) {
  209.         new portID = (listitem+1),
  210.             strDialog[300];
  211.         if(response) {
  212.             if(Adminrank >= Port[portID][pAdmin]) {
  213.                 format(strDialog, 200, "Zu/zum/zur %s teleportieren\nPortstation - Anforderung erhöhen (derzeit: %d)\nPortstation %s löschen\nPortposition von %s ändern", Port[portID][pName], Port[portID][pAdmin], Port[portID][pName], Port[portID][pName]);
  214.                 ShowPlayerDialog(playerid, (1338 + Port[portID][pID]), DIALOG_STYLE_LIST, Port[portID][pName], strDialog, "Wählen", "Abbruch");
  215.             }
  216.             else {
  217.                 SendClientMessage(playerid, COLOR_RED, "[ Unsuccessful ] "COLOR_WHITE_HTML"Du hast nicht die nötigen Rechte!");
  218.  
  219.             }
  220.         }
  221.     }
  222.    
  223.     if(dialogid > 1337 && dialogid <= (1338 + getMaxPorts())) {
  224.         new strSCM[128],
  225.             portID = (dialogid - 1338);
  226.         if(response) {
  227.             if(listitem == 0) {
  228.                 SetPlayerPos(playerid, Port[portID][pX], Port[portID][pY], Port[portID][pZ]);
  229.                 SetPlayerFacingAngle(playerid, Port[portID][pA]);
  230.                 SetPlayerInterior(playerid, Port[portID][pInt]);
  231.                 format(strSCM, 128, "[ Portsystem ] "COLOR_WHITE_HTML"Du hast dich zur/zum/zu "COLOR_LIGHTBLUE_HTML"%s"COLOR_WHITE_HTML" teleportiert!", Port[portID][pName]);
  232.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, strSCM);
  233.             }
  234.             if(listitem == 1) {
  235.                 ShowPlayerDialog(playerid, (1400 + portID), DIALOG_STYLE_INPUT, Port[portID][pID], "Bitte geben Sie nun ein neues Adminlevel an!", "Ok", "Abbruch");
  236.             }
  237.             if(listitem == 2) {
  238.                 format(strSCM, 128, "[ Portsystem ] "COLOR_WHITE_HTML"Portstation "COLOR_LIGHTBLUE_HTML"%s"COLOR_WHITE_HTML" wurde gelöscht!", Port[portID][pName]);
  239.                 if(!deletePort(portID)) {
  240.                     SendClientMessage(playerid, COLOR_LIGHTBLUE, strSCM);
  241.                     loadAllPorts();
  242.                 }
  243.                 else {
  244.                     SendClientMessage(playerid, COLOR_RED, "[ Portsystem ] "COLOR_WHITE_HTML"Konnte nicht gelöscht werden - schaue im Log!");
  245.                 }
  246.             }
  247.             if(listitem == 3) {
  248.                 SendClientMessage(playerid, COLOR_LIGHTBLUE, "[ Portsystem ] Bitte gehe nun zur neuen Stelle und tippe /setportstation!");
  249.                 SetPVarInt(playerid, "portLocationChange", portID);
  250.             }
  251.         }
  252.     }
  253.    
  254.     if(dialogid > 1400 && dialogid <= (1400 + getMaxPorts())) {
  255.         new portID = (dialogid - 1400),
  256.             strSCM[128];
  257.         if(response) {
  258.             format(strSCM, 128, "[ Portsystem ] "COLOR_WHITE_HTML"Du hast Portstation %s eine neue Anforderung (%d) gesetzt!", Port[portID][pName], strval(inputtext));
  259.             if(!editPortAdminLevel(portID, strval(inputtext))) {
  260.                 SendClientMessage(playerid, COLOR_GREEN, strSCM);
  261.                 loadPort(portID);
  262.             }
  263.             else {
  264.                 SendClientMessage(playerid, COLOR_RED, "[ Portsystem ] "COLOR_WHITE_HTML"Konnte nicht geändert werden - schaue im Log!");
  265.             }
  266.         }
  267.     }
  268.     return 1;
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement