Senior Member
|
01-24-2011
, 11:57
timed teamswitch-block
|
#1
|
Hey guys,
since the simple team-manager doesn't work for me, i wrote a little plugin myself. it works and i can switch a player to the other team, but i haven't figured out how to prevent the player from immediately switching back. Don't really know much about handles and events :<
This is what i got so far:
PHP Code:
/* Plugin Template generated by Pawn Studio */
#include <sourcemod> #undef REQUIRE_PLUGIN #include <adminmenu>
public Plugin:myinfo = { name = "Switch Player", author = "MightyMalcolm", description = "Let's and admin switch a player's team", version = "1.1", url = "http://thestormhawks.eu/" }
new bool:g_players[MAXPLAYERS+1];
public OnPluginStart() { RegAdminCmd("sm_switch",Command_SwitchPlayer,ADMFLAG_CUSTOM1,"Switches a player to the other team."); RegAdminCmd("sm_switch_unlock",Command_Unlock,ADMFLAG_CUSTOM1,"Allows a players to switch teams again."); RegAdminCmd("sm_switch_unlock_all",Command_UnlockAll,ADMFLAG_ROOT,"Allows all players to switch teams again."); HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre); }
public Action:Command_SwitchPlayer(client, args){ new String:arg1[32]; new String:name[MAX_NAME_LENGTH]; new String:adminName[MAX_NAME_LENGTH];
if(GetCmdArgs() < 1){ ReplyToCommand(client,"[SM] Usage: sm_switch <player|#userid>"); return Plugin_Handled; } /* Get the first argument */ GetCmdArg(1, arg1, sizeof(arg1));
/* Try and find a matching player */ new target = FindTarget(client, arg1, true, true); new team = GetClientTeam(target); if (target == -1) { /* FindTarget() automatically replies with the failure reason. */ return Plugin_Handled; } GetClientName(target,name,sizeof(name)); GetClientName(client,adminName, sizeof(adminName)); /* Higher and equally ranked admins are immune */ if (IsAdmin(target)){ new level_client = GetAdminImmunityLevel(GetUserAdmin(client)); new level_target = GetAdminImmunityLevel(GetUserAdmin(target)); if(level_client <= level_target){ ReplyToCommand(client,"[SM] Cannot switch admins that have the same or a higher rank!"); return Plugin_Handled; } }
if(target > 0 && IsValidEntity(target) && IsClientInGame(target)) { switch (team) { case 0: { ReplyToCommand(client,"[SM] Cannot switch a player from team Unassigned!"); return Plugin_Handled; } case 1: { ReplyToCommand(client,"[SM] Cannot switch a player from team Spectator!"); return Plugin_Handled; } case 2: { // Change the client's team ChangeClientTeam(target, 3); // make sure he doesn't switch back g_players[target]=true; CreateTimer(5*60.0, BlockTimer, target); PrintToChatAll("[SM] %s got switched to Humans by %s.", name, adminName); return Plugin_Handled; } case 3: { // Change the client's team ChangeClientTeam(target, 2); // make sure he doesn't switch back g_players[target]=true; CreateTimer(5*60.0, BlockTimer, target); PrintToChatAll("[SM] %s got switched to Undead by %s.", name, adminName); return Plugin_Handled; } default: { ReplyToCommand(client, "Invalid team index! Please try again!"); return Plugin_Handled; } } } else { ReplyToCommand (client, "[SM] Invalid player!"); return Plugin_Handled; } return Plugin_Handled; }
public Action:Command_UnlockAll(client, args){ for(new i = 0; i < MAXPLAYERS; i++){ g_players[i]=false; } ReplyToCommand(client,"[SM] All players can now switch their teams!"); return Plugin_Handled; }
public Action:Command_Unlock(client,args){ new String:arg1[32]; new String:name[MAX_NAME_LENGTH]; if(GetCmdArgs() < 1){ ReplyToCommand(client,"[SM] Usage: sm_switch_unlock <player|#userid>"); return Plugin_Handled; } /* Get the first argument */ GetCmdArg(1, arg1, sizeof(arg1));
/* Try and find a matching player */ new target = FindTarget(client, arg1, true, true); if (target == -1) { /* FindTarget() automatically replies with the failure reason. */ return Plugin_Handled; } /* Higher and equally ranked admins are immune */ if (IsAdmin(target)){ new level_client = GetAdminImmunityLevel(GetUserAdmin(client)); new level_target = GetAdminImmunityLevel(GetUserAdmin(target)); if(level_client <= level_target){ ReplyToCommand(client,"[SM] Cannot unlock admins that have the same or a higher rank!"); return Plugin_Handled; } } GetClientName(target,name,sizeof(name)); g_players[target]=false; ReplyToCommand(client,"[SM] Player %s can now switch his team!"); return Plugin_Handled; }
public Action:Event_PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast){
// if (g_players[client] == true) --> block if(g_players[GetEventInt(event,"userid")]){ ReplyToCommand (GetEventInt(event,"userid"), "[SM] You are not allowed to switch team for 5 minutes!"); return Plugin_Handled; } return Plugin_Continue; }
public Action:BlockTimer(Handle:timer, any: target){ /* TODO // Target disconnected or something, dont affect other players target = GetClientOfUserId(target); if(!target || !IsClientInGame(target)){ return Plugin_Handled; } */
// allows the player to switch team again g_players[target]=false; return Plugin_Handled; }
/* * Copied from * http://forums.alliedmods.net/showthread.php?t=74531&highlight=ping+kick */ public bool:IsAdmin(client){ new AdminId:admin = GetUserAdmin(client); decl String:name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name)); //LogAction(0, -1, "Checking for valid AdminID: Found: %d for client %s", _:admin, name); if(admin == INVALID_ADMIN_ID) { //LogAction(0, -1, "Client %s has an invalid Admin ID.", name); return false; }
//LogAction(0, -1, "Client %s has a valid Admin ID and is immune.", name); return true; }
All it does for the moment, is suppressing the messags "Player xyz joined team blabla", but i can still switch my team. also, as i commented in the code, i need to parse the actual target as a paramater for i don't want to lock teams for everyone.
and i almost forgot to mention the tag mismatch marked in the code as well.
pls help, guys! =)
Last edited by MightyMalcolm; 01-24-2011 at 17:58.
Reason: code updated
|
|