Jump to content

Salut ! Am o intrebare ! Dupa ce id, primeste heal, de ce nu ii ia banii ?


GamerulFOX

Recommended Posts

CMD:heal(playerid, params[])
{
    new id, hp, Float:viata, Float:viata2, string[256], string2[256], name1[MAX_PLAYER_NAME], viata3[MAX_PLAYERS], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(fMedic[playerid] == 0) return SendClientMessage(playerid, 0xff0000FF, "Nu faci parte din factiunea 'Medic' !");
    if(sscanf(params, "ud", id, hp)) return SendClientMessage(playerid, 0x00aeffFF, "/healp <playerid/name> <amount>");
    if(!IsPlayerConnected(id) || id == INVALID_PLAYER_ID) return SCM(playerid, 0xff0000FF, "Acel jucator nu este conectat!");
    GetPlayerName(id, name1, sizeof(name1));
    GetPlayerHealth(id, viata);
    new Float:x, Float:y, Float:z;
    GetPlayerPos(id, x, y, z);
    if(!IsPlayerInRangeOfPoint(playerid, 2.0, x, y, z)) return SendClientMessage(playerid, 0xff0000FF, "Nu esti langa acel player!");
    if(GetPlayerMoney(id) < hp*2) return SendClientMessage(playerid, 0xff0000FF, "Acel jucator nu are suficienti lei, pentru acel hp!");
    viata3[playerid] = GetPlayerHealth(id, viata2);
    if(viata3[playerid] >= 100) return SendClientMessage(playerid, 0xff0000FF, "Acel jucator are deja viata maxima!");
    format(string, sizeof(string), "Iai oferit lui %s %d heal!", name1, hp);
    SendClientMessage(playerid, 0x00aeffFF, string);
    format(string2, sizeof(string2), "Medicul %s ti-a oferit %d heal, iar tu l-ai platit!", name, hp);
    SendClientMessage(id, 0x00aeffFF, string2);
    new pay[MAX_PLAYERS];
    pay[playerid] = hp*3;
    GivePlayerMoney(id, -pay[playerid]);
    GivePlayerMoney(playerid, hp * 2);
    SetPlayerHealth(id, viata+hp);
    return 1;
}

Link to comment
Share on other sites

In primul rand acele array cu MAX_PLAYERS sunt inutile deoarece toate acele variabile pe care le creezi sunt sterse din memorie in momentul in care comanda atinge ultima acolada.

In al doilea rand, functia GetPlayerHealth nu returneaza o valoare ci o paseaza prin referinta ceea ce inseamna ca hp tau corect se afla in variabilele: viata viata2 (udne era necesar doar o singura variabila)

Voiam sa iti repar comanda da codul ala e atat de greu de citit si inteles.

CMD:heal(playerid, params[])
{
    if(fMedic[playerid] == 0) return SendClientMessage(playerid, 0xff0000FF, "Nu faci parte din factiunea 'Medic' !");

    new id, hp;
    if(sscanf(params, "ud", id, hp)) return SendClientMessage(playerid, 0x00aeffFF, "/healp <playerid/name> <amount>");
    if(!IsPlayerConnected(id) || id == INVALID_PLAYER_ID) return SCM(playerid, 0xff0000FF, "Acel jucator nu este conectat!");

    new Float:x, Float:y, Float:z;
    GetPlayerPos(id, x, y, z);
    if(!IsPlayerInRangeOfPoint(playerid, 2.0, x, y, z)) return SendClientMessage(playerid, 0xff0000FF, "Nu esti langa acel player!");
    if(GetPlayerMoney(id) < hp*2) return SendClientMessage(playerid, 0xff0000FF, "Acel jucator nu are suficienti lei, pentru acel hp!");

    new viata;
    GetPlayerHealth(id, viata);
    if(viata >= 100) return SendClientMessage(playerid, 0xff0000FF, "Acel jucator are deja viata maxima!");

    new name[MAX_PLAYER_NAME], name1[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerName(id, name1, sizeof(name1));

    format(string, sizeof(string), "Iai oferit lui %s %d heal!", name1, hp);
    SendClientMessage(playerid, 0x00aeffFF, string);

    format(string2, sizeof(string2), "Medicul %s ti-a oferit %d heal, iar tu l-ai platit!", name, hp);
    SendClientMessage(id, 0x00aeffFF, string2);

    new pay;
    pay = hp*2;

    GivePlayerMoney(id, -pay);
    GivePlayerMoney(playerid, hp * 2);
    SetPlayerHealth(id, viata+hp);

    return 1;
}

Poate asa iti este mai usor sa urmaresti logica comenzi. Am incercat sa separ comanda in pasi mai logici.

Link to comment
Share on other sites

2 hours ago, Banditul said:

In primul rand acele array cu MAX_PLAYERS sunt inutile deoarece toate acele variabile pe care le creezi sunt sterse din memorie in momentul in care comanda atinge ultima acolada.

In al doilea rand, functia GetPlayerHealth nu returneaza o valoare ci o paseaza prin referinta ceea ce inseamna ca hp tau corect se afla in variabilele: viata viata2 (udne era necesar doar o singura variabila)

Voiam sa iti repar comanda da codul ala e atat de greu de citit si inteles.

CMD:heal(playerid, params[])
{
    if(fMedic[playerid] == 0) return SendClientMessage(playerid, 0xff0000FF, "Nu faci parte din factiunea 'Medic' !");

    new id, hp;
    if(sscanf(params, "ud", id, hp)) return SendClientMessage(playerid, 0x00aeffFF, "/healp <playerid/name> <amount>");
    if(!IsPlayerConnected(id) || id == INVALID_PLAYER_ID) return SCM(playerid, 0xff0000FF, "Acel jucator nu este conectat!");

    new Float:x, Float:y, Float:z;
    GetPlayerPos(id, x, y, z);
    if(!IsPlayerInRangeOfPoint(playerid, 2.0, x, y, z)) return SendClientMessage(playerid, 0xff0000FF, "Nu esti langa acel player!");
    if(GetPlayerMoney(id) < hp*2) return SendClientMessage(playerid, 0xff0000FF, "Acel jucator nu are suficienti lei, pentru acel hp!");

    new viata;
    GetPlayerHealth(id, viata);
    if(viata >= 100) return SendClientMessage(playerid, 0xff0000FF, "Acel jucator are deja viata maxima!");

    new name[MAX_PLAYER_NAME], name1[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerName(id, name1, sizeof(name1));

    format(string, sizeof(string), "Iai oferit lui %s %d heal!", name1, hp);
    SendClientMessage(playerid, 0x00aeffFF, string);

    format(string2, sizeof(string2), "Medicul %s ti-a oferit %d heal, iar tu l-ai platit!", name, hp);
    SendClientMessage(id, 0x00aeffFF, string2);

    new pay;
    pay = hp*2;

    GivePlayerMoney(id, -pay);
    GivePlayerMoney(playerid, hp * 2);
    SetPlayerHealth(id, viata+hp);

    return 1;
}

Poate asa iti este mai usor sa urmaresti logica comenzi. Am incercat sa separ comanda in pasi mai logici.

Mersi frumos ! Sunt la inceput si de ieri am inceput sa inteleg unpic sscanf ! 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.