Raised This Month: $93 Target: $400
 23% 

Random Code Archive


Post New Thread Reply   
 
Thread Tools Display Modes
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-21-2018 , 21:20   Re: Random Code Archive
Reply With Quote #21

Here's an automated donation system I've written for an IPB store a while back. It worked well, but I don't use it nowadays. It can be adapted to other systems if you want. Look through it and make it work for you
Attached Files
File Type: zip ipb_donations.zip (14.6 KB, 81 views)
headline is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-22-2018 , 10:52   Re: Random Code Archive
Reply With Quote #22

I wrote a Listen.moe radio thing a few weeks ago. Demonstrates using InfoPanel string tables to host static HTML content.

Nothing's wrong with it, I just don't want to have to maintain it in the future. Should be easy enough to replace the stream with a different URL.
Attached Files
File Type: sp Get Plugin or Get Source (listen_moe.sp - 443 views - 5.8 KB)
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH)
nosoop is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 12-27-2018 , 00:45   Re: Random Code Archive
Reply With Quote #23

Merry Crimbus.
I decided to make a couple of my internal plugins public yesterday, including a plugin for TF2 to trade teams with a random bot on the enemy team without going to Spectate as well as my server's Custom Achievement API.

BotoX previously also made some content public on their git hosting; my favorite of the bunch is Voice, an extension that takes 16bit PCM samples through a TCP socket and streams it to players over the SourceTV client.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH)

Last edited by nosoop; 12-27-2018 at 02:01.
nosoop is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 12-27-2018 , 11:24   Re: Random Code Archive
Reply With Quote #24

Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <cstrike>
#include <clientprefs>

#define SECONDS_IN_DAY 86400

new const String:TimesToFind[][7] = 
{
	"00:00", "03:00"
}
public Plugin:myinfo = 
{
	name = "Clock Events",
	author = "Eyal282",
	description = "",
	version = "1.0",
	url = ""
}

public OnMapStart()
{
	new secondsSinceMidnight, currentTimeSecondsSinceMidnight;
	new String:Hours[7], String:Minutes[7], String:Buffer[7];
	
	FormatTime(Buffer, sizeof(Buffer), "HH:MM");
	new len = SplitString(Buffer, ":", Hours, sizeof(Hours));
		
	SplitString(Buffer[len], ":", Minutes, sizeof(Minutes));
	
	currentTimeSecondsSinceMidnight = (StringToInt(Hours) * 3600) + (StringToInt(Minutes) * 60);
	
	for(new i=0;i < sizeof(TimesToFind);i++)
	{
		len = SplitString(TimesToFind[i], ":", Hours, sizeof(Hours));
		
		SplitString(TimesToFind[i][len], ":", Minutes, sizeof(Minutes));
		
		secondsSinceMidnight = (StringToInt(Hours) * 3600) + (StringToInt(Minutes) * 60);
		
		if(currentTimeSecondsSinceMidnight > secondsSinceMidnight)
			secondsSinceMidnight += SECONDS_IN_DAY;
		
		
		CreateTimer(float(secondsSinceMidnight - currentTimeSecondsSinceMidnight), OnTimeReached, secondsSinceMidnight > 86400 ? secondsSinceMidnight - 86400 : secondsSinceMidnight, TIMER_FLAG_NO_MAPCHANGE);
	}
}

public Action:OnTimeReached(Handle:hTimer, secondsSinceMidnight)
{
	if(secondsSinceMidnight == 0)
		PrintToChatAll("It's 12:00");
		
	else //if(secondsSinceMidnight == 10800) // 10800 / 3600 = 3 hours passed since 0:00 ( aka 3:00 am )
		PrintToChatAll("TIME FOR A KRABBY PATTY");
		
	CreateTimer(float(SECONDS_IN_DAY), OnTimeReached, secondsSinceMidnight, TIMER_FLAG_NO_MAPCHANGE);
	
	return Plugin_Continue;
}
Untested, this will trigger a timer on 0:00 and 3:00 every day.
__________________
Accepting private work. Contact me if you're interested.
If you like my work, feel free to donate in appreciation with PayPal or CSGO Skins.

Total Donated: 10$
eyal282 is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 02-26-2019 , 16:23   Re: Random Code Archive
Reply With Quote #25

I used this to my rules plugin.

Code:
/**
 * Moves an item in an array before the new item.
 *
 *
 * @param Array				ADT Array Handle
 * @param OldItem			The old item to move from
 * @param NewItem			The item to before which the old item will move to.
 * @return					true on success, false if OldItem == NewItem.
 */
stock bool:MoveArrayItem(Handle:Array, OldItem, NewItem)
{
	if(NewItem == OldItem)
		return false;
	
	if(OldItem > NewItem)
	{
		for(new i=NewItem;i < OldItem-1;i++)
			SwapArrayItems(Array, i, i+1);
	}
	else
	{
		for(new i=NewItem;i > OldItem;i--)
			SwapArrayItems(Array, i, i-1);
	}
	
	return true;
}
__________________
Accepting private work. Contact me if you're interested.
If you like my work, feel free to donate in appreciation with PayPal or CSGO Skins.

Total Donated: 10$
eyal282 is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 06-17-2019 , 06:41   Re: Random Code Archive
Reply With Quote #26

For TF2, in case you ever wanted to launch projectiles the exact same way the game does it with baseballs.
I forget if these actually stun enemies.

Not shown is CTFBat_Wood::CanCreateBall(), which seems to do a few traces as a pre-check. Also not shown is making the client use their bat swing animation.

g_SDKCallInitGrenade is an SDKCall on CTFWeaponBaseGrenadeProj::InitGrenade(), which is a virtual method. If you're using that, you want the one with int and float arguments, not the one with CTFWeaponInfo&.

Code:
// Prepare the InitGrenade SDKCall, inline this into your gamedata init
void InitalizeGrenadeSDKCall(Handle hGameConf) {
	StartPrepSDKCall(SDKCall_Entity);
	PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual,
			"CTFWeaponBaseGrenadeProj::InitGrenade(int float)");
	PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_Pointer);
	PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_Pointer);
	PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer);
	PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
	PrepSDKCall_AddParameter(SDKType_Float, SDKPass_Plain);
	g_SDKCallInitGrenade = EndPrepSDKCall();
}

void CreateStunball(int client) {
	int stunball = CreateEntityByName("tf_projectile_stun_ball");
	if (!IsValidEntity(stunball)) {
		return;
	}
	
	float vecSpawnOrigin[3], vecSpawnAngles[3], vecVelocity[3], vecUnknown2[3];
	GetBallDynamics(client, vecSpawnOrigin, vecSpawnAngles, vecVelocity, vecUnknown2);
	
	SetEntPropEnt(stunball, Prop_Data, "m_hOwnerEntity", client);
	SetEntPropEnt(stunball, Prop_Data, "m_hThrower", client);
	SetEntProp(stunball, Prop_Send, "m_bCritical", false); // normally CalcIsAttackCritical()
	
	DispatchSpawn(stunball);
	
	TeleportEntity(stunball, vecSpawnOrigin, vecSpawnAngles, NULL_VECTOR);
	
	/**
	 * massive unexpected headache fix incoming
	 * 
	 * setting the velocity with TeleportEntity() means the check for CBaseEntity::IsInWorld()
	 * returns false -- this check occurs in CTFWeaponBaseGrenadeProj::DetonateThink(); when
	 * this check fails the entity is removed
	 * 
	 * CTFWeaponBaseGrenadeProj::InitGrenade() manages velocity through vphysics, which
	 * means the underlying velocity is set to 0
	 * 
	 * if you're using grenade-subclassed entities at speeds of over 2000HU/s,
	 * you'll need to use this SDKCall (or figure out what it does and implement that),
	 * otherwise you can probably get away with using TeleportEntity()
	 */
	SDKCall(g_SDKCallInitGrenade, stunball, vecVelocity, vecUnknown2, client, 0, 5.0);
	
	SetEntProp(stunball, Prop_Data, "m_bIsLive", true);
}

/** 
 * This is the reversed logic for CTFBat_Wood::GetBallDynamics(), which determines the spawning
 * parameters for the baseball.
 */
void GetBallDynamics(int client, float vecSpawnOrigin[3], float vecSpawnAngles[3],
		float vecVelocity[3], float vecUnknown2[3]) {
	float vecEyeAngles[3], vecEyeForward[3], vecEyeUp[3];
	GetClientEyeAngles(client, vecEyeAngles);
	GetAngleVectors(vecEyeAngles, vecEyeForward, NULL_VECTOR, vecEyeUp);
	
	// spawn position is sum of scaled forward eye vector and origin plus a height offset
	vecSpawnOrigin = vecEyeForward;
	
	float flModelScale = GetEntPropFloat(client, Prop_Send, "m_flModelScale");
	ScaleVector(vecSpawnOrigin, 32.0 * flModelScale);
	
	float vecOrigin[3];
	GetClientAbsOrigin(client, vecOrigin);
	AddVectors(vecOrigin, vecSpawnOrigin, vecSpawnOrigin);
	vecSpawnOrigin[2] += 50.0 * flModelScale;
	
	GetEntPropVector(client, Prop_Data, "m_angAbsRotation", vecSpawnAngles);
	
	float vecEyeForwardScale[3];
	vecEyeForwardScale = vecEyeForward;
	ScaleVector(vecEyeForwardScale, 10.0);
	
	AddVectors(vecEyeForwardScale, vecEyeUp, vecEyeUp);
	NormalizeVector(vecEyeUp, vecEyeUp);
	
	// change this value if you want to set a different speed
	ScaleVector(vecEyeUp, FindConVar("tf_scout_stunball_base_speed").FloatValue);
	vecVelocity = vecEyeUp;
	
	vecUnknown2[1] = GetRandomFloat(0.0, 100.0);
	return;
}
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH)

Last edited by nosoop; 06-19-2019 at 10:01.
nosoop is offline
404UNF
( ͡ ͜ʖ ͡)
Join Date: Dec 2011
Location: 🍁
Old 06-17-2019 , 13:06   Re: Random Code Archive
Reply With Quote #27

Quote:
Originally Posted by nosoop View Post
For TF2, in case you ever wanted to launch projectiles the exact same way the game does it with baseballs.
I forget if these actually stun enemies.
[/code]

Beauty, should be very useful.
__________________
Don't buy plugins from [G]amerX/_GamerX or FREAK (formerly Sourcemod.shop).
Most plugins they sell are either stolen from here outright, or similar ones can be found here for free.


404UNF is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-08-2019 , 07:57   Re: Random Code Archive
Reply With Quote #28

I figured I might share some natives that I've found / written and use til this day:
PHP Code:
char g_sWeapons_Classnames_List[][] =
{
    
"weapon_deagle""weapon_elite""weapon_fiveseven""weapon_glock""weapon_ak47""weapon_aug",
    
"weapon_awp""weapon_famas""weapon_g3sg1""weapon_galilar""weapon_m249""weapon_m4a1",
    
"weapon_mac10""weapon_p90""weapon_mp5sd""weapon_ump45""weapon_xm1014""weapon_bizon",
    
"weapon_mag7""weapon_negev""weapon_sawedoff""weapon_tec9""weapon_hkp2000""weapon_mp7",
    
"weapon_mp9""weapon_nova""weapon_p250""weapon_scar20""weapon_sg553""weapon_ssg08",
    
"weapon_m4a1_silencer""weapon_usp_silencer""weapon_cz75a""weapon_revolver""weapon_bayonet",
    
"weapon_knife_flip" /*"weapon_knife_gut", "weapon_knife_karambit", "weapon_knife_m9_bayonet",
    "weapon_knife_tactical", "weapon_knife_push", "weapon_knife_butterfly", "weapon_knife_falchion",
    "weapon_knife_survival_bowie", "weapon_knife_ursus", "weapon_knife_gypsy_jackknife",
    "weapon_knife_stiletto", "weapon_knife_widowmaker"*/
};

int g_iItem_Definition_Index_List[] =
{
    
123478910,
    
1113141617192324,
    
2526272829303233,
    
3435363839406061,
    
6364500505506507508509,
    
512514515516519520522523
};

stock bool SafeRemoveWeapon(int iClientint iWeapon_Entity_Index)
{
    if (!
IsValidEntity(iWeapon_Entity_Index) || !IsValidEdict(iWeapon_Entity_Index))
        return 
false;
    
    if (!
HasEntProp(iWeapon_Entity_IndexProp_Send"m_hOwnerEntity"))
        return 
false;
    
    
int iWeapon_Owner_Entity GetEntPropEnt(iWeapon_Entity_IndexProp_Send"m_hOwnerEntity");
    
    if (
iWeapon_Owner_Entity != iClient)
        
SetEntPropEnt(iWeapon_Entity_IndexProp_Send"m_hOwnerEntity"iClient);
    
    
CS_DropWeapon(iClientiWeapon_Entity_Indexfalse);
    
    if (
HasEntProp(iWeapon_Entity_IndexProp_Send"m_hWeaponWorldModel"))
    {
        
int iWeapon_World_Model GetEntPropEnt(iWeapon_Entity_IndexProp_Send"m_hWeaponWorldModel");
        
        if (
IsValidEdict(iWeapon_World_Model) && IsValidEntity(iWeapon_World_Model))
            if (!
AcceptEntityInput(iWeapon_World_Model"Kill"))
                return 
false;
    }
    
    if (!
AcceptEntityInput(iWeapon_Entity_Index"Kill"))
        return 
false;
    
    return 
true;
}

/* stock void Weapon_Classname_By_Item_Definition_Index(int iItem_Definition_Index, char[] sWeapon_Classname, int iWeapon_Classname_Size)
{
    for (int i = 0; i < sizeof(g_iItem_Definition_Index_List))
    {
        if (iItem_Definition_Index == g_iItem_Definition_Index_List[i])
        {
            Format(sWeapon_Classname, iWeapon_Classname_Size, "%s", g_sWeapons_Classnames_List[i]);
            
            break;
        }
    }
}

stock int Item_Definition_Index_By_Weapon_Classname(char[] sWeapon_Classname)
{
    for (int i = 0; i < sizeof(g_sWeapons_Classnames_List); i++)
        if (StrEqual(sWeapon_Classname, g_sWeapons_Classnames_List[i]))
            return g_iItem_Definition_Index_List[i];
    
    return -1;
} */

stock void GetWeaponClassname(int iWeapon_Entity_Indexchar[] sBufferint iBuffer_Size)
{
    switch (
GetEntProp(iWeapon_Entity_IndexProp_Send"m_iItemDefinitionIndex"))
    {
        case 
60:
            
Format(sBufferiBuffer_Size"weapon_m4a1_silencer");
        
        case 
61:
            
Format(sBufferiBuffer_Size"weapon_usp_silencer");
        
        case 
63:
            
Format(sBufferiBuffer_Size"weapon_cz75a");
        
        case 
64:
            
Format(sBufferiBuffer_Size"weapon_revolver");
        
        default:
            
GetEntityClassname(iWeapon_Entity_IndexsBufferiBuffer_Size);
    }
}

stock bool IsValidClient(int iClient)
{
    if (!(
iClient <= MaxClients) || !IsClientConnected(iClient) || !IsClientInGame(iClient) || IsFakeClient(iClient))
        return 
false;
    
    return 
true;

__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823
I am inevitable is offline
Ilusion9
Senior Member
Join Date: Jun 2018
Location: Romania
Old 09-07-2019 , 06:41   Re: Random Code Archive
Reply With Quote #29

ShowSyncHudTextToAll:

PHP Code:

stock void ShowSyncHudTextToAll
(Handle syncObj, const char[] formatany ...)
{
    
char buffer[254];
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
SetGlobalTransTarget(i);
            
VFormat(buffersizeof(buffer), format3);
            
            
ClearSyncHud(isyncObj);
            
ShowSyncHudText(isyncObjbuffer);
        }
    }

__________________
Ilusion9 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 17:18.


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