naja...ich habe ein bisschen mehr Overhead
Alles bunt und mit Sprachausgabe
Ok. Der einzige Unterschied ist, dass ich den Timer töte und zusätzlich mit Flags arbeite. Warum soll er auch weiterlaufen, obwohl er nicht gebraucht wird bzw. nichts mehr ausgeführt wird
Code:
/*
[WHO]Them's bomb countdown timer.
Ripped and stripped from bud-froggy's bombsay code to expedite release.
Edited by Kndroc to be complient with LogD 1.0
Edit by Sir Drink a lot
*/
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
#define ACCESS_CONSOLE 131072
new STRING_VERSION[MAX_DATA_LENGTH] = "v0.8";
new g_TimerIndex;
////////////////////////////////////////
// ROUND COUNTER (Big THX an SR71GOKU)//
////////////////////////////////////////
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 "
};
public plugin_init() {
plugin_registerinfo("Bomb Planting Timer","Just a countdown until the bomb explodes.",STRING_VERSION);
plugin_registercmd("bt_playeraction", "bt_playeraction", ACCESS_CONSOLE);
exec( "logd_reg 60 admin_command bt_playeraction" );
plugin_registercmd("bt_world", "bt_world", ACCESS_CONSOLE, "");
exec( "logd_reg 62 admin_command bt_world" );
return PLUGIN_CONTINUE;
}
public bt_playeraction(HLCommand,HLData,HLUserName,UserIndex){
new Data[MAX_DATA_LENGTH];
new sID[MAX_DATA_LENGTH];
new C4Timer;
convert_string(HLData, Data, MAX_DATA_LENGTH);
strbreak(Data, sID, Data, MAX_DATA_LENGTH);
if(strcmp(Data, "Planted_The_Bomb") == 0){
C4Timer=getvar("mp_c4timer");
g_TimerIndex=set_timer("announce_bomb",1,C4Timer);
playsound_all("barney/badfeeling");
}else if (strcmp(Data, "Defused_The_Bomb") == 0){
if(g_TimerIndex>0){
kill_timer(g_TimerIndex);
g_TimerIndex=0;
playsound_all("barney/survive");
}
}
return PLUGIN_CONTINUE;
}
public bt_world(HLCommand,HLData,HLUserName,UserIndex){
new Data[MAX_DATA_LENGTH];
convert_string(HLData,Data,MAX_DATA_LENGTH);
if(g_TimerIndex>0){
if(Data[6]=='E' || Data[6]=='S'){
kill_timer(g_TimerIndex);
g_TimerIndex=0;
}
}
return PLUGIN_CONTINUE;
}
public announce_bomb(Timer,Repeat,HLName,HLParam) {
if(g_TimerIndex>0){
new Number[MAX_TEXT_LENGTH];
new Text[MAX_TEXT_LENGTH];
new iTime;
iTime = Repeat - 1;
switch(iTime){
case 40: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 35: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 30: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 25: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 20: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 15: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 10: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 5: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 4: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 3: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 2: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 1: numtoword(iTime,Number,MAX_TEXT_LENGTH);
case 0: {
numtoword(iTime,Number,MAX_TEXT_LENGTH);
g_TimerIndex=0;
}
}
snprintf(Text,MAX_TEXT_LENGTH,"*** BOMB PLANTED ***^n%i seconds remaining^n**************************",iTime);
if(iTime>5){
typesay(Text,12,random(200),random(100),random(100));
}else{
typesay(Text,12,255,0,0);
}
if(strlen(Number)!=0){
if(iTime>5){
snprintf(Number,MAX_TEXT_LENGTH,"%s seconds remaining",Number);
playsound_all(Number);
}else{
playsound_all(Number);
}
}
}
}
playsound_all(Data[]){
new i;
new Target[MAX_NAME_LENGTH];
new maxplayers = maxplayercount();
for(i=1; i<=maxplayers; i++) {
strinit(Target);
if(playerinfo(i,Target,MAX_NAME_LENGTH)) {
speakto(Target,Data);
}
}
}
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);
}