Autoradio beim einsteigen Automatisch anmachen

Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Hi leute ich habe es geschaft das wenn man in ein Auto einsteigt, der Radio sender läuft den der zuforige fahrer eingeschalten hat,
    aber wenn ich dan in das Auto einsteige wird der Sender bei jeden auf den Server abgespielt ich habe es mir einer Variable bei
    OnDialogResponse gemacht die Variable ist vehradio[MAX_VEHICLES] bzw. vehradi[vehicleid] = 1; .....
    beim einsteigen wird abgefragt welcher sende und der wird dan abgespielt...


    public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
    {
    for(new i=0; i<MAX_PLAYERS; i++)
    {
    if(vehradio[vehicleid] == 1)
    {
    PlayAudioStreamForPlayer(i, "http://listen.technobase.fm/dsl.pls");
    GameTextForPlayer(i, "~r~Technobase~g~.fm", 1500,3);
    }
    else if(vehradio[vehicleid] == 2)
    {
    PlayAudioStreamForPlayer(i, "http://listen.hardbase.fm/dsl.pls");
    GameTextForPlayer(i, "~r~Hardbase~g~.fm", 1500,3);
    }
    else if(vehradio[vehicleid] == 3)
    {
    PlayAudioStreamForPlayer(i, "http://listen.housetime.fm/dsl.pls");
    GameTextForPlayer(i, "~r~Housetime~g~.fm", 1500,3);
    }
    else if(vehradio[vehicleid] == 4)
    {
    PlayAudioStreamForPlayer(i, "http://listen.trancebase.fm/dsl.pls");
    GameTextForPlayer(i, "~r~Trancebase~g~.fm", 1500,3);
    }
    else if(vehradio[vehicleid] == 5)
    {
    PlayAudioStreamForPlayer(i, "http://listen.coretime.fm/dsl.pls");
    GameTextForPlayer(i, "~r~Coretime~g~.fm", 1500,3);
    }
    else if(vehradio[vehicleid] == 6)
    {
    PlayAudioStreamForPlayer(i, "http://listen.Clubtime.fm/dsl.pls");
    GameTextForPlayer(i, "~r~Clubtime~g~.fm", 1500,3);
    }
    else if(vehradio[vehicleid] == 7)
    {
    PlayAudioStreamForPlayer(i, "http://streams.planetradio.de/planetradio/mp3/hqlivestream.m3u");
    GameTextForPlayer(i, "~r~Planet ~g~Radio", 1500,3);
    }
    else if(vehradio[vehicleid] == 8)
    {
    PlayAudioStreamForPlayer(i, "http://metafiles.gl-systemhaus.de/hr/youfm_2.m3u");//YOU FM LIVE
    GameTextForPlayer(i, "~r~YouFM ~b~Live", 1500,3);
    }
    else if(vehradio[vehicleid] == 9)
    {
    PlayAudioStreamForPlayer(i, "http://metafiles.gl-systemhaus.de/hr/youfm_rock.m3u"); // YOU FM ROCK
    GameTextForPlayer(i, "~r~YouFM ~b~Rock", 1500,3);
    }
    else if(vehradio[vehicleid] == 10)
    {
    PlayAudioStreamForPlayer(i, "http://metafiles.gl-systemhaus.de/hr/youfm_club.m3u"); // YOU FM CLUB
    GameTextForPlayer(i, "~r~YouFM ~b~Club", 1500,3);
    }
    else if(vehradio[vehicleid] == 11)
    {
    PlayAudioStreamForPlayer(i, "http://metafiles.gl-systemhaus.de/hr/youfm_black.m3u"); // YOU FM BLACK
    GameTextForPlayer(i, "~r~YouFM ~b~Black", 1500,3);
    }
    else if(vehradio[vehicleid] == 12)
    {
    PlayAudioStreamForPlayer(i, "http://mp3.89.0rtl.de/listen.pls"); // 89.0 RTL
    GameTextForPlayer(i, "~r~89.0~b~RTL", 1500,3);
    }
    else if(vehradio[vehicleid] == 0)
    {
    GameTextForPlayer(i, "~r~Radio Aus", 1500,3);
    StopAudioStreamForPlayer(i);
    }
    }
    return 1;
    }


    ich hoffe ihr könnt mir helfen wenn ihr aucnoch OnDialogResponse braucht einfach sagen

  • Ich verstehe die Logik deines Codes eh nicht.
    Warum durchgehst du alle Spieler ? So würde es jetzt jeder hören, nimm doch einfach playerid,
    die vom Callback mitgeliefert wird. (außerdem ist hier switch & case mehr empfehlenswert)


    LG

    Main: CPU: Intel Core i5-4440 @ 3,10 GHz | CPU-Cooling: Matterhorn -PURE- | RAM: 16GB Crucial Ballistix Sport DDR3-1600 DIMM CL9-9-9-24 |
    Motherboard: ASRock B85M Pro4 | GPU: Sapphire Radeon R9 390X Nitro 8GB GDDR5 |

    SSD: Samsung SSD 840 Evo 500GB | Power Supply: 550 Watt Corsair CS Series Modular 80+ Gold | Case: beQuiet! Silent Base 800


    As I walk through the valley of the shadow of death
    I take a look at my life and realize there's nothin' left.

  • Ich würde hier eher eine Enumeration verwenden, welche das vehicle, die RadioURL und den Gametext enthält. Bei einer solchen Sache haste auch mit nem switch() noch x mal den selben Code


    Edit: Und lass das MAX_PLAYERS weg - es soll nur für den Spieler aktiviert werden, welcher einsteigt

  • Sorry ich habe noch nie mir Switch und Case gearbeitet nur bei Dialogen könnt ihr mir da etwas helfen?


    switch(vehradio[vehicleid]) {
    case 1: //1.Stream
    case 2: //2.Stream
    //usw
    }

    Main: CPU: Intel Core i5-4440 @ 3,10 GHz | CPU-Cooling: Matterhorn -PURE- | RAM: 16GB Crucial Ballistix Sport DDR3-1600 DIMM CL9-9-9-24 |
    Motherboard: ASRock B85M Pro4 | GPU: Sapphire Radeon R9 390X Nitro 8GB GDDR5 |

    SSD: Samsung SSD 840 Evo 500GB | Power Supply: 550 Watt Corsair CS Series Modular 80+ Gold | Case: beQuiet! Silent Base 800


    As I walk through the valley of the shadow of death
    I take a look at my life and realize there's nothin' left.


  • public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
    {
    switch(vehradio[vehicleid])
    {
    case 0:{
    GameTextForPlayer(playerid, "~r~Radio Aus", 1500,3);
    StopAudioStreamForPlayer(playerid);
    }
    case 1:{
    PlayAudioStreamForPlayer(playerid, "http://listen.technobase.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Technobase~g~.fm", 1500,3);
    }
    case 2:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.hardbase.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Hardbase~g~.fm", 1500,3);
    }
    case 3:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.housetime.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Housetime~g~.fm", 1500,3);
    }
    case 4:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.trancebase.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Trancebase~g~.fm", 1500,3);
    }
    case 5:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.coretime.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Coretime~g~.fm", 1500,3);
    }
    case 6:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.Clubtime.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Clubtime~g~.fm", 1500,3);
    }
    case 7:
    {
    PlayAudioStreamForPlayer(playerid, "http://streams.planetradio.de/planetradio/mp3/hqlivestream.m3u");
    GameTextForPlayer(playerid, "~r~Planet ~g~Radio", 1500,3);
    }
    case 8:
    {
    PlayAudioStreamForPlayer(playerid, "http://metafiles.gl-systemhaus.de/hr/youfm_2.m3u");//YOU FM LIVE
    GameTextForPlayer(playerid, "~r~YouFM ~b~Live", 1500,3);
    }
    case 9:
    {
    PlayAudioStreamForPlayer(playerid, "http://metafiles.gl-systemhaus.de/hr/youfm_rock.m3u"); // YOU FM ROCK
    GameTextForPlayer(playerid, "~r~YouFM ~b~Rock", 1500,3);
    }
    case 10:
    {
    PlayAudioStreamForPlayer(playerid, "http://metafiles.gl-systemhaus.de/hr/youfm_club.m3u"); // YOU FM CLUB
    GameTextForPlayer(playerid, "~r~YouFM ~b~Club", 1500,3);
    }
    case 11:
    {
    PlayAudioStreamForPlayer(playerid, "http://metafiles.gl-systemhaus.de/hr/youfm_black.m3u"); // YOU FM BLACK
    GameTextForPlayer(playerid, "~r~YouFM ~b~Black", 1500,3);
    }
    case 12:
    {
    PlayAudioStreamForPlayer(playerid, "http://mp3.89.0rtl.de/listen.pls"); // 89.0 RTL
    GameTextForPlayer(playerid, "~r~89.0~b~RTL", 1500,3);
    }
    }
    return 1;
    }

  • do.de - Domain-Offensive - Domains für alle und zu super Preisen
  • Hi


    Guck dir das mal an (Hab grad keinen Compiler zur Hand, sollte aber hauen). Viel kürzer als ein if-elseif oder switch Gebilde :)



    new arr_stream[][] =
    {
    {"~r~Technobase.fm~g~", "http://listen.technobase.fm/dsl.pls"},
    {"~r~Hardbase.fm~g~", "http://listen.hardbase.fm/dsl.pls"}
    };


    new vehradio[MAX_VEHICLES];


    public OnGameModeInit()
    {
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
    vehradio[i] = 0; // Wir setzen als Standardstream Technobase
    }
    }


    public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
    {
    new arr_index = vehradio[vehicleid]; // Bestimmen des Radiosenders
    GameTextForPlayer(playerid, arr_stream[arr_index][0], 1500,3);
    PlayAudioStreamForPlayer(playerid, arr_stream[arr_index][1]);
    return 1;
    }

  • Warum sowas verwenden, wenn man eine native Callback hat ? In diesem Callback weisst Du, woher der spieler kam (Zustandsmässig) und wohin er ging(Auch wieder zustandsmässig), also zB:


    Zu Fuss -> Als Fahrer ins Auto (JETZT ist er im Auto)
    Zu Fuss -> Als Beifahrer ins Auto als Beifahrer(JETZTist er im Auto)
    Im Auto -> Aussteigen (JETZT zu Fuss unterwegs)


    JETZT -> Aufruf von OnPlayerStateChange mit newstate und oldtate


    Die States sind hier einsehbar: Klick


    Und jetzt nenn mir einen Grund, warum man noch Timer verwenden sollte - Warum das Rad neu erfinden ;)


    // Edit


  • Ja deine Methode funktioniert natürlich auch..


    €: deine ist sogar genauer, sofern mit den States so gearbeitet wird, wie ich denke..

  • Ich habs nun So:
    forward RadioVehAnAus(playerid,vehicleid);
    public RadioVehAnAus(playerid,vehicleid)
    {
    if(IsPlayerInAnyVehicle(playerid))
    {
    switch(vehradio[vehicleid])
    {
    case 0:{
    GameTextForPlayer(playerid, "~r~Radio Aus", 1500,3);
    StopAudioStreamForPlayer(playerid);
    }
    case 1:{
    PlayAudioStreamForPlayer(playerid, "http://listen.technobase.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Technobase~g~.fm", 1500,3);
    }
    case 2:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.hardbase.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Hardbase~g~.fm", 1500,3);
    }
    case 3:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.housetime.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Housetime~g~.fm", 1500,3);
    }
    case 4:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.trancebase.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Trancebase~g~.fm", 1500,3);
    }
    case 5:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.coretime.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Coretime~g~.fm", 1500,3);
    }
    case 6:
    {
    PlayAudioStreamForPlayer(playerid, "http://listen.Clubtime.fm/dsl.pls");
    GameTextForPlayer(playerid, "~r~Clubtime~g~.fm", 1500,3);
    }
    case 7:
    {
    PlayAudioStreamForPlayer(playerid, "http://streams.planetradio.de/planetradio/mp3/hqlivestream.m3u");
    GameTextForPlayer(playerid, "~r~Planet ~g~Radio", 1500,3);
    }
    case 8:
    {
    PlayAudioStreamForPlayer(playerid, "http://metafiles.gl-systemhaus.de/hr/youfm_2.m3u");//YOU FM LIVE
    GameTextForPlayer(playerid, "~r~YouFM ~b~Live", 1500,3);
    }
    case 9:
    {
    PlayAudioStreamForPlayer(playerid, "http://metafiles.gl-systemhaus.de/hr/youfm_rock.m3u"); // YOU FM ROCK
    GameTextForPlayer(playerid, "~r~YouFM ~b~Rock", 1500,3);
    }
    case 10:
    {
    PlayAudioStreamForPlayer(playerid, "http://metafiles.gl-systemhaus.de/hr/youfm_club.m3u"); // YOU FM CLUB
    GameTextForPlayer(playerid, "~r~YouFM ~b~Club", 1500,3);
    }
    case 11:
    {
    PlayAudioStreamForPlayer(playerid, "http://metafiles.gl-systemhaus.de/hr/youfm_black.m3u"); // YOU FM BLACK
    GameTextForPlayer(playerid, "~r~YouFM ~b~Black", 1500,3);
    }
    case 12:
    {
    PlayAudioStreamForPlayer(playerid, "http://mp3.89.0rtl.de/listen.pls"); // 89.0 RTL
    GameTextForPlayer(playerid, "~r~89.0~b~RTL", 1500,3);
    }
    }
    }
    else
    {
    SetTimer("RadioVehAnAus", 1000, 0);
    }
    return 1;
    }


    Aber jetzt wenn ich einsteige, steht immer da Radio Aus....
    und den Timer bei onplayerentervehicle habe ich auch auf 1 Sec also es soll jede secunde abfragen ob es in einen Auto ist und wenn er in einen ist hört die Timer auf..

    2 Mal editiert, zuletzt von RzZ41 ()

  • do.de - Domain-Offensive - Domains für alle und zu super Preisen