hier. hat bisher nur admin_bunny, nix mit team oder all, das mach ich wenn ich nochmal zeit habe.
ausserdem ne neue helperfunction, juhu (print_message)
Code:
#include <adminlib>
/* Constants */
#define ACCESS_BUNNY ACCESS_KICK
#define MSG_CONSOLE 1<<0
#define MSG_CENTER 1<<1
#define MSG_CHAT 1<<2
#define MSG_TSAY 1<<3
#define MSG_CSAY 1<<4
/* Global Variables */
new g_Version[] = "0.8";
new g_Bunny[MAX_PLAYERS];
new g_LastRun;
new g_maxplayers;
/* Function Declarations */
forward AdminBunny(HLCommand,HLData,HLUserName,UserIndex);
forward TimerBunny(Timer,Repeat,HLUser,HLParam);
/* Event Handlers */
public plugin_init() {
plugin_registerinfo("Rinde's Bunnyhopping Plugin","Forces players to duckjump",g_Version);
plugin_registercmd("admin_bunny","AdminBunny",ACCESS_BUNNY,"Make target jump repeatedly");
g_maxplayers = min(21,maxplayercount());
return PLUGIN_CONTINUE;
}
public plugin_connect(HLUserName,HLIP,UserIndex) {
g_Bunny[UserIndex] = 0;
return PLUGIN_CONTINUE;
}
public plugin_disconnect(HLUserName,UserIndex) {
g_Bunny[UserIndex] = 0;
return PLUGIN_CONTINUE;
}
public TimerBunny(Timer,Repeat,HLUser,HLParam) {
new Text[MAX_TEXT_LENGTH];
new Name[MAX_NAME_LENGTH];
new Dead;
new counter;
new i;
for(i=1;i<=g_maxplayers;i++) {
if(g_Bunny[i] == 1) {
if(playerinfo(i,Name,MAX_NAME_LENGTH,_,_,_,Dead) == 1) {
if(Dead == 0) {
execclient(Name,"+jump;wait;+duck;-jump;wait;-duck");
g_Bunny[i] = 2;
counter++;
} else {
g_Bunny[i] = 0;
snprintf(Text,MAX_TEXT_LENGTH,"%s can take breath again for a while.",Name);
print_message(Text,0,MSG_CONSOLE|MSG_CSAY);
print_message("You can take breath again for a while.",i,MSG_CSAY);
}
}
} else if(g_Bunny[i] == 2) {
g_Bunny[i] = 1;
counter++;
}
}
g_LastRun = systemtime();
if(counter > 0) {
set_timer("TimerBunny",1,0);
}
}
/* Command Handlers */
public AdminBunny(HLCommand,HLData,HLUserName,UserIndex) {
new Data[MAX_DATA_LENGTH];
new Text[MAX_TEXT_LENGTH];
new TargetIndex;
convert_string(HLData,Data,MAX_DATA_LENGTH);
strstripquotes(Data);
if(check_user(Data) == 0) {
selfmessage("Unrecognized player:");
selfmessage(Data);
} else {
get_username(Data,Data,MAX_NAME_LENGTH);
get_userindex(Data,TargetIndex);
if(g_Bunny[TargetIndex] != 0) {
selfmessage("That player already is a bunny");
} else if(check_immunity(Data) == 1) {
snprintf(Text,MAX_TEXT_LENGTH,"Fal. You can't transform %s into a bunny.",Data);
selfmessage(Data);
} else {
g_Bunny[TargetIndex] = 1;
snprintf(Text,MAX_TEXT_LENGTH,"%s is now a bunny. Happy hopping.",Data);
print_message(Text,0,MSG_CONSOLE|MSG_CSAY);
print_message("You are now a bunny. Happy hopping.",TargetIndex,MSG_CSAY);
convert_string(HLUserName,Text,MAX_NAME_LENGTH);
say_command(Text,"admin_bunny",Data);
if(g_LastRun + 2 <= systemtime()) {
set_timer("TimerBunny",1,0);
}
}
}
return PLUGIN_HANDLED;
}
/* Helper Functions */
print_message(msg[MAX_TEXT_LENGTH],UserIndex = 0,Type = 0) {
new Name[MAX_NAME_LENGTH];
new dummy;
new i,j;
for(i=0;i<5;i++) {
dummy = Type & 1<<i;
if(dummy) {
dummy &= MSG_TSAY | MSG_CSAY;
if(dummy) {
format_lines(msg);
}
if(UserIndex == 0) {
for(j=1;j<=g_maxplayers;j++) {
if(playerinfo(i,Name,MAX_NAME_LENGTH) == 1) {
messageex(Name,msg,i);
}
}
} else {
if(playerinfo(UserIndex,Name,MAX_NAME_LENGTH) == 1) {
messageex(Name,msg,i);
}
}
}
}
}
format_lines(Text[MAX_TEXT_LENGTH],maxlen = MAX_TEXT_LENGTH,linelen = 80) {
new SayText[MAX_TEXT_LENGTH];
new textpos;
new saytextpos;
new textlen = min(maxlen,strlen(Text));
new numtoadd;
new i;
while(textlen-textpos > linelen) {
for(i=textpos+79;i>textpos;--i) {
if(Text[i] == '^n' || Text[i] == ' ' && textpos == numtoadd) {
numtoadd = i;
}
}
if(numtoadd == textpos) {
numtoadd = textpos+linelen-1;
}
for(i=textpos;i<numtoadd;i++) {
SayText[saytextpos++] = Text[i];
}
SayText[saytextpos++] = '^n';
if(Text[numtoadd] == ' ' || Text[numtoadd] == '^n') {
numtoadd++;
}
textpos = numtoadd;
}
for(i=textpos;i<textlen;i++) {
SayText[saytextpos++] = Text[i];
}
saytextpos = min(saytextpos,maxlen);
for(i=0;i<saytextpos;i++) {
Text[i] = SayText[i];
}
Text[saytextpos] = '^0';
return saytextpos;
}