Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #include <ocmd>
- #include <sscanf2>
- #define COLOR_WHITE 0xFFFFFFFF
- #define COLOR_YELLOW 0xFFC300FF
- #define COLOR_BLUE 0x0037FFFF
- #define COLOR_GREEN 0x008900FF
- #define COLOR_RED 0xFF000FFF
- #define COLOR_PINK 0xFA00FFFF
- #define COLOR_LIGHTBLUE 0x0091FFFF
- #define COLOR_BLUE_HTML "{0037FF}"
- #define COLOR_RED_HTML "{FF000F}"
- #define COLOR_GREEN_HTML "{008900}"
- #define COLOR_YELLOW_HTML "{FFC300}"
- #define COLOR_PURPLE_HTML "{653AFF}"
- #define COLOR_LIGHTBLUE_HTML "{0091FF}"
- #define COLOR_WHITE_HTML "{FFFFFF}"
- #define MAX_PORTS 30
- #define Adminrank GetPVarInt(playerid, "AdminPortRank")
- enum PortEnum {
- pID,
- pName[15],
- pAdmin,
- Float:pX,
- Float:pY,
- Float:pZ,
- Float:pA,
- pInt
- };
- new Port[MAX_PORTS][PortEnum];
- stock needAdmin(playerid) {
- return SendClientMessage(playerid, COLOR_RED, "[ Unsuccessful ] "COLOR_WHITE_HTML"Du bist kein Administrator!");
- }
- stock illegalParameters(playerid, parameters[]) {
- new strSCM[128];
- format(strSCM, 128, "[ Unsuccessful ] "COLOR_WHITE_HTML"%s", parameters);
- return SendClientMessage(playerid, COLOR_RED, strSCM);
- }
- stock getMaxPorts() {
- new varCount = 0;
- mysql_query("SELECT * FROM `portStations`");
- mysql_store_result();
- varCount = mysql_num_rows();
- mysql_free_result();
- return varCount;
- }
- stock loadPort(portID) {
- new strQuery[150],
- Result[300];
- format(strQuery, 200, "SELECT * FROM `portStations` WHERE `id` = %d", portID);
- mysql_query(strQuery);
- mysql_store_result();
- mysql_fetch_row(Result);
- if(mysql_num_rows() > 0) {
- sscanf(Result, "p<|>ds[15]dffffd", Port[portID][pID],
- Port[portID][pName],
- Port[portID][pAdmin],
- Port[portID][pX],
- Port[portID][pY],
- Port[portID][pZ],
- Port[portID][pA],
- Port[portID][pInt]);
- printf(" Portstation %d geladen!", portID);
- }
- mysql_free_result();
- }
- stock getNearestPort(playerid) {
- for(new p; p <= getMaxPorts(); p++) {
- if(IsPlayerInRangeOfPoint(playerid, 7.0, Port[p][pX], Port[p][pY], Port[p][pZ])) {
- return p;
- }
- }
- return 0;
- }
- stock loadAllPorts() {
- for(new p; p <= getMaxPorts(); p++) {
- loadPort(p);
- }
- }
- stock setNewPort(playerid, portName[], portAdmin) {
- new strQuery[200],
- Float:x,
- Float:y,
- Float:z,
- Float:a;
- GetPlayerPos(playerid, x, y, z);
- GetPlayerFacingAngle(playerid, a);
- format(strQuery, 200, "INSERT INTO `portStations` (`portName`, `portRank`, `portX`, `portY`, `portZ`, `portA`, `portInt`) \
- VALUES ('%s', %d, '%f', '%f', '%f', '%f', %d)", portName, portAdmin, x, y, z, a, GetPlayerInterior(playerid));
- mysql_query(strQuery);
- loadAllPorts();
- return mysql_errno();
- }
- stock editPortPosition(portID, Float:x, Float:y, Float:z, Float:a, interiorID) {
- new strQuery[400];
- 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);
- mysql_query(strQuery);
- return mysql_errno();
- }
- stock editPortAdminLevel(portID, portAdmin) {
- new strQuery[200];
- format(strQuery, 200, "UPDATE `portStations` SET `portRank` = %d WHERE `id` = %d", portAdmin, portID);
- mysql_query(strQuery);
- return mysql_errno();
- }
- stock deletePort(portID) {
- new strQuery[100];
- format(strQuery, 100, "DELETE FROM `portStations` WHERE `id` = %d", portID);
- mysql_query(strQuery);
- return mysql_errno();
- }
- ocmd:setport(playerid, params[]) {
- new PortStationName[15],
- PortStationAdminRank;
- if(!IsPlayerAdmin(playerid))
- return needAdmin(playerid);
- if(sscanf(params, "s[15]d", PortStationName, PortStationAdminRank))
- return illegalParameters(playerid, "/setport [Portname (max. 15 Buchstaben)] [Ab welchem Adminrank]");
- if(!setNewPort(playerid, PortStationName, PortStationAdminRank)) {
- SendClientMessage(playerid, COLOR_GREEN, "[ Successful ] Neuer Port wurde gesetzt!");
- }
- else {
- SendClientMessage(playerid, COLOR_RED, "[ Unsuccessful ] Neuer Port konnte nicht gesetzt werden - überprüfe die Logs!");
- }
- return 1;
- }
- ocmd:ports(playerid, params[]) {
- #pragma unused params
- if(!IsPlayerAdmin(playerid))
- return needAdmin(playerid);
- new strPorts[1000],
- strTeilPort[100];
- for(new p; p <= getMaxPorts(); p++) {
- if(strlen(Port[p][pName]) > 0) {
- format(strTeilPort, 100, "%02d | ab Rank: %d | %s\n", Port[p][pID], Port[p][pAdmin], Port[p][pName]);
- strcat(strPorts, strTeilPort);
- }
- }
- ShowPlayerDialog(playerid, 1337, DIALOG_STYLE_LIST, "Portstationen", strPorts, "Ok", "");
- return 1;
- }
- ocmd:setportadmin(playerid, params[]) {
- new uID,
- aRank;
- if(!IsPlayerAdmin(playerid))
- return needAdmin(playerid);
- if(sscanf(params, "ud", uID, aRank))
- return illegalParameters(playerid, "/setportadmin [playerid] [Rank]");
- SetPVarInt(uID, "AdminPortRank", aRank);
- return 1;
- }
- ocmd:setportstation(playerid, params[]) {
- if(!GetPVarInt(playerid, "portLocationChange"))
- return SendClientMessage(playerid, COLOR_RED, "[ Portsystem ] Du hast keine Portstation ausgewählt!");
- if(Adminrank < Port[GetPVarInt(playerid, "portLocationChange")][pAdmin])
- return needAdmin(playerid);
- new strSCM[128],
- Float:x,
- Float:y,
- Float:z,
- Float:a;
- GetPlayerPos(playerid, x, y, z);
- GetPlayerFacingAngle(playerid, a);
- if(!editPortPosition(GetPVarInt(playerid, "portLocationChange"), x, y, z, a, GetPlayerInterior(playerid))) {
- format(strSCM, 128, "[ Portsystem ] Portstation %s wurde erfolgreich bearbeitet (neue Portposition)!", Port[GetPVarInt(playerid, "portLocationChange")][pName]);
- SendClientMessage(playerid, COLOR_GREEN, strSCM);
- loadPort(GetPVarInt(playerid, "portLocationChange"));
- }
- else {
- SendClientMessage(playerid, COLOR_RED, "[ Portsystem ] Portstation konnte nicht bearbeitet werden - schaue im Log!");
- }
- return 1;
- }
- public OnFilterScriptInit()
- {
- print("\n [LOADED] Dynamisches Portsystem (von TutNichts)\n");
- for(new p = 1; p <= getMaxPorts(); p++) {
- loadPort(p);
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == 1337) {
- new portID = (listitem+1),
- strDialog[300];
- if(response) {
- if(Adminrank >= Port[portID][pAdmin]) {
- 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]);
- ShowPlayerDialog(playerid, (1338 + Port[portID][pID]), DIALOG_STYLE_LIST, Port[portID][pName], strDialog, "Wählen", "Abbruch");
- }
- else {
- SendClientMessage(playerid, COLOR_RED, "[ Unsuccessful ] "COLOR_WHITE_HTML"Du hast nicht die nötigen Rechte!");
- }
- }
- }
- if(dialogid > 1337 && dialogid <= (1338 + getMaxPorts())) {
- new strSCM[128],
- portID = (dialogid - 1338);
- if(response) {
- if(listitem == 0) {
- SetPlayerPos(playerid, Port[portID][pX], Port[portID][pY], Port[portID][pZ]);
- SetPlayerFacingAngle(playerid, Port[portID][pA]);
- SetPlayerInterior(playerid, Port[portID][pInt]);
- format(strSCM, 128, "[ Portsystem ] "COLOR_WHITE_HTML"Du hast dich zur/zum/zu "COLOR_LIGHTBLUE_HTML"%s"COLOR_WHITE_HTML" teleportiert!", Port[portID][pName]);
- SendClientMessage(playerid, COLOR_LIGHTBLUE, strSCM);
- }
- if(listitem == 1) {
- ShowPlayerDialog(playerid, (1400 + portID), DIALOG_STYLE_INPUT, Port[portID][pID], "Bitte geben Sie nun ein neues Adminlevel an!", "Ok", "Abbruch");
- }
- if(listitem == 2) {
- format(strSCM, 128, "[ Portsystem ] "COLOR_WHITE_HTML"Portstation "COLOR_LIGHTBLUE_HTML"%s"COLOR_WHITE_HTML" wurde gelöscht!", Port[portID][pName]);
- if(!deletePort(portID)) {
- SendClientMessage(playerid, COLOR_LIGHTBLUE, strSCM);
- loadAllPorts();
- }
- else {
- SendClientMessage(playerid, COLOR_RED, "[ Portsystem ] "COLOR_WHITE_HTML"Konnte nicht gelöscht werden - schaue im Log!");
- }
- }
- if(listitem == 3) {
- SendClientMessage(playerid, COLOR_LIGHTBLUE, "[ Portsystem ] Bitte gehe nun zur neuen Stelle und tippe /setportstation!");
- SetPVarInt(playerid, "portLocationChange", portID);
- }
- }
- }
- if(dialogid > 1400 && dialogid <= (1400 + getMaxPorts())) {
- new portID = (dialogid - 1400),
- strSCM[128];
- if(response) {
- format(strSCM, 128, "[ Portsystem ] "COLOR_WHITE_HTML"Du hast Portstation %s eine neue Anforderung (%d) gesetzt!", Port[portID][pName], strval(inputtext));
- if(!editPortAdminLevel(portID, strval(inputtext))) {
- SendClientMessage(playerid, COLOR_GREEN, strSCM);
- loadPort(portID);
- }
- else {
- SendClientMessage(playerid, COLOR_RED, "[ Portsystem ] "COLOR_WHITE_HTML"Konnte nicht geändert werden - schaue im Log!");
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement