Jump to content
  • 0

eroare collect tasta y


Question

Posted

salut, am facut un special quest exact ca in videoclip-ul lui edison. Iar cand apas tasta y sa collectezi giftul nu merge, nu se intampla nimic

am pus in gm

hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
    if(SpecialQuest[playerid]) {
        if(newkeys & KEY_YES) {

 

 

5 answers to this question

Recommended Posts

  • 0
Posted

Probabil prima conditie cu SpecialQuest[playerid] este falsa, dar nu prea imi pot da cu parerea atat timp cat nu oferi mai mult cod. Daca in tutorial merge inseamna ca ai omis ceva.

  • 0
Posted

hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
    if(SpecialQuest[playerid]) {
        if(newkeys == KEY_YES) {
            if(IsPlayerInAnyVehicle(playerid))
            return 1;
            
            new
                Float: x, Float: y, Float: z;

            GetPlayerObjectPos(playerid, quest_objects, x, y, z);

            if(!PlayerToPoint(3.0, playerid, x, y, z))
                return 1;

            PlayerInfo[playerid][quest_objects] ++;
            UpdateVar(playerid, "quest_objects", PlayerInfo[playerid][quest_objects]);

            RemovePlayerMapIcon(playerid, 50);
            DestroyPlayerObject(playerid, questObject[playerid]);

            if(CheckObjects(playerid) == QUEST_OBJECTS) {

                DestroyVehicle(questVehicle[playerid]);
    
                questVehicle[playerid] = 0;
                SpecialQuest[playerid] = 0;

                gString[0] = EOS;
                format(gString, sizeof(gString), "(( Info: %s a terminat Quest-ul Special si a primit un premiu!))", GetName(playerid));
                SendClientMessageToAll(COLOR_CLIENT, gString);

                new
                    rand_money = 20000 + random(10000),
                    rand_rp = 3 + random(3),
                    rand_pp = 3 + random(3);

                GivePlayerMoney(playerid, rand_money);
                PlayerInfo[playerid][pExp] += rand_rp;
                PlayerInfo[playerid][pPremiumPoints] += rand_pp;

                Update(playerid, pCashx);
                Update(playerid, pRP);
                Update(playerid, pPremiumPointsx);


                gString[0] = EOS;
                format(gString, sizeof(gString), "Felicitari! Ai primit: $%s, %d respect points si %d puncte premium.", FormatNumber(rand_money), rand_rp, rand_pp);
                SCM(playerid, COLOR_YELLOW, gString);                
            }
            else set_quest_point(playerid);
        }
    }
    return 1;
}

  • 0
Posted (edited)

Salut @viji,

Cel mai probabil, problema provine de la linia: if(newkeys == KEY_YES)

Forma corecta pentru a verifica daca o tasta este apasata, este aceasta (ex tasta Y): if(newkeys & KEY_YES) (diferenta fiind ca am inlocuit == cu &)

How to NOT to check for a key
Let's presume that you want to detect when a player presses their FIRE button, the obvious code would be:

if (newkeys == KEY_FIRE)
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".

How to check for a key
So, if the variable can contain multiple keys at once, how do you check for just a single one?
The answer is bit masking.
Each key has its own bit in the variable (some keys have the same bit, but they are onfoot/incar keys, so can never be pressed at the same time anyway) and you need to check for just that single bit:

if (newkeys & KEY_FIRE)
Note that the single & is correct - this is a bitwise AND, not a logical AND, which is what the two ampersands are called.

Pentru mai multe detalii, verifica wiki.

Daca totusi, inca intampini probleme, atunci, alte cauze ar fi, cum s-a mentionat si mai sus, variabila 'SpecialQuest' sa fie 0 (false), sau sa nu iti fie detectata pozitia obiectului de la quest. Poti adauga cateva verificari, cum ar fi cateva mesaje de test, atunci cand jucatorul nu se afla langa pozitia obiectului spre exemplu, sa-i returneze un mesaj (return SendClientMessage(playerid, -1, "Nu te afli langa obiect");). Totusi, daca nu ai omis nimic din sistem, mai mult ca sigur, cred ca problema provine de la ce ti-am spus prima data, mai sus.

O dimineata/zi/seara buna!

 

Edited by shane

Daca te-am ajutat =>

spacer.png

  • 0
Posted (edited)
On 2/5/2023 at 1:54 PM, viji said:

hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
    if(SpecialQuest[playerid]) {
        if(newkeys == KEY_YES) {
            if(IsPlayerInAnyVehicle(playerid))
            return 1;
            
            new
                Float: x, Float: y, Float: z;

            GetPlayerObjectPos(playerid, quest_objects, x, y, z);

            if(!PlayerToPoint(3.0, playerid, x, y, z))
                return 1;

            PlayerInfo[playerid][quest_objects] ++;
            UpdateVar(playerid, "quest_objects", PlayerInfo[playerid][quest_objects]);

            RemovePlayerMapIcon(playerid, 50);
            DestroyPlayerObject(playerid, questObject[playerid]);

            if(CheckObjects(playerid) == QUEST_OBJECTS) {

                DestroyVehicle(questVehicle[playerid]);
    
                questVehicle[playerid] = 0;
                SpecialQuest[playerid] = 0;

                gString[0] = EOS;
                format(gString, sizeof(gString), "(( Info: %s a terminat Quest-ul Special si a primit un premiu!))", GetName(playerid));
                SendClientMessageToAll(COLOR_CLIENT, gString);

                new
                    rand_money = 20000 + random(10000),
                    rand_rp = 3 + random(3),
                    rand_pp = 3 + random(3);

                GivePlayerMoney(playerid, rand_money);
                PlayerInfo[playerid][pExp] += rand_rp;
                PlayerInfo[playerid][pPremiumPoints] += rand_pp;

                Update(playerid, pCashx);
                Update(playerid, pRP);
                Update(playerid, pPremiumPointsx);


                gString[0] = EOS;
                format(gString, sizeof(gString), "Felicitari! Ai primit: $%s, %d respect points si %d puncte premium.", FormatNumber(rand_money), rand_rp, rand_pp);
                SCM(playerid, COLOR_YELLOW, gString);                
            }
            else set_quest_point(playerid);
        }
    }
    return 1;
}

ai pus id-ul gresit la obiect la GetPlayerObjectPos, si nu asa se verifica key-urile apasate

Edited by Sancky

Join the conversation

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

Guest
Answer this question...

×   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.