Enum Information returns C?
#1

hi, I made my first enum ever...
an enum to easly make missions in my script, instead of adding 50 lines per mission, I try to do it with maybe 5 lines per mission...

anyways this is what I have:
pawn Code:
enum DMissions
{
    mission_name[200],
    person_name[200],
    pick_place[50],
    deliver_place[50],
    mission_type,
    Float:pick_x,
    Float:pick_y,
    Float:pick_z,
    Float:deliver_x,
    Float:deliver_y,
    Float:deliver_z
};

new Mission[6][DMissions]=
{
//==============================================================================
//Mission TYPE 1
//==============================================================================
    {"Travis Pastrana Is Going to participate the X-games", "Travis Pastrana""The Hollywood Hotel",  "The Stadium"1,  \
    334.4390,-1519.8026,35.7015,
    2732.6616,-1841.6346,9.9145},
   
    {"Chris Martin is back from his smash concert in the Stadium VIVA LA VIDA man!",    "Chris Martin", "The Stadium",  "Chris Martin's Hotel",  1, \
    2732.6616,-1841.6346,9.9145,
    1737.9714,-1270.4094,13.5441},
   
//==============================================================================
//Mission TYPE 2
//==============================================================================
   
    {"The Pope has a meeting with Barack Obama",    "The Pope", "The Airport",  "The White House",  2,  \
    1682.4960,-2290.7954,13.0821,
    1122.9896,-2036.9480,69.8938},
   
    {"Herman Van Rompuy, President of Europe has a meeting with Barack Obama""Herman Van Rompuy",    "The Airport",  "The White House",  2,  \
    1682.4960,-2290.7954,13.0821,
    1122.9896,-2036.9480,69.8938},
   
//==============================================================================
//Mission TYPE 3
//==============================================================================
   
    {"Barack Obama has arrived from his trip to Mexico",    "Barack Obama", "The Airport",  "The White House",  3,  \
    1682.4960,-2290.7954,13.0821,
    1122.9896,-2036.9480,69.8938},
   
    {"Rob Dyredek has arrived at the airport""Rob Dyredek""The Airport",  "Dyrdek's House",  3,   \
    1682.4960,-2290.7954,13.0821,
    974.4201,-819.5055,96.6825}
};
ok, so I did not try to make extremely hard functions at the beginning, just some easy stuff to test if I fully understand the way to use this stuff...

ok so the little test code:
pawn Code:
if (strcmp("/mission1", cmdtext, true) == 0)
    {
        new
            string[200],
            mName = Mission[1][mission_name],
            mPName = Mission[1][person_name];
        format(string,sizeof(string),"%s",mName);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        format(string,sizeof(string),"%s",mPName);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        return 1;
    }
Ok, I compile, and get no errors, so I think that I'm on the good way
but when I go in game i get the following message when I type /mission1

C
CCC

so that means that my first string returned as C
and the second as CCC
... I have no Idea why it gets C...
and why it does not do what it should do...

Thanks in advance
Reply
#2

pawn Code:
if (strcmp("/mission1", cmdtext, true) == 0)
    {
        new
            string[200],
            mName = Mission[sizeof(Mission)][mission_name],
            mPName = Mission[sizeof(Mission)][person_name];
        format(string,sizeof(string),"%s",mName);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        format(string,sizeof(string),"%s",mPName);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        return 1;
    }
Reply
#3

pawn Code:
format(string,sizeof(string),"%s",Mission[id or int][mission_name]);
pawn Code:
new Mission[6][DMissions]=
{
//==============================================================================
//Mission TYPE 1
//==============================================================================
    {"Travis Pastrana Is Going to participate the X-games", "Travis Pastrana",  "The Hollywood Hotel",  "The Stadium",  1,  \
    334.4390,-1519.8026,35.7015,
    2732.6616,-1841.6346,9.9145},
   
    {"Chris Martin is back from his smash concert in the Stadium VIVA LA VIDA man!",    "Chris Martin", "The Stadium",  "Chris Martin's Hotel",  1, \
    2732.6616,-1841.6346,9.9145,
    1737.9714,-1270.4094,13.5441},
   
//==============================================================================
//Mission TYPE 2
//==============================================================================
   
    {"The Pope has a meeting with Barack Obama",    "The Pope", "The Airport",  "The White House",  2,  \
    1682.4960,-2290.7954,13.0821,
    1122.9896,-2036.9480,69.8938},
   
    {"Herman Van Rompuy, President of Europe has a meeting with Barack Obama",  "Herman Van Rompuy",    "The Airport",  "The White House",  2,  \
    1682.4960,-2290.7954,13.0821,
    1122.9896,-2036.9480,69.8938},
   
//==============================================================================
//Mission TYPE 3
//==============================================================================
   
    {"Barack Obama has arrived from his trip to Mexico",    "Barack Obama", "The Airport",  "The White House",  3,  \
    1682.4960,-2290.7954,13.0821,
    1122.9896,-2036.9480,69.8938},
   
    {"Rob Dyredek has arrived at the airport",  "Rob Dyredek",  "The Airport",  "Dyrdek's House",  3,   \
    1682.4960,-2290.7954,13.0821,
    974.4201,-819.5055,96.6825}
};
I am surprised that the errors do not pop up using: "\"
Reply
#4

EDIT: to the first poster
Code:
C:\Users\William\Documents\Famous' World\Famous' World\gamemodes\Famous.pwn(4482) : error 032: array index out of bounds (variable "Mission")
C:\Users\William\Documents\Famous' World\Famous' World\gamemodes\Famous.pwn(4483) : error 032: array index out of bounds (variable "Mission")
lines:
pawn Code:
mName = Mission[sizeof(Mission)][mission_name],
            mPName = Mission[sizeof(Mission)][person_name];
to the second poster:
well the \ stands for new line in PAWN, doesn't it?
I did it because otherwise it's kinda annoying and hard to insert the chords and stuff...
and I don't get the [id or int]
thing...
Reply
#5

Do this:
pawn Code:
new sMission = sizeof(Mission)
and then replace sizeof(Mission) with sMission.
This will fix it.
Reply
#6

:O now it returns as serverUnknownCommand ingame...
wtf?

pawn Code:
if (strcmp("/mission1", cmdtext, true) == 0)
    {
        new sMission = sizeof(Mission);
        new
            mName = Mission[sMission][mission_name],
            mPName = Mission[sMission][person_name];
        format(string,sizeof(string),"%s",mName);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        format(string,sizeof(string),"%s",mPName);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        return 1;
    }
Reply
#7

pawn Code:
if (strcmp("/mission1", cmdtext, true) == 0)
    {
        new sMission = sizeof(Mission);
        format(string,sizeof(string),"%s",Mission[sMission][mission_name]);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        format(string,sizeof(string),"%s",Mission[sMission][person_name]);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        return 1;
    }
Reply
#8

still unknown command thing :/
pawn Code:
if (strcmp("/mission1", cmdtext, true) == 0)
    {
        new sMission = sizeof(Mission);
        format(string,sizeof(string),"%s",Mission[sMission][mission_name]);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        format(string,sizeof(string),"%s",Mission[sMission][person_name]);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        return 1;
    }
Reply
#9

Well, you have to do this like that:
pawn Code:
new Mission[6][DMissions]=
{
//==============================================================================
//Mission TYPE 1
//==============================================================================
  {var1},
  {var2},
   {var3},
{var4},
//and so on!
Reply
#10

but how to i put the info in the variables then? so I can use them later on?
Reply
#11

You can remove the '\' from the end of the line. It's used for strings.
Reply
#12

Thanks but i still get the
c
and
ccc
pawn Код:
if (strcmp("/mission1", cmdtext, true) == 0)
    {
        new
            mName = Mission[1][mission_name],
            mPName = Mission[1][person_name];
        format(string,sizeof(string),"%s",mName);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        format(string,sizeof(string),"%s",mPName);
        SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
        return 1;
    }
Reply
#13

Just input the info you have in the enum....
pawn Код:
mission_name[200],
    person_name[200],
    pick_place[50],
    deliver_place[50],
    mission_type,
    Float:pick_x,
    Float:pick_y,
    Float:pick_z,
    Float:deliver_x,
    Float:deliver_y,
    Float:deliver_z
Something like
pawn Код:
{"Mission name"},
{"This is the person name"},
{"Pick place..."},
and so on, you got it.
Reply
#14

But how do i differ the info from mission with the others f.e
Reply
#15

mName and mPName should be strings.

pawn Код:
new
    mName[200],
    mPName[200];
strmid(mName, Mission[1][mission_name], 0, 200);
strmid(mPName, Mission[1][person_name], 0, 200);
Reply
#16

Thanks alot!
it works : )
just a little question
how can I get f.e the name of all the missions with type 1?
i know its with a loop
and its something like this:
pawn Код:
for(new im; im < mission; im++)
and then an if statement to check the type
but i don't know what exactly to put instead of that < missions
:/
Reply
#17

pawn Код:
for(new im; im < sizeof(Mission); im++)
Reply
#18

Thanks + rep!
but for the new command I'm stuck :/
pawn Код:
if (strcmp("/mission1", cmdtext, true) == 0)
    {
        for(new im; im < sizeof(Mission); im++)
        {
            if(Mission[][mission_type]//stuck here )
            {
            new
                    mName[200],
                    mPName[200];
            strmid(mName, Mission[1][mission_name], 0, 200);
            strmid(mPName, Mission[1][person_name], 0, 200);
            format(string,sizeof(string),"%s",mName);
            SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
            format(string,sizeof(string),"%s",mPName);
            SendClientMessage(playerid, COLOR_YELLOW_LABEL, string);
           
            }
        }
        return 1;
    }
I don't get what to do next :/
Reply
#19

pawn Код:
// indentation
    if(strcmp("/mission", cmdtext, true, 8) == 0) {
        new
            i = 0,
            tmp[128],
            type = strval(cmdtext[8]);
        for( ; i != sizeof Mission; ++i) {
            if(Mission[i][mission_type] == type) {
                format(tmp, sizeof tmp, "Mission: \"%s\" Person: \"%s\"", Mission[i][mission_name], Mission[i][person_name]);
                SendClientMessage(playerid, COLOR_YELLOW_LABEL, tmp);
            }
        }
        if(tmp[0]) {
            return true;
        }
    }
I used tmp because I dont know if the string variable is global or created in OnPlayerCommandText
Reply
#20

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)