diff --git a/scripting/L4D2Tools.sp b/scripting/L4D2Tools.sp index 45ed5e2..160b0e0 100644 --- a/scripting/L4D2Tools.sp +++ b/scripting/L4D2Tools.sp @@ -75,6 +75,7 @@ public void OnPluginStart() { HookUserMessage(GetUserMessageId("VGUIMenu"), VGUIMenu, true); RegAdminCmd("sm_model", Command_SetClientModel, ADMFLAG_ROOT); + RegAdminCmd("sm_surv", Cmd_SetSurvivor, ADMFLAG_ROOT); RegAdminCmd("sm_respawn_all", Command_RespawnAll, ADMFLAG_CHEATS, "Makes all dead players respawn in a closet"); RegConsoleCmd("sm_pmodels", Command_ListClientModels, "Lists all player's models"); } @@ -139,44 +140,27 @@ public Action Command_SetClientModel(int client, int args) { } int target; for (int i = 0; i < target_count; i++) { - int team = GetClientTeam(target_list[i]); target = target_list[i]; - /*if(team == 1) { - int bot = GetIdleBot(target); - if(bot > -1) { - target = bot; - team = 2; - } - else { - ReplyToCommand(client, "Player %N is spectating and is not idle.", target); - return Plugin_Handled; - } - }*/ bool keepModel = StrEqual(arg3, "keep", false); - if(IsClientConnected(target) && IsClientInGame(target) && IsClientInGame(target) && IsPlayerAlive(target) && team == 2 || team == 3) { - SetEntProp(target, Prop_Send, "m_survivorCharacter", modelID); - SetEntityModel(target, modelPath); - if (IsFakeClient(target)) { - char name[32]; - GetSurvivorName(target, name, sizeof(name)); - SetClientInfo(target, "name", name); - } - UpdatePlayerIdentity(target, view_as(modelID), keepModel); + if(IsClientConnected(target) && IsClientInGame(target) && IsPlayerAlive(target)) { + int team = GetClientTeam(target_list[i]); + if(team == 2 || team == 4) { + SetEntProp(target, Prop_Send, "m_survivorCharacter", modelID); + SetEntityModel(target, modelPath); + if (IsFakeClient(target)) { + char name[32]; + GetSurvivorName(target, name, sizeof(name)); + SetClientInfo(target, "name", name); + } + UpdatePlayerIdentity(target, view_as(modelID), keepModel); - int weapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon"); - if( weapon != -1 ) { - DataPack pack = new DataPack(); - pack.WriteCell(GetClientUserId(target)); - pack.WriteCell(EntIndexToEntRef(weapon)); // Save last held weapon to switch back + int weapon = GetPlayerWeaponSlot(target, 0); + if( weapon != -1 ) { + DataPack pack = new DataPack(); + pack.WriteCell(GetClientUserId(target)); + pack.WriteCell(EntIndexToEntRef(weapon)); // Save last held weapon to switch back - CreateTimer(0.1, Timer_RequipWeapon, pack); - - for( int slot = 0; slot <= 4; slot++ ) { - weapon = GetPlayerWeaponSlot(target, slot); - if( weapon != -1 ) { - pack.WriteCell(EntIndexToEntRef(weapon)); - SDKHooks_DropWeapon(target, weapon, NULL_VECTOR, NULL_VECTOR); - } + CreateTimer(0.1, Timer_RequipWeapon, pack); } } } @@ -185,12 +169,50 @@ public Action Command_SetClientModel(int client, int args) { return Plugin_Handled; } +public Action Cmd_SetSurvivor(int client, int args) { + if(args < 1) { + ReplyToCommand(client, "Usage: sm_surv "); + }else{ + char arg1[32], arg2[16]; + GetCmdArg(1, arg1, sizeof(arg1)); + GetCmdArg(2, arg2, sizeof(arg2)); + + int modelID = GetSurvivorId(arg2); + if(modelID == -1) { + ReplyToCommand(client, "Invalid survivor type entered. Case-sensitive, full name required."); + return Plugin_Handled; + } + char target_name[MAX_TARGET_LENGTH]; + int target_list[MAXPLAYERS], target_count; + bool tn_is_ml; + if ((target_count = ProcessTargetString( + arg1, + client, + target_list, + MAXPLAYERS, + COMMAND_FILTER_CONNECTED, + target_name, + sizeof(target_name), + tn_is_ml)) <= 0) + { + /* This function replies to the admin with a failure message */ + ReplyToTargetError(client, target_count); + return Plugin_Handled; + } + int target; + for (int i = 0; i < target_count; i++) { + target = target_list[i]; + SetEntProp(target, Prop_Send, "m_survivorCharacter", modelID); + } + } + return Plugin_Handled; +} + public Action Timer_RequipWeapon(Handle hdl, DataPack pack) { pack.Reset(); int client = GetClientOfUserId(pack.ReadCell()); if(client == 0) return; - int activeWeapon = pack.ReadCell(); int weapon; while( pack.IsReadable() ) @@ -200,9 +222,6 @@ public Action Timer_RequipWeapon(Handle hdl, DataPack pack) { EquipPlayerWeapon(client, weapon); } } - if( EntRefToEntIndex(activeWeapon) != INVALID_ENT_REFERENCE ) { - SetEntPropEnt(client, Prop_Data, "m_hActiveWeapon", activeWeapon); - } } public Action Event_BotPlayerSwap(Event event, const char[] name, bool dontBroadcast) { @@ -242,6 +261,7 @@ public void OnClientDisconnect(int client) { public void OnMapStart() { HookEntityOutput("info_changelevel", "OnStartTouch", EntityOutput_OnStartTouchSaferoom); HookEntityOutput("trigger_changelevel", "OnStartTouch", EntityOutput_OnStartTouchSaferoom); + } public Action Event_OnWeaponDrop(int client, int weapon) { @@ -279,6 +299,7 @@ public void EntityOutput_OnStartTouchSaferoom(const char[] output, int caller, i } } } + } public Action Timer_TPBots(Handle timer, int user) {