Motor will nicht angehen...

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 Breadfish,


    wollte mal ein anderes Motorsystem machen, was man per 2 Tasten aktivieren muss, jedoch will er es nicht machen und bleibt hängen,
    obwohl ich keine Errors/Warnings bekomme.


    Hier mal Code:


    if(PRESSED(KEY_SPRINT | KEY_DOWN)&&(IsPlayerInAnyVehicle(playerid))&&(GetPlayerState(playerid)==PLAYER_STATE_DRIVER)){
    new engine,lights,alarm,doors,bonnet,boot,objective;
    new seat;seat = GetPlayerVehicleSeat(playerid);
    new vid = GetPlayerVehicleID(playerid);
    if(seat == 0){
    if(GetVehicleModel(vid) == 510 ||(GetVehicleModel(vid) == 481 ||(GetVehicleModel(vid) == 509))){
    SendClientMessage(playerid,ROT,"FEHLER: Fahrräder haben kein Motor.");
    }else{
    new damageveh=GetPlayerVehicleID(playerid);
    new Float:damagecheck;GetVehicleHealth(damageveh,damagecheck);
    if(damagecheck<299 && damagecheck >249){
    SendClientMessage(playerid,ROT,"Dieses Fahrzeug hat einen Totalschaden.");
    }else{
    GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
    SetVehicleParamsEx(vid,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
    motor[vid] = true;
    }
    }
    }
    }


    Hoffe es kann wer helfen, danke im vorraus.

  • So wird das nix.


    Bedenke:


    Zitat

    How to check for multiple keys
    If you want to check for players HOLDING crouch and fire then the following code will work fine: if ((newkeys & KEY_FIRE) && (newkeys & KEY_CROUCH))
    However if you want to detect when they FIRST press fire and crouch the following code WILL NOT work. It will work if they manage to press the two keys at exactly the same time, but if they're fractionally out (far less than half a second) it won't: if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE) && (newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))
    Why not? Because OnPlayerKeyStateChange is called every time a single key changes. So they press "KEY_FIRE" - OnPlayerKeyStateChange is called with "KEY_FIRE" in "newkeys" and not in "oldkeys", then they press "KEY_CROUCH" - OnPlayerKeyStateChange is called with "KEY_CROUCH" and "KEY_FIRE" in "newkeys", but "KEY_FIRE" is now also in "oldkeys" as it's already been pressed, so "!(oldkeys & KEY_FIRE)" will fail. Fortunately the solution is very simple (in fact simpler than the original code): if ((newkeys & (KEY_FIRE | KEY_CROUCH)) == (KEY_FIRE | KEY_CROUCH) && (oldkeys & (KEY_FIRE | KEY_CROUCH)) != (KEY_FIRE | KEY_CROUCH))
    This may look complicated, but it checks that both keys are set in "newkeys" and that both the keys were not set in "oldkeys", if one of them was set in "oldkeys" that doesn't matter as not both of them were. All these things can be simplified greatly with defines.


    Quelle.


    if(newkeys & bla && newkeys & bla)
    {
    //starte und stoppe motor
    }


    Versuch es mal so aufzubauen.
    Ist jetzt nur ein Beispiel.