Beiträge von Double-O-Seven

    #include <a_samp>


    forward SpeedCheck();
    forward PnP_OnGameModeInit();
    forward PnP_OnPlayerStateChange(playerid,newstate,oldstate);


    #define MAX_CHECKS 3
    #define SPEED_2D


    new Float:LastPos[MAX_PLAYERS][3];
    new PlayerSpeed[MAX_PLAYERS][MAX_CHECKS];
    new PlayerTime[MAX_PLAYERS];
    new Checks[MAX_PLAYERS];
    new StateDriver[MAX_PLAYERS];


    public OnPlayerStateChange(playerid,newstate,oldstate)
    {
    StateDriver[playerid]=(newstate==PLAYER_STATE_DRIVER);
    return PnP_OnPlayerStateChange(playerid,newstate,oldstate);
    }


    public OnGameModeInit()
    {
    SetTimer("SpeedCheck",250,true);
    return PnP_OnGameModeInit();
    }


    public SpeedCheck()
    {
    new Float:pos[3];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
    if(GetPlayerPos(i,pos[0],pos[1],pos[2]))
    {
    if(StateDriver[i])
    {
    Checks[i]++;
    if(Checks[i]==MAX_CHECKS)
    Checks[i]=0;
    #if defined SPEED_2D
    PlayerSpeed[i][Checks[i]]=floatround(floatsqroot((LastPos[i][0]-pos[0])*(LastPos[i][0]-pos[0])+(LastPos[i][1]-pos[1])*(LastPos[i][1]-pos[1]))/float(GetTickCount()-PlayerTime[i])*3600);
    #else
    PlayerSpeed[i][Checks[i]]=floatround(floatsqroot((LastPos[i][0]-pos[0])*(LastPos[i][0]-pos[0])+(LastPos[i][1]-pos[1])*(LastPos[i][1]-pos[1])+(LastPos[i][2]-pos[2])*(LastPos[i][2]-pos[2]))/float(GetTickCount()-PlayerTime[i])*3600);
    #endif
    }
    else
    {
    for(new j=0;j<MAX_CHECKS;j++)
    PlayerSpeed[i][j]=0;
    Checks[i]=0;
    }
    PlayerTime[i]=GetTickCount();
    LastPos[i]=pos;
    }
    }
    return 1;
    }


    stock GetPlayerSpeed(playerid,mph=false)
    {
    new v;
    for(new i=0;i<MAX_CHECKS;i++)
    v+=PlayerSpeed[playerid][i];
    v/=MAX_CHECKS;
    if(mph)
    v=floatround(v/(1.61));
    return v;
    }


    #define OnGameModeInit PnP_OnGameModeInit
    #define OnPlayerStateChange PnP_OnPlayerStateChange


    Mein GetPlayerSpeed-Include.

    Hallo.
    Wenn ich den MTA Race Map Editor installiere, kann ich ihn ganz normal starten. Und auch mappen.
    Wenn ich dann beende und neustarten will kommt immer die Meldung: "Could not load race creator."
    Wieso? :s
    Das ist erst seit kurzem so und ich weiss nicht wieso :S


    Ich muss jedes Mal neu installieren, wenn ich weiter mappen will Dx

    #define MAX_PICKUPS 400
    #define PICKUP_TYPE_WEAPON 1


    new PickupType[MAX_PICKUPS];
    new PickupWeapon[MAX_PICKUPS];
    new PickupAmmo[MAX_PICKUPS];
    new DestroyPickupTimer[MAX_PICKUPS];


    forward DropWeapons(playerid);
    public DropWeapons(playerid)
    {
    if(IsPlayerConnected(playerid))
    {
    #define MAX 300
    new weaponid,ammo,modelid,pickupid;
    new success=false;
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    for(new i=1;i<12;i++)
    {
    GetPlayerWeaponData(playerid,i,weaponid,ammo);
    if(weaponid)
    {
    if(ammo>MAX)
    ammo=MAX;
    modelid=GetWeaponModel(weaponid);
    if(modelid)
    {
    pickupid=CreatePickup(modelid,1,x+(random(10)-random(10)),y+(random(10)-random(10)),z);
    PickupType[pickupid]=PICKUP_TYPE_WEAPON;
    PickupWeapon[pickupid]=weaponid;
    PickupAmmo[pickupid]=ammo;
    DestroyPickupTimer[pickupid]=SetTimerEx("DestroyWeaponPickup",10000+random(1000),false,"i",pickupid);
    success=true;
    }
    }
    }
    ResetPlayerWeapons(playerid);
    #undef MAX
    return success;
    }
    return 0;
    }


    forward DestroyWeaponPickup(pickupid);
    public DestroyWeaponPickup(pickupid)
    {
    if(PickupType[pickupid]==PICKUP_TYPE_WEAPON)
    {
    PickupType[pickupid]=PICKUP_TYPE_NONE;
    PickupWeapon[pickupid]=0;
    PickupAmmo[pickupid]=0;
    DestroyPickup(pickupid);
    return 1;
    }
    return 0;
    }


    stock GetWeaponModel(weaponid)
    {
    switch(weaponid)
    {
    case 1:
    return 331;

    case 2..8:
    return weaponid+331;

    case 9:
    return 341;

    case 10..15:
    return weaponid+311;

    case 16..18:
    return weaponid+326;


    case 22..29:
    return weaponid+324;

    case 30,31:
    return weaponid+325;

    case 32:
    return 372;

    case 33..45:
    return weaponid+324;

    case 46:
    return 371;
    }
    return 0;
    }


    public OnPlayerPickUpPickup(playerid, pickupid)
    {
    switch(PickupType[pickupid])
    {
    case PICKUP_TYPE_WEAPON:
    {
    GivePlayerWeapon(playerid,PickupWeapon[pickupid],PickupAmmo[pickupid]);
    KillTimer(DestroyPickupTimer[pickupid]);
    DestroyWeaponPickup(pickupid);
    }
    }
    return 1;
    }

    #undef MAX_PLAYERS
    #define MAX_PLAYERS 100
    Nach #include <a_samp> ist am einfachsten.

    /say, /kick, /ban etc. mit Grund (strtok benutzt):

    new cmd[32],tmp[32],idx;


    if(!strcmp(cmd,"/kick",true) && IsPlayerAdmin(playerid))
    {
    tmp=strtok(cmdtext,idx);
    new id=strval(tmp); // or ReturnUser(tmp);
    if(!IsPlayerConnected(id) || id==playerid || !cmdtext[idx])
    return SendClientMessage(playerid,0xFF0000FF,"Usage: /KICK <ID> <REASON>");


    new string[128];
    GetPlayerName(id,string,sizeof(string));
    format(string,sizeof(string),"*** %s has been kicked. (Reason: %s)",string,cmdtext[idx]);
    SendClientMessageToAll(0xFF0000FF,string);
    Kick(id);
    return 1;
    }


    new cmd[32],tmp[32],idx;


    if(!strcmp(cmd,"/say",true) && IsPlayerAdmin(playerid))
    {
    if(!cmdtext[idx])
    return SendClientMessage(playerid,0xFF0000FF,"Usage: /SAY <TEXT>");


    new string[128];
    format(string,sizeof(string),"* Admin: %s",cmdtext[idx]);
    SendClientMessageToAll(0x00FF00FF,string);
    Kick(id);
    return 1;
    }
    Anstatt lange Funktionen für Grund zu benutzen, einfach wissen, was der Index bei strtok bewirkt und anwenden. ;)



    Was man auch oft sieht: Überflüssig viele string-Variablen, Beispiel:

    if(!strcmp(cmd,"/me",true))
    {
    if(!cmdtext[idx])
    return SendLanguageMessage(playerid,0xFF0000FF,"Usage: /me <Text>");


    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    new string[128];
    format(string,sizeof(string),"%s %s",name,cmdtext[idx]);
    SendClientMessageToAll(0xFFFF00FF,string);
    return 1;
    }


    Schlecht.



    if(!strcmp(cmd,"/me",true))
    {
    if(!cmdtext[idx])
    return SendLanguageMessage(playerid,0xFF0000FF,"Usage: /me <Text>");


    new string[128];
    GetPlayerName(playerid,string,sizeof(string));
    format(string,sizeof(string),"%s %s",name,cmdtext[idx]);
    SendClientMessageToAll(0xFFFF00FF,string);
    return 1;
    }


    Viel besser.



    Wieso immer GetPlayerName!?
    Anstatt immer den Spielernamen neu zu laden:

    new PlayerName[MAX_PLAYERS][MAX_PLAYER_NAME];
    new PlayerIp[MAX_PLAYERS][16];


    public OnPlayerConnect(playerid)
    {
    GetPlayerName(playerid,PlayerName[playerid],MAX_PLAYER_NAME);
    GetPlayerIp(playerid,PlayerIp[playerid],16);
    //etc.
    return 1;
    }


    Man hat so mehr oder weniger konstante Daten gespeichert in einer Variable, anstatt es immer wieder neu zu laden.
    Falls man SetPlayerName benutzt, formatiert man PlayerName eben neu.

    Wurzel(4)=4^0,5=2
    Wurzel ist das gleiche, wie hoch 0,5

    Das Hochzeichen habe ich schon versucht und dass ^0.5 die Wurzel ist, weiss ich auch.
    Aber wenn ich new var=2^2; printf("%d",var); mache, printet der Server nur 0.
    Das Problem hatte ich schon im englischen Forum gepostet, aber kam auf keine Lösung.


    ---


    #include <a_samp>


    forward SpeedCheck();
    forward PnP_OnGameModeInit();
    forward PnP_OnPlayerStateChange(playerid,newstate,oldstate);


    #define MAX_CHECKS 3


    new Float:LastPos[MAX_PLAYERS][3];
    new PlayerSpeed[MAX_PLAYERS][MAX_CHECKS];
    new PlayerTime[MAX_PLAYERS];
    new Checks[MAX_PLAYERS];
    new StateDriver[MAX_PLAYERS];


    public OnPlayerStateChange(playerid,newstate,oldstate)
    {
    StateDriver[playerid]=(newstate==PLAYER_STATE_DRIVER);
    return PnP_OnPlayerStateChange(playerid,newstate,oldstate);
    }


    public OnGameModeInit()
    {
    SetTimer("SpeedCheck",250,true);
    return PnP_OnGameModeInit();
    }


    public SpeedCheck()
    {
    new Float:pos[3];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
    if(GetPlayerPos(i,pos[0],pos[1],pos[2]))
    {
    if(StateDriver[i])
    {
    Checks[i]++;
    if(Checks[i]==MAX_CHECKS)
    Checks[i]=0;
    PlayerSpeed[i][Checks[i]]=floatround(floatsqroot((LastPos[i][0]-pos[0])*(LastPos[i][0]-pos[0])+(LastPos[i][1]-pos[1])*(LastPos[i][1]-pos[1])+(LastPos[i][2]-pos[2])*(LastPos[i][2]-pos[2]))/float(GetTickCount()-PlayerTime[i])*3600);
    }
    else
    {
    for(new j=0;j<MAX_CHECKS;j++)
    PlayerSpeed[i][j]=0;
    Checks[i]=0;
    }
    PlayerTime[i]=GetTickCount();
    LastPos[i]=pos;
    }
    }
    return 1;
    }


    stock GetPlayerSpeed(playerid,mph=false)
    {
    new v;
    for(new i=0;i<MAX_CHECKS;i++)
    v+=PlayerSpeed[playerid][i];
    v/=MAX_CHECKS;
    if(mph)
    v=floatround(v/(1.61));
    return v;
    }


    #define OnGameModeInit PnP_OnGameModeInit
    #define OnPlayerStateChange PnP_OnPlayerStateChange
    Das ist der Code. Und deshalb laggt der Server ein wenig. Ich musst im SpeedCheck die float...-Funktionen loswerden. Diese führen zu den Laggs Dx

    Guten Abend. Ich habe eine kleine Frage: Ist es möglich die Wurzel zu ziehen, ohne floatsqroot zu benutzen?
    Ich will in meinem Speedometer für die Geschwindigkeit keiten float...-Funktionen benutzen, weil mir gesagt wurde, dass diese laggen - was ich eigentlich auch bestätigen kann: MapIconStreamer laggt, wenn ich Distanzen mit float...-Funktionen berechne.

    Ankündigung:


    Ich werde bald ein Streamer-Paket veröffentlichen, welches folgendes beinhalten wird:

    • Checkpointstreamer (100% fertig)
    • Mapiconstreamer (100% fertig, Full- und Lightversion)
    • Objektstreamer (100% fertig)
    • Vehiclestreamer (80% fertig)
    • Pickupstreamer (0% fertig, wird keine Probleme auf Linux machen

    MfG Double-O-Seven