Jump to content

ZCMD si STRCMP - in acelasi script


M3TrickZz

Recommended Posts

ZCMD + STRCMP

 

Nota:

  • Aceasta metoda nu scade timpul de executie al comenzilor intrucat in continuare se va folosi strcmp pentru a se compara comanda tastata cu comenzile existente in script.
  • O recomand doar in cazul in care doriti sa convertiti comenzile de pe strcmp pe ZCMD, insa nu aveti timp sa le modificati pe toate 'dintr-o lovitura'.
  • Daca considerati ca v-am ajutat, apasati pe +1, sau macar un simplu multumesc.

 

In primul rand, includeti libraria "zcmd" in script-ul dvs.:

#include <zcmd>

Cautati in script-ul dvs. callback-ul "OnPlayerCommandText":

public OnPlayerCommandText(playerid, cmdtext [])

In acest moment, il modificati in "OnPlayerCommandPerformed" si adaugati un ultim parametru, "success":

public OnPlayerCommandPerformed(playerid, cmdtext [], success)

Explicatie:
In momentul in care ZCMD executa o comanda, este apelat callback-ul OnPlayerCommandPerformed() cu parametrul "success = 1" daca acea comanda este ZCMD, sau "success = 0" daca acea comanda NU este ZCMD.

Totodata, va trebui sa adaugati urmatoarea verificare la OnPlayerCommandPerformed ():

 

if (success) return 1;

Explicatie:
In cazul in care comanda executata este ZCMD, nu trebuie sa ne legam de ea, deoarece ne intereseaza comenzile non-ZCMD.
[hr:3r21s1e9][/hr:3r21s1e9]
Daca totul este corect, callback-ul ar trebui sa arate in felul urmator:


 

public OnPlayerCommandPerformed(playerid, cmdtext [], success)
{
    if (success) return 1; // In cazul in care comanda executata este ZCMD, nu se intampla nimic


    // Comenzile dvs: (exemple)
    if (!strcmp (cmdtext, "/test", true, 5)) // Verifica daca a fost tastata comanda "/test"
    {
        SendClientMessage(playerid, -1, "Test!");
        return 1; // Comanda a fost procesata
    }

    if (!strcmp (cmdtext, "/test2", true, 6)) // Verifica daca, comanda executata este "/test2"
    {
        SendClientMessage(playerid, -1, "Test2!");
        return 1; // Comanda a fost procesata
    }

    return 0; // In cazul in care comanda nu se gaseste in script (indiferent daca e ZCMD sau alt procesor de comenzi) trimite mesajul "SERVER: Unknown command."
}

In cazul in care doriti sa fie afisat un mesaj diferit la tastarea unei comenzi inexistente, modificati linia:

return 0;

In:

return SendClientMessage(playerid, -1, "* Comanda tastata nu exista." );
Edited by M3TrickZz
Link to comment
Share on other sites

  • 6 months later...
  • 1 year later...

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.