[Problem] mit Krankenhaussystem

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
  • Hallo Brotfische,

    Ich bin momentan dabei ein Krankenhaussystem zu scripten, also so dass man am nähesten Krankenhaus spawnt, aber leider spawn ich immer nur am gleichen :(


    Codes:


    public OnPlayerSpawn(playerid)
    {
    if(tot[playerid] == 1)
    {
    new
    Float: KrankenhausDistance[8],
    closest = -1,
    Float: tmp_distance = -1.0;


    KrankenhausDistance[0] = GetPlayerDistanceFromPoint(playerid, 2034.1149,-1414.9154,16.9922);
    KrankenhausDistance[1] = GetPlayerDistanceFromPoint(playerid, 1182.1077,-1324.0918,13.5815);
    KrankenhausDistance[2] = GetPlayerDistanceFromPoint(playerid, 1244.3423,331.9934,19.5547);
    KrankenhausDistance[3] = GetPlayerDistanceFromPoint(playerid, 1607.6090,1821.0934,10.8280);
    KrankenhausDistance[4] = GetPlayerDistanceFromPoint(playerid, -317.0090,1056.6217,19.7422);
    KrankenhausDistance[5] = GetPlayerDistanceFromPoint(playerid, -1514.7358,2527.0601,55.7455);
    KrankenhausDistance[6] = GetPlayerDistanceFromPoint(playerid, -2661.2441,633.7098,14.4531);
    KrankenhausDistance[7] = GetPlayerDistanceFromPoint(playerid, -2198.7803,-2306.5793,30.6250);


    for (new i; i != sizeof (HospitalDistance); ++i)
    {
    if (KrankenhausDistance[i] > tmp_distance)
    {
    tmp_distance = KrankenhausDistance[i];
    closest = i;
    }
    }


    // set player's pos
    switch (closest)
    {
    case 0:
    {
    SetPlayerPos(playerid, 2034.1149,-1414.9154,16.9922);
    SetPlayerFacingAngle(playerid, 133.3335);
    tot[playerid] = 0;
    }
    case 1:
    {
    SetPlayerPos(playerid, 1182.1077,-1324.0918,13.5815);
    SetPlayerFacingAngle(playerid, 270.4434);
    tot[playerid] = 0;
    }
    case 2:
    {
    SetPlayerPos(playerid, 1244.3423,331.9934,19.5547);
    SetPlayerFacingAngle(playerid, 335.6859);
    tot[playerid] = 0;
    }
    case 3:
    {
    SetPlayerPos(playerid, 1607.6090,1821.0934,10.8280);
    SetPlayerFacingAngle(playerid, 0.7354);
    tot[playerid] = 0;
    }
    case 4:
    {
    SetPlayerPos(playerid, -317.0090,1056.6217,19.7422);
    SetPlayerFacingAngle(playerid, 358.9579);
    tot[playerid] = 0;
    }
    case 5:
    {
    SetPlayerPos(playerid, -1514.7358,2527.0601,55.7455);
    SetPlayerFacingAngle(playerid, 359.0611);
    tot[playerid] = 0;
    }
    case 6:
    {
    SetPlayerPos(playerid, -2661.2441,633.7098,14.4531);
    SetPlayerFacingAngle(playerid, 180.1544);
    tot[playerid] = 0;
    }
    case 7:
    {
    SetPlayerPos(playerid, -2198.7803,-2306.5793,30.6250);
    SetPlayerFacingAngle(playerid, 320.6338);
    tot[playerid] = 0;
    }
    }
    return 1;
    }
    }


    Ich hoffe es kann mir jemand helfen :D


    MFG German_ScriperHD


    Mit freundlichen Grüßen
    German_ScripterHD

  • Achso, jaaa, das ist klar. Du hast das bei OnPlayerSpawn stehen.
    Du musst die Abfrage auf das nächste Krankenhaus bei OnPlayerDeath machen, das i in einer Spielervariable speichern, und es dann bei OnPlayerSpawn auslesen.


    Oder du machst es so, dass du die Position bei OnPlayerDeath speicherst, und dann bei OnPlayerSpawn die Distanz von dort zu den Krankenhäusern berechnest.

  • public OnPlayerSpawn(playerid)
    {
    if(tot[playerid] == 1)
    {
    // set player's pos
    switch (GetPVarInt(playerid, "i"))
    {
    case 0:
    {
    SetPlayerPos(playerid, 2034.1149,-1414.9154,16.9922);
    SetPlayerFacingAngle(playerid, 133.3335);
    tot[playerid] = 0;
    }
    case 1:
    {
    SetPlayerPos(playerid, 1182.1077,-1324.0918,13.5815);
    SetPlayerFacingAngle(playerid, 270.4434);
    tot[playerid] = 0;
    }
    case 2:
    {
    SetPlayerPos(playerid, 1244.3423,331.9934,19.5547);
    SetPlayerFacingAngle(playerid, 335.6859);
    tot[playerid] = 0;
    }
    case 3:
    {
    SetPlayerPos(playerid, 1607.6090,1821.0934,10.8280);
    SetPlayerFacingAngle(playerid, 0.7354);
    tot[playerid] = 0;
    }
    case 4:
    {
    SetPlayerPos(playerid, -317.0090,1056.6217,19.7422);
    SetPlayerFacingAngle(playerid, 358.9579);
    tot[playerid] = 0;
    }
    case 5:
    {
    SetPlayerPos(playerid, -1514.7358,2527.0601,55.7455);
    SetPlayerFacingAngle(playerid, 359.0611);
    tot[playerid] = 0;
    }
    case 6:
    {
    SetPlayerPos(playerid, -2661.2441,633.7098,14.4531);
    SetPlayerFacingAngle(playerid, 180.1544);
    tot[playerid] = 0;
    }
    case 7:
    {
    SetPlayerPos(playerid, -2198.7803,-2306.5793,30.6250);
    SetPlayerFacingAngle(playerid, 320.6338);
    tot[playerid] = 0;
    }
    }
    return 1;
    }
    return 1;
    }


    Und bei OnPlayerDeath:
    new
    Float: KrankenhausDistance[8],
    closest = -1,
    Float: tmp_distance = 9999999.0;


    KrankenhausDistance[0] = GetPlayerDistanceFromPoint(playerid, 2034.1149,-1414.9154,16.9922);
    KrankenhausDistance[1] = GetPlayerDistanceFromPoint(playerid, 1182.1077,-1324.0918,13.5815);
    KrankenhausDistance[2] = GetPlayerDistanceFromPoint(playerid, 1244.3423,331.9934,19.5547);
    KrankenhausDistance[3] = GetPlayerDistanceFromPoint(playerid, 1607.6090,1821.0934,10.8280);
    KrankenhausDistance[4] = GetPlayerDistanceFromPoint(playerid, -317.0090,1056.6217,19.7422);
    KrankenhausDistance[5] = GetPlayerDistanceFromPoint(playerid, -1514.7358,2527.0601,55.7455);
    KrankenhausDistance[6] = GetPlayerDistanceFromPoint(playerid, -2661.2441,633.7098,14.4531);
    KrankenhausDistance[7] = GetPlayerDistanceFromPoint(playerid, -2198.7803,-2306.5793,30.6250);


    for (new i; i != sizeof (HospitalDistance); ++i)
    {
    if (KrankenhausDistance[i] < tmp_distance)
    {
    tmp_distance = KrankenhausDistance[i];
    closest = i;
    }
    }
    SetPVarInt(playerid, "i", closest);


    Anstatt die PVar kannst du auch die tot-Variable nehmen, aber da ich nicht weiß wie du die sonst noch verwendest habe ich es dir so gemacht, das passt auf jeden Fall.

    3HZXdYd.png

    Einmal editiert, zuletzt von Jeffry ()

  • Ich habe es jetzt so gemacht:

    public OnPlayerSpawn(playerid)
    {
    if(tot[playerid] == 1)
    {
    switch (GetPVarInt(playerid, "i"))
    {
    case 0:
    {
    SetPlayerPos(playerid, 2034.1149,-1414.9154,16.9922);
    SetPlayerFacingAngle(playerid, 133.3335);
    }
    case 1:
    {
    SetPlayerPos(playerid, 1182.1077,-1324.0918,13.5815);
    SetPlayerFacingAngle(playerid, 270.4434);
    }
    case 2:
    {
    SetPlayerPos(playerid, 1244.3423,331.9934,19.5547);
    SetPlayerFacingAngle(playerid, 335.6859);
    }
    case 3:
    {
    SetPlayerPos(playerid, 1607.6090,1821.0934,10.8280);
    SetPlayerFacingAngle(playerid, 0.7354);
    }
    case 4:
    {
    SetPlayerPos(playerid, -317.0090,1056.6217,19.7422);
    SetPlayerFacingAngle(playerid, 358.9579);
    }
    case 5:
    {
    SetPlayerPos(playerid, -1514.7358,2527.0601,55.7455);
    SetPlayerFacingAngle(playerid, 359.0611);
    }
    case 6:
    {
    SetPlayerPos(playerid, -2661.2441,633.7098,14.4531);
    SetPlayerFacingAngle(playerid, 180.1544);
    }
    case 7:
    {
    SetPlayerPos(playerid, -2198.7803,-2306.5793,30.6250);
    SetPlayerFacingAngle(playerid, 320.6338);
    }
    }
    SetPlayerSkin(playerid,sInfo[playerid][skin]);
    tot[playerid] = 0;
    return 1;
    }
    }
    public OnPlayerDeath(playerid, killerid, reason)
    {
    new Float: KrankenhausDistance[8],Float: tmp_distance = 9999999.0;
    KrankenhausDistance[0] = GetPlayerDistanceFromPoint(playerid, 2034.1149,-1414.9154,16.9922);
    KrankenhausDistance[1] = GetPlayerDistanceFromPoint(playerid, 1182.1077,-1324.0918,13.5815);
    KrankenhausDistance[2] = GetPlayerDistanceFromPoint(playerid, 1244.3423,331.9934,19.5547);
    KrankenhausDistance[3] = GetPlayerDistanceFromPoint(playerid, 1607.6090,1821.0934,10.8280);
    KrankenhausDistance[4] = GetPlayerDistanceFromPoint(playerid, -317.0090,1056.6217,19.7422);
    KrankenhausDistance[5] = GetPlayerDistanceFromPoint(playerid, -1514.7358,2527.0601,55.7455);
    KrankenhausDistance[6] = GetPlayerDistanceFromPoint(playerid, -2661.2441,633.7098,14.4531);
    KrankenhausDistance[7] = GetPlayerDistanceFromPoint(playerid, -2198.7803,-2306.5793,30.6250);


    for (new i; i != sizeof (KrankenhausDistance); ++i)
    {
    if (KrankenhausDistance[i] < tmp_distance)
    {
    tmp_distance = KrankenhausDistance[i];

    }
    SetPVarInt(playerid, "i", i);
    }
    tot[playerid] = 1;
    }


    aber ich spawn immer am gleichen Krankenhaus... warum? :(


    Mit freundlichen Grüßen
    German_ScripterHD

  • for (new i; i != sizeof (KrankenhausDistance); ++i)
    {
    if (KrankenhausDistance[i] < tmp_distance)
    {
    tmp_distance = KrankenhausDistance[i];
    SetPVarInt(playerid, "i", i);
    }
    }


    Ich hatte im Beispiel oben das aus Versehen mit i anstatt closest stehen, aber so kann man es auch machen.

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