22.03.2017, 13:46
So I've made this little function, which was supposed to return a simplified name of the weatherID (https://sampwiki.blast.hk/wiki/WeatherID).
The function 'GetWeatherNameFromID()' returns the weather from the '_weathers' array and works perfectly fine (tested).
The problems:
I've also considered to use `strcmp` (checking the first characters of the weather) instead of `strfind()`.
Any help/example/tutorial would be helpful.
PHP код:
new const _weathers[][] = {
"EXTRASUNNY_LA",
"SUNNY_LA",
"EXTRASUNNY_SMOG_LA",
"SUNNY_SMOG_LA",
"CLOUDY_LA",
"SUNNY_SF",
"EXTRASUNNY_SF",
"CLOUDY_SF",
"RAINY_SF",
"FOGGY_SF",
"SUNNY_VEGAS",
"EXTRASUNNY_VEGAS",
"CLOUDY_VEGAS",
"EXTRASUNNY_COUNTRYSIDE",
"SUNNY_COUNTRYSIDE",
"CLOUDY_COUNTRYSIDE",
"RAINY_COUNTRYSIDE",
"EXTRASUNNY_DESERT",
"SUNNY_DESERT"
};
stock GetWeatherSimplifiedNameFromID(weatherid) {
new weathername[30];
weathername = GetWeatherNameFromID(weatherid);
new string[20];
if (strfind(weathername, "SUNNY", true) != -1) {
string = "Sunny";
return string;
}
if (strfind(weathername, "ClOUDY", true) != -1) {
string = "Cloudy";
return string;
}
if (strfind(weathername, "RAINY", true) != -1) {
string = "Rainy";
return string;
}
if (strfind(weathername, "FOGGY", true) != -1) {
string = "Foggy";
return string;
}
else string = "Unidentified";
return string;
}
The problems:
- The weathers that starts with 'SUNNY' returns 'Foggy'.
- The weathers that starts with 'CLOUDY' returns 'Sunny'.
- The weathers that starts with 'RAINY' returns 'Sunny'.
- The weathers that starts with 'FOGGY' returns 'Sunny'.
I've also considered to use `strcmp` (checking the first characters of the weather) instead of `strfind()`.
Any help/example/tutorial would be helpful.