26.12.2010, 18:45
CarColourFromName(const colourName[]);
Untested, should work though.
Example of usage:
Would return one of the following:
pawn Код:
stock CarColourFromName(const colourName[]) {
if(strcmp(colourName, "black", true, 5) == 0) {
new RandomBlacks[][1] =
{
0,
36,
40
};
new rand = random(sizeof(RandomBlacks));
return RandomBlacks[rand][1];
}
if(strcmp(colourName, "blue", true, 4) == 0) {
new RandomBlues[][1] =
{
2, 7, 10, 12, 20,
28, 53, 59, 79, 87,
93, 94, 95, 100, 103,
106, 108, 125
};
new rand = random(sizeof(RandomBlues));
return RandomBlues[rand][1];
}
if(strcmp(colourName, "red", true, 3) == 0) {
new RandomReds[][1] =
{
3, 17, 18, 21, 22, 30, 31, 42, 43, 48, 58, 62, 70, 78, 80, 82, 88, 115, 117, 121, 124
};
new rand = random(sizeof(RandomReds));
return RandomReds[rand][1];
}
if(strcmp(colourName, "green", true, 5) == 0) {
new RandomGreens[][1] =
{
4, 16, 37, 44, 51, 86, 114
};
new rand = random(sizeof(RandomGreens));
return RandomGreens[rand][1];
}
if(strcmp(colourName, "grey", true, 4) == 0) {
new RandomGreys[][1] =
{
8, 9, 11, 13, 14, 15, 19, 23, 24, 25, 26, 27, 29, 33, 34 35, 50, 60, 64, 90, 92, 96, 105, 109, 122
};
new rand = random(sizeof(RandomGreys));
return RandomGreys[rand][1];
}
if(strcmp(colourName, "pink", true, 4) == 0) {
new RandomPinks[][1] =
{
5, 85, 126
};
new rand = random(sizeof(RandomGreys));
return RandomGreys[rand][1];
}
if(strcmp(colourName, "white", true, 5) == 0) {
return 0;
}
if(strcmp(colourName, "yellow", true, 6) == 0) {
return 6;
}
else {
printf("CarColourFromName: %s was not recognised. Available colour names:", colourName);
print("black, blue, red, green, grey, pink, white, yellow.");
return 0;
}
}
Example of usage:
pawn Код:
printf("Random black car colour: %s", CarColourFromName("black"));
Quote:
Random black car colour: 0 |
Quote:
Random black car colour: 36 |
Quote:
Random black car colour: 40 |