Motor mit Taste starten(problem)

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
  • Hey, ich hab versucht den motor ueber eine Taste starten zu lassen, und zwar nur wenn man die Taste los laesst, jedoch geht der motor immer wieder an & aus wenn man keine andere Taste drueckt


    public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
    {
    if((oldkeys & KEY_ANALOG_DOWN) && !(newkeys & KEY_ANALOG_DOWN))
    {
    new vhd,engine,lights,alarm,doors,bonnet,boot,objective;
    vhd = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vhd,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine == 0 || engine== -1)
    {
    SetVehicleParamsEx(vhd,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
    GameTextForPlayer(playerid,"~w~Motor: ~g~An",1000,4);
    }
    }
    if((oldkeys & KEY_ANALOG_DOWN) && !(newkeys & KEY_ANALOG_DOWN))
    {
    new vhd,engine,lights,alarm,doors,bonnet,boot,objective;
    vhd = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vhd,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine == 1)
    {
    SetVehicleParamsEx(vhd,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
    GameTextForPlayer(playerid,"~w~Motor: ~r~Aus",1000,4);
    }
    }
    return 1;
    }


    xXSeXyBreaDXx -> BREAD. -> [LoG]Bread -> Bread

  • So reicht es eigentlich. Ungetestet, sag einfach Bescheid.
    public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
    {
    if(newkeys == KEY_ANALOG_DOWN)
    {
    new vhd,engine,lights,alarm,doors,bonnet,boot,objective;
    vhd = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vhd,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine == 0 || engine== -1)
    {
    SetVehicleParamsEx(vhd,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
    GameTextForPlayer(playerid,"~w~Motor: ~g~An",1000,4);
    }
    }
    else if(newkeys == KEY_ANALOG_DOWN)
    {
    new vhd,engine,lights,alarm,doors,bonnet,boot,objective;
    vhd = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vhd,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine == 1)
    {
    SetVehicleParamsEx(vhd,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
    GameTextForPlayer(playerid,"~w~Motor: ~r~Aus",1000,4);
    }
    }
    return 1;
    }

  • Zitat

    This code may even work in your testing, but it is wrong and your
    testing is insufficient. Try crouching and pressing fire - your code
    will instantly stop working. Why? Because "newkeys" is no longer the
    same as "KEY_FIRE", it is the same as "KEY_FIRE" COMBINED WITH
    "KEY_CROUCH".

    Aber nicht, wenn du versuchst mehrere Tasten gleichzeitig zu drücken...

  • do.de - Domain-Offensive - Domains für alle und zu super Preisen
  • if(IsPlayerInAnyVehicle(playerid))
    {
    if(newkeys & KEY_ANALOG_DOWN)
    {
    new vhd,engine,lights,alarm,doors,bonnet,boot,objective;
    vhd = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vhd,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine == 0 || engine== -1)
    {
    SetVehicleParamsEx(vhd,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
    GameTextForPlayer(playerid,"~w~Motor: ~g~An",1000,4);
    }
    }
    else if(newkeys & KEY_ANALOG_DOWN)
    {
    new vhd,engine,lights,alarm,doors,bonnet,boot,objective;
    vhd = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vhd,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine == 1)
    {
    SetVehicleParamsEx(vhd,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
    GameTextForPlayer(playerid,"~w~Motor: ~r~Aus",1000,4);
    }
    }
    }


    xXSeXyBreaDXx -> BREAD. -> [LoG]Bread -> Bread


  • bringt was?


    Spoiler anzeigen
    if(IsPlayerInAnyVehicle(playerid))
    {
    if(newkeys & KEY_ANALOG_DOWN)
    {
    new vhd,engine,lights,alarm,doors,bonnet,boot,objective;
    vhd = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vhd,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine == 0 || engine== -1)
    {
    SetVehicleParamsEx(vhd,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
    GameTextForPlayer(playerid,"~w~Motor: ~g~An",1000,4);
    }
    else if(engine == 1)
    {
    SetVehicleParamsEx(vhd,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
    GameTextForPlayer(playerid,"~w~Motor: ~r~Aus",1000,4);
    }
    return 1;
    }
    }


    Viel einfacher :) (Im Expander)


    lg :thumbup:


  • Dein Fehler:


    Du musst engine auf 1 bzw 0 setzen, wenn du den Motor an bzw. aus gemacht hast.

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