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 _MYSQL_HOST "localhost"
- #define _MYSQL_USER "root"
- #define _MYSQL_PASS "root"
- #define _MYSQL_DB "samp"
- #define RADIO_STREAMS_DEBUG 1
- #define DIALOG_CARMENU_RADIO 300
- #define DIALOG_RADIO_ADD_NAME 301
- #define DIALOG_RADIO_ADD_URL 302
- #define DIALOG_RADIO_ADD_CHECK 303
- #define DIALOG_RADIO_MANAGE_LIST 304
- new MySQL_Connection;
- new CarRadio[MAX_VEHICLES],
- CarRadioName[MAX_PLAYERS][32],
- CarRadioURL[MAX_PLAYERS][128];
- stock DB_Connect() {
- #if RADIO_STREAMS_DEBUG == 1
- print("\n[MySQL]: Es wird versucht eine sichere Verbindung zur Datenbank herzustellen...");
- #endif
- MySQL_Connection = mysql_connect(_MYSQL_HOST, _MYSQL_USER, _MYSQL_DB, _MYSQL_PASS);
- #if RADIO_STREAMS_DEBUG == 1
- printf("%s %s %s %s %i", _MYSQL_HOST, _MYSQL_USER, _MYSQL_DB, _MYSQL_PASS, MySQL_Connection);
- #endif
- if(MySQL_Connection) {
- #if RADIO_STREAMS_DEBUG == 1
- print("[MySQL]: Die Verbindung zur Datenbank wurde erfolgreich hergestellt!");
- #endif
- CheckTables();
- return 1;
- }
- #if RADIO_STREAMS_DEBUG == 1
- print("[MySQL]: Es konnte beim ersten Versuch keine Verbindung zur Datenbank hergestellt werden.");
- print("[MySQL]: Es wird Versucht die Verbindung erneut herzustellen");
- #endif
- MySQL_Connection = mysql_connect(_MYSQL_HOST, _MYSQL_USER, _MYSQL_DB, _MYSQL_PASS);
- if(MySQL_Connection) {
- #if RADIO_STREAMS_DEBUG == 1
- print("[MySQL]: Die Verbindung zur Datenbank wurde erfolgreich bem zweiten Versuch hergestellt!");
- #endif
- CheckTables();
- return 1;
- }
- #if RADIO_STREAMS_DEBUG == 1
- print("[MySQL]: Die Verbindung konnte auch im zweiten Versuch nicht hergestellt werden.");
- print("[MySQL]: Der Server beendet sich nun selber.");
- #endif
- SendRconCommand("exit");
- return 1;
- }
- stock CheckTables() {
- mysql_query(MySQL_Connection, "CREATE TABLE IF NOT EXISTS `radiostations` (`id` int(11) NOT NULL AUTO_INCREMENT,`radio_name` text NOT NULL,`radio_url` text NOT NULL,`radio_active` tinyint(1) NOT NULL DEFAULT '1',PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;");
- return 1;
- }
- stock PlayerName(playerid) {
- new Name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
- return Name;
- }
- public OnFilterScriptInit()
- {
- print("\n Radio System von Adrian aka Ch4oS\n");
- DB_Connect();
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- CarRadio[vehicleid] = 0;
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate) {
- new vehicleid = GetPlayerVehicleID(playerid);
- if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) {
- if(CarRadio[vehicleid] != 0) {
- new _query[128];
- format(_query, sizeof _query, "SELECT * FROM radiostations WHERE id='%i' LIMIT 1", CarRadio[vehicleid]);
- mysql_query(MySQL_Connection, _query);
- new _temp[128];
- cache_get_field_content(0, "radio_url", _temp);
- PlayAudioStreamForPlayer(playerid, _temp);
- }
- }
- if(newstate == PLAYER_STATE_ONFOOT) {
- StopAudioStreamForPlayer(playerid);
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- new _query[512], _string[512];
- switch(dialogid) {
- case DIALOG_CARMENU_RADIO: {
- if(response) {
- format(_query, sizeof _query, "SELECT * FROM radiostations WHERE radio_name='%s' LIMIT 1", inputtext);
- mysql_query(MySQL_Connection, _query);
- new _temp[128];
- cache_get_field_content(0, "radio_url", _temp);
- PlayAudioStreamForPlayer(playerid, _temp);
- cache_get_field_content(0, "radio_name", _temp);
- format(_string, sizeof _string, "Du hast den Radiosender auf %s gestellt.", _temp);
- SendClientMessage(playerid, -1, _string);
- CarRadio[GetPlayerVehicleID(playerid)] = cache_get_field_content_int(0, "id");
- } else StopAudioStreamForPlayer(playerid);
- }
- case DIALOG_RADIO_ADD_NAME: {
- if(response) {
- if(!strlen(inputtext) || strlen(inputtext) < 6)return SendClientMessage(playerid, 0xAFAFAFFF, "Der Name ist zu kurz."), ShowPlayerDialog(playerid, DIALOG_RADIO_ADD_NAME, DIALOG_STYLE_INPUT, "Radio hinzufügen", "Gebe den Namen des Radios ein.", "Weiter", "Abbruch");
- if(strlen(inputtext) > 32)return SendClientMessage(playerid, 0xAFAFAFFF, "Der Name ist zu lang."), ShowPlayerDialog(playerid, DIALOG_RADIO_ADD_NAME, DIALOG_STYLE_INPUT, "Radio hinzufügen", "Gebe den Namen des Radios ein.", "Weiter", "Abbruch");
- ShowPlayerDialog(playerid, DIALOG_RADIO_ADD_URL, DIALOG_STYLE_INPUT, "Radio hinzufügen", "Gebe die URL des Radios ein.", "Weiter", "Zurück");
- format(CarRadioName[playerid], 32, "%s", inputtext);
- }
- }
- case DIALOG_RADIO_ADD_URL: {
- if(response) {
- if(!strlen(inputtext) || strlen(inputtext) < 6)return SendClientMessage(playerid, 0xAFAFAFFF, "Die URL ist zu kurz."), ShowPlayerDialog(playerid, DIALOG_RADIO_ADD_URL, DIALOG_STYLE_INPUT, "Radio hinzufügen", "Gebe die URL des Radios ein.", "Weiter", "Zurück");
- if(strlen(inputtext) > 128)return SendClientMessage(playerid, 0xAFAFAFFF, "Die URL ist zu lang."), ShowPlayerDialog(playerid, DIALOG_RADIO_ADD_URL, DIALOG_STYLE_INPUT, "Radio hinzufügen", "Gebe die URL des Radios ein.", "Weiter", "Zurück");
- format(CarRadioURL[playerid], 128, "%s", inputtext);
- format(_string, sizeof _string, "Radio Name: %s\nRadio URL: %s\n\nWollen sie die Radiostation hinzufügen?", CarRadioName[playerid], CarRadioURL[playerid]);
- ShowPlayerDialog(playerid, DIALOG_RADIO_ADD_CHECK, DIALOG_STYLE_INPUT, "Radio hinzufügen", _string, "Ja", "Nein");
- }
- }
- case DIALOG_RADIO_ADD_CHECK: {
- if(response) {
- format(_query, sizeof _query, "INSERT INTO radiostations (`radio_name`, `radio_url`) VALUES ('%s', '%s')", CarRadioName[playerid], CarRadioURL[playerid]);
- mysql_query(MySQL_Connection, _query);
- SendClientMessage(playerid, -1, "Du hast erfolgreich eine Radiostation hinzugefügt.");
- #if RADIO_STREAMS_DEBUG == 1
- printf("[Radio-System]: %s hat einen Radiosender hinzugefügt.", PlayerName(playerid));
- #endif
- }
- }
- case DIALOG_RADIO_MANAGE_LIST: {
- if(response) {
- ShowPlayerDialog(playerid, DIALOG_RADIO_ADD_NAME, DIALOG_STYLE_INPUT, "Radio hinzufügen", "Gebe den Namen des Radios ein.", "Weiter", "Abbruch");
- } else if(!response) {
- new _start, _end;
- _start = strfind(inputtext, "[");
- _end = strfind(inputtext, "]");
- strdel(inputtext, 0, _start+1);
- strdel(inputtext, _end, strlen(inputtext));
- new _id = strval(inputtext);
- format(_query, sizeof _query, "DELETE FROM radiostations WHERE id='%i'", _id);
- mysql_query(MySQL_Connection, _query);
- SendClientMessage(playerid, -1, "Du hast erfolgreich einen Radiosender gelöscht.");
- #if RADIO_STREAMS_DEBUG == 1
- printf("[Radio-System]: %s hat einen Radiosender gelöscht.", PlayerName(playerid));
- #endif
- }
- }
- }
- return 1;
- }
- ocmd:carradio(playerid, params[]) {
- if(GetPlayerVehicleSeat(playerid) != 1 && GetPlayerVehicleSeat(playerid) != 0)return SendClientMessage(playerid, 0xAFAFAFFF, "Du bist kein Fahrer oder Beifahrer eines Fahrzeuges!");
- mysql_query(MySQL_Connection, "SELECT * FROM radiostations WHERE radio_active='1'");
- new _rows, _fields;
- cache_get_data(_rows, _fields);
- if(!_rows)return SendClientMessage(playerid, 0xAFAFAFFF, "Es sind keine Radiosender vorhanden.");
- new _radios, _dstring[1028];
- while(_radios < _rows) {
- new _temp[32];
- cache_get_field_content(_radios, "radio_name", _temp);
- format(_dstring, sizeof _dstring, "%s%s\n", _dstring, _temp);
- _radios++;
- }
- ShowPlayerDialog(playerid, DIALOG_CARMENU_RADIO, DIALOG_STYLE_LIST, "Radiosender", _dstring, "Einschalten", "Ausschalten");
- return 1;
- }
- ocmd:listradios(playerid, params[]) {
- if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, 0xAFAFAFFF, "Du bist kein Administrator.");
- mysql_query(MySQL_Connection, "SELECT * FROM radiostations WHERE radio_active='1'");
- new _rows, _fields;
- cache_get_data(_rows, _fields);
- if(!_rows)return ShowPlayerDialog(playerid, DIALOG_RADIO_MANAGE_LIST, DIALOG_STYLE_LIST, "Radiosender", "Es sind keine Radiosender vorhanden", "Hinzufügen", "");
- new _radios, _dstring[1028];
- while(_radios < _rows) {
- new _temp[32];
- cache_get_field_content(_radios, "radio_name", _temp);
- format(_dstring, sizeof _dstring, "%s[%i] %s\n", cache_get_field_content_int(_radios, "id"), _dstring, _temp);
- _radios++;
- }
- ShowPlayerDialog(playerid, DIALOG_RADIO_MANAGE_LIST, DIALOG_STYLE_LIST, "Radiosender", _dstring, "Hinzufügen", "Löschen");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement