nicht ganz richtig
Ich habe gerade eine Version vom timemanager gebastelt, die eine Timeleft-Zeit Ansage drin hat. Das heißt, er muss meine Sekunden in Minute und Sekunde und dann auch in ein Wort umwandeln. Die Funktion kannst Du entsprechend für Deine Zwecke umwandeln. Das Prinzip bleibt ja das selbe.
Du nutzt einmal einen Array 1 - 19 und dann einen Zehner-Array.
Hier nun die Funktion: (oder ist es sogar die Funktion, die ich mal mit Warhead geabstelt habe...ganz ganz früher
Code:
/*Alles zum Timeleft*/
SpeakTimeleft() {
new i;
new maxplayers = maxplayercount();
new SessionID;
new Target[MAX_NAME_LENGTH];
new WONID;
new outputstring[MAX_DATA_LENGTH];
new seconds;
new minutes;
new first;
new second;
new third;
new fourth;
new Minutes[MAX_TEXT_LENGTH];
new Seconds[MAX_TEXT_LENGTH];
new Authid[MAX_AUTHID_LENGTH];
new low[20][]={"","one ", "two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ","eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "};
new high[10][]={"", "", "twenty ","thirty ","fourty ","fifty ","sixty ","seventy ","eighty ","ninety "};
minutes=time/60;
seconds=time%60;
if(minutes<=0 && seconds <=0){
return PLUGIN_FAILURE;
}
first=minutes/10;
second=minutes%10;
if(first==1){
second=minutes;
first=0;
}
third=seconds/10;
fourth=seconds%10;
if(third==1){
fourth=seconds;
third=0;
}
if(minutes>0){
snprintf(Minutes, MAX_DATA_LENGTH, "%s%s", high[first], low[second]);
}
if(seconds>0){
snprintf(Seconds, MAX_DATA_LENGTH, "%s%s ", high[third], low[fourth]);
}
snprintf(outputstring,MAX_DATA_LENGTH,"fvox/%s minutes %s seconds remaining",Minutes,Seconds );
for(i=1; i<=maxplayers; i++) {
strinit(Target);
if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,_,_,Authid)==1) {
if(strcmp(Authid,"BOT")!=0){
speakto(Target,outputstring);
}
}
}
return PLUGIN_HANDLED;
}
public HandleSay(HLCommand,HLData,HLUserName,UserIndex) {
new Command[MAX_COMMAND_LENGTH];
new Data[MAX_DATA_LENGTH];
new User[MAX_NAME_LENGTH];
convert_string(HLCommand,Command,MAX_COMMAND_LENGTH);
convert_string(HLData,Data,MAX_DATA_LENGTH);
convert_string(HLUserName,User,MAX_NAME_LENGTH);
strstripquotes(Data);
if (streq(Data, "timeleft")==1) {
checktime = systemtime()-(systemtime()- checktime);
map_time();
if (systemtime() < iLastSpeak) {
return PLUGIN_CONTINUE;
} else {
SpeakTimeleft();
iLastSpeak = systemtime();
iLastSpeak += 60;
}
}
return PLUGIN_CONTINUE;
}
Und hier auch mal, wie es SR71GOKU generell gemacht hat. Die Lösung ist wahrscheinlich schon passender für Dich.
Code:
/* The library of words for numtoword */
static OnesLib[10][] = { "", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine " };
static TensLib[10][] = {"", "ten ", "twenty ", "thirty ", "fourty ", "fifty ", "sixty ", "seventy ", "eighty ", "ninety " } ;
static TeensLib[10][] = {"", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen " };
static HundredsLib[10][] = { "", "one hundred ", "two hundred ", "three hundred ", "four hundred ", "five hundred ", "six hundred ", "seven hundred ", "eight hundred ", "nine hundred " };
static GroupNamesLib[5][] = {"", "thousand ", "million ", "billion ", "trillion " };
stock do_numtoword(iNum,str[],iLevel,iLength) {
/* If there is more than one group of 3, then take care of the others first. */
if(iNum >= 1000) do_numtoword(iNum / 1000,str,iLevel + 1,iLength);
/* Grab the the first 3 digits only */
iNum %= 1000;
/* Isolate each digit */
new _hundreds = iNum / 100;
new _tens = (iNum / 10) % 10;
new _ones = iNum % 10;
/* Take care of the teen numbers */
if(_tens == 1 && _ones != 0) {
snprintf(str,iLength,"%s%s%s%s",str,HundredsLib[_hundreds],TeensLib[_ones],GroupNamesLib[iLevel]);
} else {
snprintf(str,iLength,"%s%s%s%s%s",str,HundredsLib[_hundreds], TensLib[_tens], OnesLib[_ones],GroupNamesLib[iLevel]);
}
if(iLevel==0) str[strlen(str)-1] = 0; /* Gets rid of the trailing space*/
return 1;
}
stock numtoword(iNum,str[],iLength) {
/* Empties the first char of the string */
str[0] = 0;
str[iLength-1] = 0;
if(iNum == 0) {
snprintf(str,iLength,"zero");
return 1;
}
if(iNum < 0) {
iNum *= -1;
snprintf(str,iLength,"negative ");
}
return do_numtoword(iNum,str,0,iLength);
}
Diesen Code habe ich aus seiner .inc Datei.