Raised This Month: $ Target: $400
 0% 

Useful Stock(S) [Any Game]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Master53
Veteran Member
Join Date: Dec 2009
Old 12-06-2010 , 14:58   Useful Stock(S) [Any Game]
Reply With Quote #1

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);

__________________
Master(d)




Last edited by Master53; 02-02-2011 at 13:59. Reason: updated.
Master53 is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 12-06-2010 , 17:35   Re: Useful Stock(S) [Any Game]
Reply With Quote #2

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.
AtomicStryker is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 12-06-2010 , 18:26   Re: Useful Stock(S) [Any Game]
Reply With Quote #3

yea ill change them both
__________________
Master(d)



Master53 is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 12-07-2010 , 06:45   Re: Useful Stock(S) [Any Game]
Reply With Quote #4

You should add const correctness and robust error checking. Also, use static instead of new for global variables.
__________________

Last edited by FaTony; 12-07-2010 at 06:47.
FaTony is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-07-2010 , 18:29   Re: Useful Stock(S) [Any Game]
Reply With Quote #5

You no give me credit for my GetClientWeaponCount?
__________________

Last edited by McFlurry; 12-07-2010 at 18:33.
McFlurry is offline
Send a message via Skype™ to McFlurry
Master53
Veteran Member
Join Date: Dec 2009
Old 12-09-2010 , 21:17   Re: Useful Stock(S) [Any Game]
Reply With Quote #6

Quote:
Originally Posted by McFlurry View Post
You no give me credit for my GetClientWeaponCount?
Oh yes ofcorce
__________________
Master(d)



Master53 is offline
Mecha the Slag
Veteran Member
Join Date: Jun 2009
Location: Denmark
Old 12-10-2010 , 17:31   Re: Useful Stock(S) [Any Game]
Reply With Quote #7

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);

__________________
Mecha the Slag is offline
psychonic

BAFFLED
Join Date: May 2008
Old 12-10-2010 , 17:40   Re: Useful Stock(S) [Any Game]
Reply With Quote #8

Quote:
Originally Posted by Mecha the Slag View Post
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.
psychonic is offline
Samantha
SourceMod Donor
Join Date: Feb 2010
Location: Madagascar
Old 12-10-2010 , 18:04   Re: Useful Stock(S) [Any Game]
Reply With Quote #9

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.
__________________
"I give sopport and knolage in making extractions"
"MASTER(D) - dun0: are you mocing me?" -Master the grate

Plugins
Godmode Until Attack | No Block Team Filter
Extensions
Rcon Hooks
Samantha is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 12-10-2010 , 19:24   Re: Useful Stock(S) [Any Game]
Reply With Quote #10

Quote:
Originally Posted by Mecha the Slag View Post
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 is offline
Reply



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:40.


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