Enum Information returns C?
#21

Quote:
Originally Posted by knackworst
Посмотреть сообщение
O.o
Now that's what I call professional structure...
I do not fully understand lol

um, the string variable is under the commandtext callback
There is nothing professional in that :/
It is just sad that I always see in "/admin" commands a count variable which is totally unnecessary

pawn Код:
// indentation
    if(strcmp("/mission", cmdtext, true, 8) == 0) { // command
        // the string variable must be empty
        new
            i = 0, // loop variable
            type = strval(cmdtext[8]); // number behind "/mission"
        for( ; i != sizeof Mission; ++i) { // loop through the array
            if(Mission[i][mission_type] == type) { // check if the type match
                format(string, sizeof string, "Mission: \"%s\" Person: \"%s\"", Mission[i][mission_name], Mission[i][person_name]);
                SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
            }
        }
        if(string[0]) { // if the string isnt empty, format was used which means that the type got found
            return true; // if found we stop here, if not maybe some other command like "/missions" get executed
        }
    }
To make that work we need to avoid the mission number 0 because strval would return 0 if there isnt a number like in "/missions" the "s"

Also make your array constant
pawn Код:
new const Mission[6][DMissions] =
Reply
#22

ah, it works thanks alot
and I understand it now
but 2 things I never understood in this code...
why using strval(cmdtext
if u can also use dcmd and scanff?
I see the professional writers using strval
and the more beginners using DCMD
I don't get why we don't always use scanff since its very easy to work with and not that hard to see what's going on : )
and also I don't really see where u made it that there will be a Clientmessage created for each mission.
its something I find very usefull but I don't see where in the code it makes that there will be created 1 message for 1 mission info...

anyways, thanks alot
and rep plus = )
Reply
#23

Quote:
Originally Posted by knackworst
Посмотреть сообщение
why using strval(cmdtext
I usually avoid sscanf it if it is not necessary, I am not sure if strval would be faster in this one

Quote:
Originally Posted by knackworst
Посмотреть сообщение
if u can also use dcmd and scanff?
this command wouldnt work with dcmd or zcmd as it doesnt use any space between command and parameter
sure you could use sscanf for that but I only use it for two parameter or more

Quote:
Originally Posted by knackworst
Посмотреть сообщение
and also I don't really see where u made it that there will be a Clientmessage created for each mission.
its something I find very usefull but I don't see where in the code it makes that there will be created 1 message for 1 mission info...
the loop gets executed for each index of the array, if you would hardcode that loop it would look like that

pawn Код:
if(Mission[0][mission_type] == type) {
    format(string, sizeof string, "Mission: \"%s\" Person: \"%s\"", Mission[0][mission_name], Mission[0][person_name]);
    SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
}
if(Mission[1][mission_type] == type) {
    format(string, sizeof string, "Mission: \"%s\" Person: \"%s\"", Mission[1][mission_name], Mission[1][person_name]);
    SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
}
if(Mission[2][mission_type] == type) {
    format(string, sizeof string, "Mission: \"%s\" Person: \"%s\"", Mission[2][mission_name], Mission[2][person_name]);
    SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
}
// and so on
so if the type would be 1 the first two would get called
Reply
#24

Ah, thank you! : )
and one very last question (to not have to make another topic for this in 5 days...)
how can I get A random index
so that it returns the info out of a random mission?
Reply
#25

Quote:
Originally Posted by knackworst
Посмотреть сообщение
Ah, thank you! : )
and one very last question (to not have to make another topic for this in 5 days...)
how can I get A random index
so that it returns the info out of a random mission?
pawn Код:
new rand = random(sizeof Mission);
format(string, sizeof string, "Mission: \"%s\" Person: \"%s\"", Mission[rand][mission_name], Mission[rand][person_name]);
SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
Reply
#26

Thank you! : )
Reply
#27

and uhm, how can I make the random only for the type 1 missions?
(or mission 1,2,3)
I tried this:
pawn Код:
new rand = random(sizeof Mission);
   
    if(gTeam[playerid] == TEAM_DRIVERS && level == 1)//nevermind this
    {
        if(Mission[rand][mission_type] == 1)
        {//blahblah more code
but then I can only go further when the random number turns 1, wich is not all the time...
so I need a random that goes random through the mission with mission_type 1
(it are the first 3 missions aswell)
yes I know i was going to stop posting and asking about this...
but I just couldn't figure out...
Reply
#28

Quote:
Originally Posted by knackworst
Посмотреть сообщение
and uhm, how can I make the random only for the type 1 missions?
(or mission 1,2,3)
I tried this:
pawn Код:
new rand = random(sizeof Mission);
   
    if(gTeam[playerid] == TEAM_DRIVERS && level == 1)//nevermind this
    {
        if(Mission[rand][mission_type] == 1)
        {//blahblah more code
but then I can only go further when the random number turns 1, wich is not all the time...
so I need a random that goes random through the mission with mission_type 1
(it are the first 3 missions aswell)
yes I know i was going to stop posting and asking about this...
but I just couldn't figure out...
the define code is just there to check if the string array could be used if not we create a new array
pawn Код:
if(gTeam[playerid] == TEAM_DRIVERS && level == 1)
{
    new
        i = 0,
        rand = 0;
    #if sizeof Mission <= sizeof string
        #define tmp string
    #else
        new tmp[sizeof Mission];
    #endif
    for( ; i != sizeof Mission; ++i)
    {
        if(Mission[i][mission_type] == 1)
        {
            tmp[rand++] = i;
        }
    }
    if(rand)
    {
        rand = tmp[random(rand)];
        format(string, sizeof string, "Mission: \"%s\" Person: \"%s\"", Mission[rand][mission_name], Mission[rand][person_name]);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
    }
    #if sizeof Mission <= sizeof string
        #undef tmp
    #endif
}
Reply
#29

Ah nice
But how do i do the same for type 2 and 3
And btw i think i own u like 6 reps or something for this topic already *.*
Reply
#30

So the two codes put together

pawn Код:
// indentation
    if((strcmp("/mission", cmdtext, true, 8) == 0) && (gTeam[playerid] == TEAM_DRIVERS) && (level == 1))
    {
        new
            i = 0,
            count = 0,
            type = strval(cmdtext[8]);
        #if sizeof Mission <= sizeof string
            #define tmp string
        #else
            new tmp[sizeof Mission];
        #endif
        for( ; i != sizeof Mission; ++i)
        {
            if(Mission[i][mission_type] == type)
            {
                tmp[count++] = i;
            }
        }
        if(count)
        {
            i = tmp[random(count)];
            format(string, sizeof string, "Mission: \"%s\" Person: \"%s\"", Mission[i][mission_name], Mission[i][person_name]);
            SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
            return true;
        }
        #if sizeof Mission <= sizeof string
            #undef tmp
        #endif
    }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)