Raised This Month: $12 Target: $400
 3% 

[req] Swimming


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ApoziX
Member
Join Date: Sep 2018
Old 10-18-2018 , 23:41   [req] Swimming
Reply With Quote #1

Someome Can Add Cmd To Toggle Swimming?

here is the code
+rep for helpers
PHP Code:
#include <sourcemod>

#include <tf2>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart() {
    
HookEvent("player_spawn"OnPlayerSpawnEventHookMode_PostNoCopy);
}

public 
void OnPlayerSpawn(Event event, const char[] namebool dontBroadcast) {
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    
    if (
client && IsPlayerAlive(client) && CheckCommandAccess(client"air_swim"ADMFLAG_GENERIC)) {
        
TF2_AddCondition(clientTFCond_SwimmingCurseTFCondDuration_Infinite);
    }

__________________
Looking To Start A TF2 Community
My Discord | My Steam
ApoziX is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 10-19-2018 , 03:53   Re: [req] Swimming
Reply With Quote #2

Untested.

PHP Code:
#include <sourcemod>
#include <tf2>
#include <adminmenu>

#pragma semicolon 1
#pragma newdecls required

#define ASC_VERSION "1.0"

public Plugin myinfo =
{
    
name "[TF2] Air Swim Condition",
    
author "ApoziX and Psyk0tik (Crasher_3637)",
    
description "Provides a command to toggle air swim condition on players.",
    
version ASC_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?t=311471"
};

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    if (
GetEngineVersion() != Engine_TF2)
    {
        
strcopy(errorerr_max"This plugin only supports Team Fortress 2.");
        return 
APLRes_SilentFailure;
    }

    return 
APLRes_Success;
}

bool g_bAirSwim[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
LoadTranslations("common.phrases");
    
RegAdminCmd("sm_swim"cmdAirSwimADMFLAG_GENERIC"Toggle air swim condition for players.");
    
CreateConVar("asc_version"ASC_VERSION"Plugin version"FCVAR_NOTIFY|FCVAR_DONTRECORD);
}

public 
void OnClientPutInServer(int client)
{
    
g_bAirSwim[client] = false;
}

public 
Action cmdAirSwim(int clientint args)
{
    if (!
bIsValidClient(client))
    {
        
ReplyToCommand(client"[SM] You must be in-game to use this command.");
        return 
Plugin_Handled;
    }

    
char target[32], target_name[32], toggle[32];
    
int target_list[MAXPLAYERS], target_count;
    
bool tn_is_ml;
    
GetCmdArg(1targetsizeof(target));
    
GetCmdArg(2togglesizeof(toggle));
    
int toggler StringToInt(toggle);

    if (
args != || toggler || toggler 1)
    {
        if (
IsVoteInProgress())
        {
            
ReplyToCommand(client"[SM] Usage: sm_swim <#userid|name> <0|1>");
        }
        else
        {
            
vMenuSwim(client0);
        }

        return 
Plugin_Handled;
    }

    if ((
target_count ProcessTargetString(targetclienttarget_listMAXPLAYERSCOMMAND_FILTER_ALIVEtarget_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }

    for (
int i 0target_counti++)
    {
        if (
bIsValidClient(target_list[i]))
        {
            switch (
toggler)
            {
                case 
0:
                {
                    
TF2_RemoveCondition(target_list[i], TFCond_SwimmingCurse);
                    
PrintToChat(target_list[i], "[SM] You cannot air swim anymore.");
                }
                case 
1:
                {
                    
TF2_AddCondition(target_list[i], TFCond_SwimmingCurseTFCondDuration_Infinite);
                    
PrintToChat(target_list[i], "[SM] You can now air swim.");
                }
            }
        }
    }

    if (
tn_is_ml)
    {
        
ShowActivity2(client"[SM] ""Toggled air swimming for %t."clienttarget_name);
    }
    else
    {
        
ShowActivity2(client"[SM] ""Toggled air swimming for %s."clienttarget_name);
    }

    return 
Plugin_Handled;
}

void vMenuSwim(int clientint item)
{
    
Menu mSwimMenu = new Menu(iSwimMenuHandler);
    
mSwimMenu.SetTitle("Choose a player:");
    
AddTargetsToMenu(mSwimMenuclienttruetrue);
    
mSwimMenu.DisplayAt(clientitemMENU_TIME_FOREVER);
}

public 
int iSwimMenuHandler(Menu menuMenuAction actionint param1int param2)
{
    switch (
action)
    {
        case 
MenuAction_Enddelete menu;
        case 
MenuAction_Select:
        {
            
char sInfo[32];
            
menu.GetItem(param2sInfosizeof(sInfo));
            
int iTarget GetClientOfUserId(StringToInt(sInfo));

            if (
iTarget == 0)
            {
                
PrintToChat(param1"[SM] %t""Player no longer available");
            }
            else if (!
CanUserTarget(param1iTarget))
            {
                
PrintToChat(param1"[SM] %t""Unable to target");
            }
            else if (!
IsPlayerAlive(iTarget))
            {
                
PrintToChat(param1"[SM] %t""Player has since died");
            }
            else
            {
                switch (
g_bAirSwim[iTarget])
                {
                    case 
true:
                    {
                        
TF2_RemoveCondition(iTargetTFCond_SwimmingCurse);
                        
g_bAirSwim[iTarget] = false;
                        
PrintToChat(iTarget"[SM] You cannot air swim anymore.");
                    }
                    case 
false:
                    {
                        
TF2_AddCondition(iTargetTFCond_SwimmingCurseTFCondDuration_Infinite);
                        
g_bAirSwim[iTarget] = true;
                        
PrintToChat(iTarget"[SM] You can now air swim.");
                    }
                }

                
ShowActivity2(param1"[SM] ""Toggled air swimming for %N."iTarget);

                if (
IsClientInGame(param1) && !IsClientInKickQueue(param1))
                {
                    
vMenuSwim(param1menu.Selection);
                }
            }
        }
    }

    return 
0;
}

stock bool bIsValidClient(int client)
{
    if (
client <= || client MaxClients || !IsClientInGame(client))
    {
        return 
false;
    }

    return 
true;

Attached Files
File Type: sp Get Plugin or Get Source (tf2_air_swim.sp - 150 views - 4.3 KB)
__________________

Last edited by Psyk0tik; 10-19-2018 at 18:23.
Psyk0tik is offline
ApoziX
Member
Join Date: Sep 2018
Old 10-19-2018 , 04:49   Re: [req] Swimming
Reply With Quote #3

Quote:
Originally Posted by Crasher_3637 View Post
Untested.

PHP Code:
#include <sourcemod>
#include <tf2>
#include <adminmenu>

#pragma semicolon 1
#pragma newdecls required

#define ASC_VERSION "1.0"

public Plugin myinfo =
{
    
name "[TF2] Air Swim Condition",
    
author "ApoziX and Psyk0tik (Crasher_3637)",
    
description "Provides a command to toggle air swim condition on players.",
    
version ASC_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?t=311471"
};

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    if (
GetEngineVersion() != Engine_TF2)
    {
        
strcopy(errorerr_max"This plugin only supports Team Fortress 2.");
        return 
APLRes_SilentFailure;
    }

    return 
APLRes_Success;
}

bool g_bAirSwim[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
LoadTranslations("common.phrases");
    
RegAdminCmd("sm_swim"cmdAirSwimADMFLAG_GENERIC"Toggle air swim condition for players.");
    
CreateConVar("asc_version"ASC_VERSION"Plugin version"FCVAR_NOTIFY|FCVAR_DONTRECORD);
}

public 
void OnClientPutInServer(int client)
{
    
g_bAirSwim[client] = false;
}

public 
Action cmdAirSwim(int clientint args)
{
    if (!
bIsValidClient(client))
    {
        
ReplyToCommand(client"[SM] You must be in-game to use this command.");
        return 
Plugin_Handled;
    }

    
char target[32], target_name[32], toggle[32];
    
int target_list[MAXPLAYERS], target_count;
    
bool tn_is_ml;
    
GetCmdArg(1targetsizeof(target));
    
GetCmdArg(2togglesizeof(toggle));
    
int toggler StringToInt(toggle);

    if (
args != || toggler || toggler 1)
    {
        if (
IsVoteInProgress())
        {
            
ReplyToCommand(client"[SM] Usage: sm_swim <#userid|name> <0|1>");
        }
        else
        {
            
vMenuSwim(client0);
        }

        return 
Plugin_Handled;
    }

    if ((
target_count ProcessTargetString(targetclienttarget_listMAXPLAYERSCOMMAND_FILTER_ALIVEtarget_namesizeof(target_name), tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }

    for (
int i 0target_counti++)
    {
        if (
bIsValidClient(target_list[i]))
        {
            switch (
toggler)
            {
                case 
0:
                {
                    
TF2_RemoveCondition(target_list[i], TFCond_SwimmingCurse);
                    
PrintToChat(target_list[i], "[SM] You cannot air swim anymore.");
                }
                case 
1:
                {
                    
TF2_AddCondition(target_list[i], TFCond_SwimmingCurseTFCondDuration_Infinite);
                    
PrintToChat(target_list[i], "[SM] You can now air swim.");
                }
            }
        }
    }

    if (
tn_is_ml)
    {
        
ShowActivity2(client"[SM] ""Toggled air swimming for %t."clienttarget_name);
    }
    else
    {
        
ShowActivity2(client"[SM] ""Toggled air swimming for %s."clienttarget_name);
    }

    return 
Plugin_Handled;
}

void vMenuSwim(int clientint item)
{
    
Menu mSwimMenu = new Menu(iSwimMenuHandler);
    
mSwimMenu.SetTitle("Choose a player:");
    
AddTargetsToMenu(mSwimMenuclienttruetrue);
    
mSwimMenu.DisplayAt(clientitemMENU_TIME_FOREVER);
}

public 
int iSwimMenuHandler(Menu menuMenuAction actionint param1int param2)
{
    switch (
action)
    {
        case 
MenuAction_Enddelete menu;
        case 
MenuAction_Select:
        {
            
char sInfo[32];
            
menu.GetItem(param2sInfosizeof(sInfo));
            
int iTarget GetClientOfUserId(StringToInt(sInfo));

            if (
iTarget == 0)
            {
                
PrintToChat(param1"[SM] %t""Player no longer available");
            }
            else if (!
CanUserTarget(param1iTarget))
            {
                
PrintToChat(param1"[SM] %t""Unable to target");
            }
            else if (!
IsPlayerAlive(iTarget))
            {
                
PrintToChat(param1"[SM] %t""Player has since died");
            }
            else
            {
                switch (
g_bAirSwim[iTarget])
                {
                    case 
true:
                    {
                        
TF2_RemoveCondition(iTargetTFCond_SwimmingCurse);
                        
g_bAirSwim[iTarget] = false;
                        
PrintToChat(iTarget"[SM] You cannot air swim anymore.");
                    }
                    case 
false:
                    {
                        
TF2_AddCondition(iTargetTFCond_SwimmingCurseTFCondDuration_Infinite);
                        
g_bAirSwim[iTarget] = true;
                        
PrintToChat(iTarget"[SM] You can now air swim.");
                    }
                }

                
ShowActivity2(param1"[SM] ""Toggled air swimming for %N."iTarget);

                if (
IsClientInGame(param1) && !IsClientInKickQueue(param1))
                {
                    
vMenuSwim(param1menu.Selection);
                }
            }
        }
    }

    return 
0;
}

stock bool bIsValidClient(int client)
{
    if (
client >= || client MaxClients || !IsClientInGame(client))
    {
        return 
false;
    }

    return 
true;


Thanks Mate +rep
__________________
Looking To Start A TF2 Community
My Discord | My Steam
ApoziX is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 10-19-2018 , 18:24   Re: [req] Swimming
Reply With Quote #4

I edited my previous post to correct the wrong symbol used in bIsValidClient.
__________________
Psyk0tik is offline
ApoziX
Member
Join Date: Sep 2018
Old 11-02-2018 , 16:16   Re: [req] Swimming
Reply With Quote #5

Quote:
Originally Posted by Crasher_3637 View Post
I edited my previous post to correct the wrong symbol used in bIsValidClient.
Working LIT!
__________________
Looking To Start A TF2 Community
My Discord | My Steam
ApoziX is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:29.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode