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 |
// 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
}
}
new const Mission[6][DMissions] =
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... |
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
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? |
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);
new rand = random(sizeof Mission);
if(gTeam[playerid] == TEAM_DRIVERS && level == 1)//nevermind this
{
if(Mission[rand][mission_type] == 1)
{//blahblah more code
and uhm, how can I make the random only for the type 1 missions?
(or mission 1,2,3) I tried this: pawn Код:
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... |
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
}
// 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
}