AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Useful Stock(S) [Any Game] (https://forums.alliedmods.net/showthread.php?t=144685)

Master53 12-06-2010 14:58

Useful Stock(S) [Any Game]
 
these are just some useful stocks which i'v made and collected over time.

Special thanks to "McFlurry" for his weapon stocks

Added:
GetTeamCount to get the amount of clients in spesific team.
PHP Code:

static UserMsg:FadeID;
static 
UserMsg:ShakeID;


stock SetEntityArmor(ClientArmor)
{

    
//Set Prop Data:
    
SetEntProp(ClientProp_Data"m_ArmorValue"Armor4);
}

stock GetClientScore(Client)
{

    
//Get Prop Data::
    
return GetEntProp(ClientProp_Data"m_iFrags");
}

stock SetClientScore(Clientscore)
{

    
//Set Prop Data:
    
SetEntProp(ClientProp_Data"m_iFrags"score);
}

stock HideHud(ClientType)
{

    
//Set Prop Data:
    
SetEntProp(ClientProp_Send"m_iHideHUD"Type);
}

stock SetClientDeath(Clientdeath)
{

    
//Set Prop Data:
    
SetEntProp(ClientProp_Data"m_iDeaths"death); 
}

stock GetClientDeath(Client)
{

    
//Get Prop Data:
    
return GetEntProp(ClientProp_Data"m_iDeaths");
}

stock SetEntityTimeScale(ClientFloat:fSpeed)
{

    
//Set Prop Data:
    
SetEntPropFloat(ClientProp_Data"m_flLaggedMovementValue"fSpeed);    
}

stock SetEntityMaxSpeed(ClientFloat:Speed)
{

    
//Declare:
    
new SpeedOffset = -1;

    
//Initialize:
    
SpeedOffset FindSendPropOffs("CBasePlayer""m_flMaxspeed");

    
//Set Speed:
    
if(SpeedOffset 0SetEntData(ClientSpeedOffsetSpeed4true);
}

stock SetEntitySkin(entitySkin:skin)
{

    
//Set Prop Send:
    
SetEntProp(entityProp_Send"m_nSkin"skin);
}

stock GetClientConVar(Client, const String:Name[], String:Value[64])
{  

    
//Get Client Convar Value:
    
QueryClientConVar(ClientNameConVarQueryFinished:ClientConVarClient);

    
//Initialize:
    
Value ConVarValue[Client];

    
//Return:
    
return Value
}

stock bool:IsAdmin(Client)
{

    
//Declare:
    
new Admin GetUserFlagBits(Client);

    
//Not Admin:
    
if(Admin != 0)
    {

        
//Return:
        
return true;       
    }

    
//Return:
    
return false;
}

stock GetTotalClients()
{

    
//Declare:
    
new count 0;

    
//Loop:
    
for(new 1<= GetMaxClients(); X++)
    {

        
//Connected:
        
if(IsClientConnected(X) && IsClientInGame(X))
        {

            
//Initialize:
            
count++;
        }
    }

    
//Return:
    
return count;
}

stock GetTeamCount(Team)
{

    
//Declare:
    
new count 0;

    
//Loop:
    
for(new 1<= GetMaxClients(); i++)
    {

        
//Connected:
        
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == Team)
        {

            
//Initialize:
            
count++;
        }
    }

    
//Return:
    
return count;
}

//Get Weapon Count:
stock GetClientWeaponCount(Client)
{
    
//Declare:
    
new count 0;

    
//Loop:
    
for(new 0<= 10i++)
    {

        
//Declare:
        
new wep GetPlayerWeaponSlot(Clienti);

        
//Has Weapon:
        
if(wep != -1)
        {

            
//Initialize:
            
count++;
        }
    }

    
//Return:
    
return count;
}

//shake effect
stock Shake(ClientFloat:LengthFloat:Severity)
{

    
//Conntected:
    
if(IsClientConnected(Client) && IsClientInGame(Client))
    {

        
//User Messages:
        
ShakeID GetUserMessageId("Shake");

        
//Declare:
        
new SendClient[2];
        
SendClient[0] = Client;

        
//Handle:
        
new Handle:ViewMessage StartMessageEx(ShakeIDSendClient1);

        
//Write Handle:
        
BfWriteByte(ViewMessage0);
        
BfWriteFloat(ViewMessageSeverity);
        
BfWriteFloat(ViewMessage10.0);
        
BfWriteFloat(ViewMessageLength);

        
//Close:
        
EndMessage();
    }
}

public 
FadeClient(Clientbool:out)
{

    
//Conntected:
    
if(IsClientConnected(Client) && IsClientInGame(Client))
    {

        
//User Messages:
        
FadeID GetUserMessageId("Fade");

        
//Declare
        
new SendClient[2];
        
SendClient[0] = Client;

        
//Handle:
        
new Handle:ViewMessage StartMessageEx(FadeIDSendClient1);

        
//Write Handle:
        
BfWriteShort(ViewMessage3000); //fade time
        
BfWriteShort(ViewMessage0); //hold time
        
if (out)
        {

            
//Out and Stayout
            
BfWriteShort(ViewMessage0x0002|0x0008);
        }

        
//Override:
        
else
        {

            
//In Ignore Other Fades
            
BfWriteShort(ViewMessage0x0001|0x0010);
        }

        
//Red
        
BfWriteByte(ViewMessage25);

        
//Green
        
BfWriteByte(ViewMessage0);

        
//Blue
        
BfWriteByte(ViewMessage0);

        
//Alpha
        
BfWriteByte(ViewMessage250);

        
//Cloose:
        
EndMessage();
    }
}

//Bipass Cheats:
stock CheatCommand(Client, const String:command[], const String:arguments[])
{

    
//Connected:
    
if(IsClientConnected(Client) && IsClientInGame(Client))
    {

        
//Define:
        
new admindata GetUserFlagBits(Client);

        
//Set Client Flag Bits:
        
SetUserFlagBits(ClientADMFLAG_ROOT);

        
//Define:
        
new flags GetCommandFlags(command);

        
//Set Client Flags:
        
SetCommandFlags(commandflags & ~FCVAR_CHEAT);

        
//Command:
        
ClientCommand(Client"\"%s\" \"%s\""commandarguments);

        
//Set Client Flags:
        
SetCommandFlags(commandflags);

        
//Set Client Flag Bits:
        
SetUserFlagBits(Clientadmindata);
    }

    
//Return:
    
return;
}

//Stop Sound from all Channels:
stock StopSoundPerm(ClientString:sound[])
{

    
//Stop Sound:
    
StopSound(ClientSNDCHAN_AUTOsound);
    
StopSound(ClientSNDCHAN_WEAPONsound);
    
StopSound(ClientSNDCHAN_VOICEsound);
    
StopSound(ClientSNDCHAN_ITEMsound);
    
StopSound(ClientSNDCHAN_BODYsound);
    
StopSound(ClientSNDCHAN_STREAMsound);
    
StopSound(ClientSNDCHAN_VOICE_BASEsound);
    
StopSound(ClientSNDCHAN_USER_BASEsound);



AtomicStryker 12-06-2010 17:35

Re: Useful Stock(S) [Any Game]
 
PHP Code:

stock SetEntitySpeed(ClientFloat:fSpeed)
{

    
//Set Prop Data:
    
SetEntPropFloat(ClientProp_Data"m_flLaggedMovementValue"fSpeed);    
}

stock SetSpeed(ClientFloat:Speed)
{

    
//Declare:
    
new SpeedOffset = -1;

    
//Initialize:
    
SpeedOffset FindSendPropOffs("CHL2MP_Player""m_flMaxspeed");

    
//Set Speed:
    
if(SpeedOffset 0SetEntData(ClientSpeedOffsetSpeed4true);


Some of these are really mis-named. SetEntityTimeScale and SetEntityMaxSpeed would be much better.

Also the second might work better if you get the clients netclass instead of using a specific one.

Master53 12-06-2010 18:26

Re: Useful Stock(S) [Any Game]
 
yea ill change them both :)

FaTony 12-07-2010 06:45

Re: Useful Stock(S) [Any Game]
 
You should add const correctness and robust error checking. Also, use static instead of new for global variables.

McFlurry 12-07-2010 18:29

Re: Useful Stock(S) [Any Game]
 
You no give me credit for my GetClientWeaponCount?:P

Master53 12-09-2010 21:17

Re: Useful Stock(S) [Any Game]
 
Quote:

Originally Posted by McFlurry (Post 1365535)
You no give me credit for my GetClientWeaponCount?:P

Oh yes ofcorce :P

Mecha the Slag 12-10-2010 17:31

Re: Useful Stock(S) [Any Game]
 
IsValidClient() is a must. I'm surprised it's not a part of the default stocks.

PHP Code:

stock bool:IsValidClient(iClient) {
    if (
iClient <= 0) return false;
    if (
iClient MaxClients) return false;
    if (!
IsClientConnected(iClient)) return false;
    return 
IsClientInGame(iClient);



psychonic 12-10-2010 17:40

Re: Useful Stock(S) [Any Game]
 
Quote:

Originally Posted by Mecha the Slag (Post 1368066)
IsValidClient() is a must. I'm surprised it's not a part of the default stocks.

PHP Code:

stock bool:IsValidClient(iClient) {
    if (
iClient <= 0) return false;
    if (
iClient MaxClients) return false;
    if (!
IsClientConnected(iClient)) return false;
    return 
IsClientInGame(iClient);



The last two are redundant. IsClientInGame implies connected and will just return false if not.

Samantha 12-10-2010 18:04

Re: Useful Stock(S) [Any Game]
 
PHP Code:

stock GetTotalClients()
{

    
//Declare:
    
new count 0;

    
//Loop:
    
for(new 1<= GetMaxClients(); X++)
    {

        
//Connected:
        
if(IsClientConnected(X) && IsClientInGame(X))
        {

            
//Initialize:
            
count++;
        }
    }

    
//Return:
    
return count;


GetMaxClients() is depreciated and putting any constant function in a loop is bad because it will call it several times, while placing it in a variable wont.

naris 12-10-2010 19:24

Re: Useful Stock(S) [Any Game]
 
Quote:

Originally Posted by Mecha the Slag (Post 1368066)
IsValidClient() is a must. I'm surprised it's not a part of the default stocks.

PHP Code:

stock bool:IsValidClient(iClient) {
    if (
iClient <= 0) return false;
    if (
iClient MaxClients) return false;
    if (!
IsClientConnected(iClient)) return false;
    return 
IsClientInGame(iClient);



I use this
PHP Code:

#define IsValidClient(%1) (%1 > 0 && %1 <= MaxClients && IsClientInGame(%1)) 


naris 12-10-2010 19:28

Re: Useful Stock(S) [Any Game]
 
Quote:

Originally Posted by samantharp (Post 1368091)
PHP Code:

stock GetTotalClients() 

GetMaxClients() is depreciated and putting any constant function in a loop is bad because it will call it several times, while placing it in a variable wont.

Why wouldn't you just use GetClientCount(false)?

berni 12-11-2010 16:55

Re: Useful Stock(S) [Any Game]
 
Also I see no need in commenting every single line of the code, especially things like this:

PHP Code:

    //Return:
    
return; 

Isn't it obvious that it's a return ?

Also, sometimes you use return at the end, in other functions there isn't one, why ?

Use i, j, k for as loop count variables

PHP Code:

stock bool:IsAdmin(Client)
{

    
//Declare:
    
new Admin GetUserFlagBits(Client);

    
//Not Admin:
    
if(Admin 1)
    {

        
//Return:
        
return true;       
    } 

Is he admin now or not ? wtf


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

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