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

[TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bitl
Senior Member
Join Date: Jul 2012
Old 12-16-2012 , 12:56   [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #1

Hello, and today we will develop a plugin that modifies the inner game aspects for gameplay, also known as a gamemode.

With our gamemode, we will make one where you spawn as Pyro, and you get only one weapon.

Requirements:
-Sourcemod
-TF2
-TF2Items
-TF2Items GiveWeapon (plugin and .inc)

Now lets get started!

Includes (can be modified):
Code:
#include <sourcemod>
#include <tf2items>
#include <tf2_stocks>
#include <tf2items_giveweapon>
You need these for your plugin to compile correctly.

Now, to make our plugin.

Code:
new TF2ItemSlot = 8;
This tells us to find all the slots. We need this so that we can strip all the items.

Code:
public Plugin:myinfo =
{
	name = "[TF2] Pyro Battle",
	author = "Me",
	description = "A gamemode where pyros fight eachother.",
	version = "1.0",
	url = ""
};
Plugin info, nothing new here.

Next you would need to hook the events, for this, I chose player_spawn and post_inventory_application.

Code:
public OnPluginStart()
{
	HookEvent( "post_inventory_application", OnPostInventoryApplicationAndPlayerSpawn );
	HookEvent( "player_spawn", OnPostInventoryApplicationAndPlayerSpawn );
}
Next, add the OnPostInventoryApplicationAndPlayerSpawn function.

Code:
public OnPostInventoryApplicationAndPlayerSpawn( Handle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
}
Next, add the client defines in the extention:

Code:
new iClient = GetClientOfUserId( GetEventInt( hEvent, "userid" ) )
After that, add the part where it removes all of the players items before spawning.

Code:
for( new iSlot = 0; iSlot < _:TF2ItemSlot; iSlot++ )
		TF2_RemoveWeaponSlot( iClient, iSlot );
Next, add the weapon. we will talk about the weapon code later.

Code:
TF2Items_GiveWeapon(iClient, 9990);
Then add the slot1 and slot2 removers, just in case.

Code:
TF2_RemoveWeaponSlot(iClient, 1);
TF2_RemoveWeaponSlot(iClient, 2);
Then add the SetClass, and then you are done.

Code:
TF2_SetPlayerClass(iClient, TFClass_Pyro, false, true);
So the entire plugin should look like this:

Code:
#include <sourcemod>
#include <tf2items>
#include <tf2_stocks>
#include <tf2items_giveweapon>

new TF2ItemSlot = 8;
 
public Plugin:myinfo =
{
	name = "[TF2] Pyro Battle",
	author = "Me",
	description = "A gamemode where pyros fight eachother.",
	version = "1.0",
	url = ""
};
 
public OnPluginStart()
{
	HookEvent( "post_inventory_application", OnPostInventoryApplicationAndPlayerSpawn );
	HookEvent( "player_spawn", OnPostInventoryApplicationAndPlayerSpawn );
}

public OnPostInventoryApplicationAndPlayerSpawn( Handle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
	new iClient = GetClientOfUserId( GetEventInt( hEvent, "userid" ) )
	
	for( new iSlot = 0; iSlot < _:TF2ItemSlot; iSlot++ )
		TF2_RemoveWeaponSlot( iClient, iSlot );
	
	TF2Items_GiveWeapon(iClient, 9990);
		
	TF2_RemoveWeaponSlot(iClient, 1);
	TF2_RemoveWeaponSlot(iClient, 2);
	
	TF2_SetPlayerClass(iClient, TFClass_Pyro, false, true)
}
Now, here's the weapon code, create a file named tf2items.givecustom.txt in sourcemod/configs, then put this in the .txt:

Code:
"custom_give_weapons_vlolz"
{
	"9990"
    {
		"classname"	"tf_weapon_syringegun_medic"
		"index"		"527"
		"slot"		"0"
		"quality"		"9"
		"level"		"10"
		"attribs"		"280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10"
		"ammo"		"300"
    }
}
Then you are done!

You can edit this plugin to your liking, but DO NOT RELEASE THE PYROBATTLE PLUGIN TO NEW PLUGINS.

Plugin and files included are below.
Attached Files
File Type: smx pyrobattle.smx (2.9 KB, 531 views)
File Type: sp Get Plugin or Get Source (pyrobattle.sp - 443 views - 956 Bytes)
File Type: txt tf2items.givecustom.txt (262 Bytes, 591 views)
__________________
My Plugins
Modified Plugins:
Building Spawner
Monster
It's Raining Men!
Tutorials:
Custom Gamemode

I DON'T DO PLUGIN REQUESTS.

Last edited by Bitl; 12-16-2012 at 12:59.
Bitl is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 12-16-2012 , 17:06   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #2

neat
Mitchell is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 12-19-2012 , 01:21   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #3

as longer as TF2Items GiveWeapon uses TF2ItemsInfo,
there's already TF2ItemSlot enum
so you have to check for it
Code:
#if !defined _tf2itemsinfo_included
new TF2ItemSlot = 8;
#endif
you also can crate weapon with TF2Items GiveWeapon' natives
Code:
public OnAllPluginsLoaded()
{
    TF2Items_CreateWeapon( 9990, "tf_weapon_syringegun_medic", 527, 0, 9, 10, "280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10", 300, _, true );
}
also someone told me do not use function/variable names longer than 32 chars.

so plugin should look like:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <tf2_stocks>

#define REQUIRE_EXTENSIONS
#define AUTOLOAD_EXTENSIONS
#include <tf2items>

#undef REQUIRE_PLUGIN
#tryinclude <tf2itemsinfo>

#define REQUIRE_PLUGIN
#include <tf2items_giveweapon>

#define MY_WEAPON_ID 9090

#if !defined _tf2itemsinfo_included
new TF2ItemSlot 8;
#endif

public Plugin:myinfo =
{
    
name "[TF2] Pyro Battle",
    
author "You",
    
description "A gamemode where pyros fight each others.",
    
version "1.1",
    
url "http://forums.alliedmods.net/showthread.php?t=203225"
};

public 
OnPluginStart()
{
    
HookEvent"post_inventory_application"OnHookedEvent );
    
HookEvent"player_spawn"OnHookedEvent );
}

public 
OnAllPluginsLoaded()
{
    
TF2Items_CreateWeaponMY_WEAPON_ID"tf_weapon_syringegun_medic"5270910"280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10"300_true );
}

public 
OnPostInventoryApplicationAndPlayerSpawnHandle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
    new 
iClient GetClientOfUserIdGetEventInthEvent"userid" ) )
    if( 
iClient <= || iClient MaxClients || !IsClientInGame(iClient/*|| !IsPlayerAlive(iClient)*/ )
        return;
    
    for( new 
iSlot 0iSlot _:TF2ItemSlotiSlot++ )
        
TF2_RemoveWeaponSlotiClientiSlot );
    
    
TF2_SetPlayerClassiClientTFClass_Pyro_true );
    
    
TF2Items_GiveWeaponiClientMY_WEAPON_ID );

EDIT:
oh
any reason why it's a tf_weapon_syringegun_medic with item ID #527 (widowmaker)?
__________________

Last edited by Leonardo; 12-19-2012 at 01:32.
Leonardo is offline
Bitl
Senior Member
Join Date: Jul 2012
Old 12-21-2012 , 00:26   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #4

Quote:
Originally Posted by Leonardo View Post
as longer as TF2Items GiveWeapon uses TF2ItemsInfo,
there's already TF2ItemSlot enum
so you have to check for it
Code:
#if !defined _tf2itemsinfo_included
new TF2ItemSlot = 8;
#endif
you also can crate weapon with TF2Items GiveWeapon' natives
Code:
public OnAllPluginsLoaded()
{
    TF2Items_CreateWeapon( 9990, "tf_weapon_syringegun_medic", 527, 0, 9, 10, "280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10", 300, _, true );
}
also someone told me do not use function/variable names longer than 32 chars.

so plugin should look like:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <tf2_stocks>

#define REQUIRE_EXTENSIONS
#define AUTOLOAD_EXTENSIONS
#include <tf2items>

#undef REQUIRE_PLUGIN
#tryinclude <tf2itemsinfo>

#define REQUIRE_PLUGIN
#include <tf2items_giveweapon>

#define MY_WEAPON_ID 9090

#if !defined _tf2itemsinfo_included
new TF2ItemSlot 8;
#endif

public Plugin:myinfo =
{
    
name "[TF2] Pyro Battle",
    
author "You",
    
description "A gamemode where pyros fight each others.",
    
version "1.1",
    
url "http://forums.alliedmods.net/showthread.php?t=203225"
};

public 
OnPluginStart()
{
    
HookEvent"post_inventory_application"OnHookedEvent );
    
HookEvent"player_spawn"OnHookedEvent );
}

public 
OnAllPluginsLoaded()
{
    
TF2Items_CreateWeaponMY_WEAPON_ID"tf_weapon_syringegun_medic"5270910"280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10"300_true );
}

public 
OnPostInventoryApplicationAndPlayerSpawnHandle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
    new 
iClient GetClientOfUserIdGetEventInthEvent"userid" ) )
    if( 
iClient <= || iClient MaxClients || !IsClientInGame(iClient/*|| !IsPlayerAlive(iClient)*/ )
        return;
    
    for( new 
iSlot 0iSlot _:TF2ItemSlotiSlot++ )
        
TF2_RemoveWeaponSlotiClientiSlot );
    
    
TF2_SetPlayerClassiClientTFClass_Pyro_true );
    
    
TF2Items_GiveWeaponiClientMY_WEAPON_ID );

EDIT:
oh
any reason why it's a tf_weapon_syringegun_medic with item ID #527 (widowmaker)?
It looks cool in the pyro's viewmodel.
__________________
My Plugins
Modified Plugins:
Building Spawner
Monster
It's Raining Men!
Tutorials:
Custom Gamemode

I DON'T DO PLUGIN REQUESTS.
Bitl is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 12-21-2012 , 05:34   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #5

Quote:
Originally Posted by Bitl View Post
Quote:
Originally Posted by Leonardo View Post
as longer as TF2Items GiveWeapon uses TF2ItemsInfo,
there's already TF2ItemSlot enum
so you have to check for it
Code:
#if !defined _tf2itemsinfo_included
new TF2ItemSlot = 8;
#endif
you also can crate weapon with TF2Items GiveWeapon' natives
Code:
public OnAllPluginsLoaded()
{
    TF2Items_CreateWeapon( 9990, "tf_weapon_syringegun_medic", 527, 0, 9, 10, "280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10", 300, _, true );
}
also someone told me do not use function/variable names longer than 32 chars.

so plugin should look like:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <tf2_stocks>

#define REQUIRE_EXTENSIONS
#define AUTOLOAD_EXTENSIONS
#include <tf2items>

#undef REQUIRE_PLUGIN
#tryinclude <tf2itemsinfo>

#define REQUIRE_PLUGIN
#include <tf2items_giveweapon>

#define MY_WEAPON_ID 9090

#if !defined _tf2itemsinfo_included
new TF2ItemSlot 8;
#endif

public Plugin:myinfo =
{
    
name "[TF2] Pyro Battle",
    
author "You",
    
description "A gamemode where pyros fight each others.",
    
version "1.1",
    
url "http://forums.alliedmods.net/showthread.php?t=203225"
};

public 
OnPluginStart()
{
    
HookEvent"post_inventory_application"OnHookedEvent );
    
HookEvent"player_spawn"OnHookedEvent );
}

public 
OnAllPluginsLoaded()
{
    
TF2Items_CreateWeaponMY_WEAPON_ID"tf_weapon_syringegun_medic"5270910"280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10"300_true );
}

public 
OnPostInventoryApplicationAndPlayerSpawnHandle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
    new 
iClient GetClientOfUserIdGetEventInthEvent"userid" ) )
    if( 
iClient <= || iClient MaxClients || !IsClientInGame(iClient/*|| !IsPlayerAlive(iClient)*/ )
        return;
    
    for( new 
iSlot 0iSlot _:TF2ItemSlotiSlot++ )
        
TF2_RemoveWeaponSlotiClientiSlot );
    
    
TF2_SetPlayerClassiClientTFClass_Pyro_true );
    
    
TF2Items_GiveWeaponiClientMY_WEAPON_ID );

EDIT:
oh
any reason why it's a tf_weapon_syringegun_medic with item ID #527 (widowmaker)?
It looks cool in the pyro's viewmodel.
why don't just use tf_weapon_shotgun_pyro then?
__________________
Leonardo is offline
Bitl
Senior Member
Join Date: Jul 2012
Old 12-21-2012 , 22:47   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #6

Quote:
Originally Posted by Leonardo View Post
why don't just use tf_weapon_shotgun_pyro then?
Then it would not have rapid fire.
__________________
My Plugins
Modified Plugins:
Building Spawner
Monster
It's Raining Men!
Tutorials:
Custom Gamemode

I DON'T DO PLUGIN REQUESTS.
Bitl is offline
Bitl
Senior Member
Join Date: Jul 2012
Old 01-26-2013 , 22:45   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #7

Quote:
Originally Posted by Leonardo View Post
as longer as TF2Items GiveWeapon uses TF2ItemsInfo,
there's already TF2ItemSlot enum
so you have to check for it
Code:
#if !defined _tf2itemsinfo_included
new TF2ItemSlot = 8;
#endif
you also can crate weapon with TF2Items GiveWeapon' natives
Code:
public OnAllPluginsLoaded()
{
    TF2Items_CreateWeapon( 9990, "tf_weapon_syringegun_medic", 527, 0, 9, 10, "280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10", 300, _, true );
}
also someone told me do not use function/variable names longer than 32 chars.

so plugin should look like:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <tf2_stocks>

#define REQUIRE_EXTENSIONS
#define AUTOLOAD_EXTENSIONS
#include <tf2items>

#undef REQUIRE_PLUGIN
#tryinclude <tf2itemsinfo>

#define REQUIRE_PLUGIN
#include <tf2items_giveweapon>

#define MY_WEAPON_ID 9090

#if !defined _tf2itemsinfo_included
new TF2ItemSlot 8;
#endif

public Plugin:myinfo =
{
    
name "[TF2] Pyro Battle",
    
author "You",
    
description "A gamemode where pyros fight each others.",
    
version "1.1",
    
url "http://forums.alliedmods.net/showthread.php?t=203225"
};

public 
OnPluginStart()
{
    
HookEvent"post_inventory_application"OnHookedEvent );
    
HookEvent"player_spawn"OnHookedEvent );
}

public 
OnAllPluginsLoaded()
{
    
TF2Items_CreateWeaponMY_WEAPON_ID"tf_weapon_syringegun_medic"5270910"280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10"300_true );
}

public 
OnPostInventoryApplicationAndPlayerSpawnHandle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
    new 
iClient GetClientOfUserIdGetEventInthEvent"userid" ) )
    if( 
iClient <= || iClient MaxClients || !IsClientInGame(iClient/*|| !IsPlayerAlive(iClient)*/ )
        return;
    
    for( new 
iSlot 0iSlot _:TF2ItemSlotiSlot++ )
        
TF2_RemoveWeaponSlotiClientiSlot );
    
    
TF2_SetPlayerClassiClientTFClass_Pyro_true );
    
    
TF2Items_GiveWeaponiClientMY_WEAPON_ID );

EDIT:
oh
any reason why it's a tf_weapon_syringegun_medic with item ID #527 (widowmaker)?
Here is a fixed version of the code above:

Code:
#pragma semicolon 1

#include <sourcemod>
#include <tf2_stocks>

#define REQUIRE_EXTENSIONS
#define AUTOLOAD_EXTENSIONS
#include <tf2items>

#undef REQUIRE_PLUGIN
#tryinclude <tf2itemsinfo>

#define REQUIRE_PLUGIN
#include <tf2items_giveweapon>

#define BATTLE_RIFLE_ID 9090

#if !defined _tf2itemsinfo_included
new TF2ItemSlot = 8;
#endif

public Plugin:myinfo =
{
    name = "[TF2] Pyro Battle",
    author = "Bitl",
    description = "A gamemode where pyros fight each others.",
    version = "1.1",
    url = "http://forums.alliedmods.net/showthread.php?t=203225"
};

public OnPluginStart()
{
    HookEvent( "post_inventory_application", OnPostInventoryApplicationAndPlayerSpawn );
    HookEvent( "player_spawn", OnPostInventoryApplicationAndPlayerSpawn );
}

public OnAllPluginsLoaded()
{
    TF2Items_CreateWeapon( BATTLE_RIFLE_ID, "tf_weapon_syringegun_medic", 527, 0, 9, 10, "280 ; 1 ; 6 ; 1.45 ; 31 ; 3 ; 32 ; 1 ; 2 ; 1.4 ; 125 ; -10", 300, _, true );
}

public OnPostInventoryApplicationAndPlayerSpawn( Handle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
    new iClient = GetClientOfUserId( GetEventInt( hEvent, "userid" ) );
    if( iClient <= 0 || iClient > MaxClients || !IsClientInGame(iClient) /*|| !IsPlayerAlive(iClient)*/ )
        return;
    
    for( new iSlot = 0; iSlot < _:TF2ItemSlot; iSlot++ )
        TF2_RemoveWeaponSlot( iClient, iSlot );
    
    TF2_SetPlayerClass( iClient, TFClass_Pyro, _, true );
    
    TF2Items_GiveWeapon( iClient, BATTLE_RIFLE_ID );
}
__________________
My Plugins
Modified Plugins:
Building Spawner
Monster
It's Raining Men!
Tutorials:
Custom Gamemode

I DON'T DO PLUGIN REQUESTS.
Bitl is offline
Alurict
Junior Member
Join Date: Feb 2013
Old 02-16-2013 , 06:54   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #8

Just wondering, would there be a simple way to detect which class the user selected and force them to equip items for that class? Perhaps with TF2_GetPlayerClass?

This way the user can still pick their class, but not customize the class loadout.

I'm pretty new at all this stuff, so just curious. Thanks!

Edit: I tried the following code change to no avail:
PHP Code:
    if (TF2_GetPlayerClass(iClient)&TFClass_Scout)
    {
        
TF2Items_GiveWeapon(iClient9990);
        
TF2Items_GiveWeapon(iClient9989);
    } 

Last edited by Alurict; 02-16-2013 at 07:24.
Alurict is offline
Alurict
Junior Member
Join Date: Feb 2013
Old 02-16-2013 , 07:29   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #9

Scratch that, I figured it out. New to all this code so I'm guessing around at syntax haha.

PHP Code:
    if (TF2_GetPlayerClass(iClient) == TFClass_Scout)
    {
        
TF2Items_GiveWeapon(iClient9990);
        
TF2Items_GiveWeapon(iClient9989);
    } 
Then, you'd just have to include a statement for every class with the items you want it them to use and it works wonders.

Thanks for the helpful post! =]

Last edited by Alurict; 02-16-2013 at 08:24.
Alurict is offline
Unreal1
AlliedModders Donor
Join Date: Dec 2010
Old 12-22-2012 , 10:12   Re: [TF2 + TF2Items + TF2Items GiveWeapon] How to make a custom gamemode
Reply With Quote #10

Why are you going through 8 slots? Aren't there only 4?
Unreal1 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 15:05.


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