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

[CSGO] no stack grenades


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sHoC
Senior Member
Join Date: Nov 2015
Location: Italy
Old 09-23-2017 , 06:38   [CSGO] no stack grenades
Reply With Quote #1

Hello guys, I have this plugin that is givin to every player a pack of grenades at spawn and there is a weird bug, the grenades are stacking, I mean you can have mutiple grenades , flashbangs, molotov, can someone edit this source cod to prevent the stack of grenades.

Code:
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0"
new Handle:gs_Cvar_Enable = INVALID_HANDLE
new Handle:gs_Cvar_hegrenade = INVALID_HANDLE
new Handle:gs_Cvar_decoy = INVALID_HANDLE
new Handle:gs_Cvar_molotov = INVALID_HANDLE

public Plugin:myinfo = 
{
	name = "Grenades On Spawn",
	author = "Tair",
	description = "Gives Grenades On Spawn (Decoy , Smoke , HeGrenade ,Molotov)",
	version = "1.1",
	url = "Www.sourcemod.net"
}

public OnPluginStart() 
{
	HookEvent("player_spawn", Event_PlayerSpawn);
        CreateConVar("sm_gs_version", PLUGIN_VERSION, "Version of the Plugin", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
        gs_Cvar_Enable = CreateConVar("sm_gs_enabled", "1", "Enables or Disables the Plugin", FCVAR_PLUGIN);
        gs_Cvar_molotov = CreateConVar("sm_gs_molotov", "1", "Enables or Disables Molotov");
        gs_Cvar_hegrenade = CreateConVar("sm_gs_hegrenade", "1", "Enables or Disables HeGrenade");
        gs_Cvar_decoy = CreateConVar("sm_gs_decoy", "1", "Enables or Disables Flashbang");
}


public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{

	new client = GetClientOfUserId(GetEventInt(event, "userid"));

	if (GetConVarInt(gs_Cvar_Enable))
	{
	PrintToChat(client, " \x04[SM] \x03You Received Grenades !");

	if (GetConVarInt(gs_Cvar_molotov))
	{
	GivePlayerItem(client, "weapon_molotov");
        }

	if (GetConVarInt(gs_Cvar_hegrenade))
	{
	GivePlayerItem(client, "weapon_hegrenade");
        }

	if (GetConVarInt(gs_Cvar_decoy))
	{
	GivePlayerItem(client, "weapon_decoy");
        }
	}
}
__________________
sHoC is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 09-23-2017 , 06:43   Re: [CSGO] no stack grenades
Reply With Quote #2

What do you want exactly?

1 grenade randomly chosen between smoke/flashbang/molotov/he/decoy for each player?
__________________

Last edited by micapat; 09-23-2017 at 06:46.
micapat is offline
sHoC
Senior Member
Join Date: Nov 2015
Location: Italy
Old 09-23-2017 , 09:03   Re: [CSGO] no stack grenades
Reply With Quote #3

Quote:
Originally Posted by micapat View Post
What do you want exactly?

1 grenade randomly chosen between smoke/flashbang/molotov/he/decoy for each player?
no.. I want players get only, grenade, decoy and molo, sometimes they are getting 2xgrenades, 3decoys, molo, I dont want to get more then 3 nades
__________________
sHoC is offline
sneaK
SourceMod Moderator
Join Date: Feb 2015
Location: USA
Old 09-23-2017 , 10:58   Re: [CSGO] no stack grenades
Reply With Quote #4

That's probably because the plugin isn't checking if they already have that grenade already or not.
__________________
sneaK is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 09-23-2017 , 11:33   Re: [CSGO] no stack grenades
Reply With Quote #5

check if player is alive first
8guawong is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 09-23-2017 , 12:42   Re: [CSGO] no stack grenades
Reply With Quote #6

Try this:

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls  required

public Plugin myinfo 
{
    
name        "Grenades On Spawn",
    
author      "Tair",
    
description "Give grenades on spawn (Decoy, HeGrenade, Molotov)",
    
version     "2.0",
    
url         "www.sourcemod.net"
}

ConVar gl_cvar_enable;
ConVar gl_cvar_enable_hegrenade;
ConVar gl_cvar_enable_molotov;
ConVar gl_cvar_enable_decoy;

public 
void OnPluginStart() 
{
    
CreateConVar("sm_gs_version""2.0""Version of the plugin"FCVAR_SPONLY FCVAR_REPLICATED FCVAR_NOTIFY);
    
    
gl_cvar_enable           CreateConVar("sm_gs_enabled",   "1""Enable / Disable the plugin");
    
gl_cvar_enable_hegrenade CreateConVar("sm_gs_hegrenade""1""Enable / Disable the he grenade");
    
gl_cvar_enable_molotov   CreateConVar("sm_gs_molotov",   "1""Enable / Disable the molotov");
    
gl_cvar_enable_decoy     CreateConVar("sm_gs_decoy",     "1""Enable / Disable the decoy");
}

public 
void OnClientPutInServer(int iClient)
{
    
SDKHook(iClientSDKHook_SpawnPostOnPlayerSpawnPost);
}

public 
void OnPlayerSpawnPost(int iPlayer)
{
    if (
gl_cvar_enable.BoolValue && IsPlayerAlive(iPlayer))
    {
        if (
gl_cvar_enable_hegrenade.BoolValue && GetEntProp(iPlayerProp_Data"m_iAmmo"_14) == 0)
        {
            
GivePlayerItem(iPlayer"weapon_hegrenade");
        }
        
        if (
gl_cvar_enable_molotov.BoolValue && GetEntProp(iPlayerProp_Data"m_iAmmo"_17) == 0)
        {
            
GivePlayerItem(iPlayer"weapon_molotov");
        }

        if (
gl_cvar_enable_decoy.BoolValue && GetEntProp(iPlayerProp_Data"m_iAmmo"_18) == 0)
        {
            
GivePlayerItem(iPlayer"weapon_decoy");
        }
        
        
PrintToChat(iPlayer" \x04[SM] \x03You received grenades!");
    }

__________________
micapat is offline
sHoC
Senior Member
Join Date: Nov 2015
Location: Italy
Old 09-23-2017 , 20:52   Re: [CSGO] no stack grenades
Reply With Quote #7

Quote:
Originally Posted by micapat View Post
Try this:

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls  required

public Plugin myinfo 
{
    
name        "Grenades On Spawn",
    
author      "Tair",
    
description "Give grenades on spawn (Decoy, HeGrenade, Molotov)",
    
version     "2.0",
    
url         "www.sourcemod.net"
}

ConVar gl_cvar_enable;
ConVar gl_cvar_enable_hegrenade;
ConVar gl_cvar_enable_molotov;
ConVar gl_cvar_enable_decoy;

public 
void OnPluginStart() 
{
    
CreateConVar("sm_gs_version""2.0""Version of the plugin"FCVAR_SPONLY FCVAR_REPLICATED FCVAR_NOTIFY);
    
    
gl_cvar_enable           CreateConVar("sm_gs_enabled",   "1""Enable / Disable the plugin");
    
gl_cvar_enable_hegrenade CreateConVar("sm_gs_hegrenade""1""Enable / Disable the he grenade");
    
gl_cvar_enable_molotov   CreateConVar("sm_gs_molotov",   "1""Enable / Disable the molotov");
    
gl_cvar_enable_decoy     CreateConVar("sm_gs_decoy",     "1""Enable / Disable the decoy");
}

public 
void OnClientPutInServer(int iClient)
{
    
SDKHook(iClientSDKHook_SpawnPostOnPlayerSpawnPost);
}

public 
void OnPlayerSpawnPost(int iPlayer)
{
    if (
gl_cvar_enable.BoolValue && IsPlayerAlive(iPlayer))
    {
        if (
gl_cvar_enable_hegrenade.BoolValue && GetEntProp(iPlayerProp_Data"m_iAmmo"_14) == 0)
        {
            
GivePlayerItem(iPlayer"weapon_hegrenade");
        }
        
        if (
gl_cvar_enable_molotov.BoolValue && GetEntProp(iPlayerProp_Data"m_iAmmo"_17) == 0)
        {
            
GivePlayerItem(iPlayer"weapon_molotov");
        }

        if (
gl_cvar_enable_decoy.BoolValue && GetEntProp(iPlayerProp_Data"m_iAmmo"_18) == 0)
        {
            
GivePlayerItem(iPlayer"weapon_decoy");
        }
        
        
PrintToChat(iPlayer" \x04[SM] \x03You received grenades!");
    }

with your version, players dosent get any grenades
__________________
sHoC is offline
Zeisen
Member
Join Date: Nov 2016
Location: Republic of Korea
Old 09-23-2017 , 21:27   Re: [CSGO] no stack grenades
Reply With Quote #8

Quote:
Originally Posted by sHoC View Post
with your version, players dosent get any grenades
Try Prop_Data to Prop_Send. might work.
Zeisen is offline
Deven
AlliedModders Donor
Join Date: Jun 2009
Old 09-24-2017 , 04:25   Re: [CSGO] no stack grenades
Reply With Quote #9

Here try this version

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

#define PLUGIN_AUTHOR "Deven"
#define PLUGIN_VERSION "1.1"

#pragma newdecls required

bool b_lateload;

EngineVersion g_Game;

public Plugin myinfo = 
{
	name = "Grenades",
	author = PLUGIN_AUTHOR,
	description = "Gives Grenades On Spawn",
	version = PLUGIN_VERSION,
	url = "www.prgaming.net"
};

public APLRes AskPluginLoad2(Handle myself, bool late, char []error, int err_max)
{
	b_lateload = late;
	
	return APLRes_Success;
}

    public void OnPluginStart(){
    	g_Game = GetEngineVersion();
	if(g_Game != Engine_CSGO)
	{
		SetFailState("This plugin is for CSGO only.");	
	}
	CreateConVar("sm_vipnade_version", PLUGIN_VERSION, "Version", FCVAR_DONTRECORD | FCVAR_REPLICATED | FCVAR_SPONLY);
	HookEvent("player_spawn", Event_PlayerSpawn);
	ServerCommand("sm_rcon ammo_grenade_limit_total 7"); /* for some reason these are locked cvars every map change they go back to default values.....!*/
	ServerCommand("sm_rcon ammo_grenade_limit_default 2");
	ServerCommand("sm_rcon mp_t_default_grenades 0");
	ServerCommand("sm_rcon mp_ct_default_grenades 0");
	if (b_lateload)
	{
		for (int i = 1; i <= MaxClients; i++)
		{
			HookEvent("player_spawn", Event_PlayerSpawn);
		}
	}
}

    public void OnMapStart(){
	ServerCommand("sm_rcon ammo_grenade_limit_total 7"); /* for some reason these are locked cvars every map change they go back to default values.....!*/
	ServerCommand("sm_rcon ammo_grenade_limit_default 2");
	ServerCommand("sm_rcon mp_t_default_grenades 0");
	ServerCommand("sm_rcon mp_ct_default_grenades 0");
}



public Action Event_PlayerSpawn(Handle event, const char []name, bool dontBroadcast)
{
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	if(IsClientInGame(client) && IsPlayerAlive(client) && (GetUserFlagBits(client) & ADMFLAG_GENERIC) && (GetClientTeam(client) == CS_TEAM_CT)){
	GivePlayerItem(client, "weapon_healthshot");
	GivePlayerItem(client, "weapon_healthshot");
	GivePlayerItem(client, "weapon_healthshot");
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_smokegrenade");
	GivePlayerItem(client, "weapon_tagrenade");
	GivePlayerItem(client, "weapon_tagrenade");
	GivePlayerItem(client, "weapon_incgrenade");
	GivePlayerItem(client, "weapon_taser");
	return Plugin_Handled;
}
	
	if(IsClientInGame(client) && IsPlayerAlive(client) && (GetUserFlagBits(client) & ADMFLAG_GENERIC) && (GetClientTeam(client) == CS_TEAM_T)){
	GivePlayerItem(client, "weapon_healthshot");
	GivePlayerItem(client, "weapon_healthshot");
	GivePlayerItem(client, "weapon_healthshot");
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_smokegrenade");
	GivePlayerItem(client, "weapon_tagrenade");
	GivePlayerItem(client, "weapon_tagrenade");
	GivePlayerItem(client, "weapon_molotov");
	GivePlayerItem(client, "weapon_taser");
	return Plugin_Handled;
}
	
	if(IsClientInGame(client) && IsPlayerAlive(client) && (GetClientTeam(client) == CS_TEAM_CT)){
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_incgrenade");
	return Plugin_Handled;
}
	
	if(IsClientInGame(client) && IsPlayerAlive(client) && (GetClientTeam(client) == CS_TEAM_T)){
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_molotov");
	return Plugin_Handled;
}
	return Plugin_Continue;
}
Edit to your liking.

Last edited by Deven; 09-24-2017 at 18:42. Reason: Cleaned up old code & add lateload support
Deven is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 09-24-2017 , 06:19   Re: [CSGO] no stack grenades
Reply With Quote #10

Quote:
Originally Posted by sHoC View Post
with your version, players dosent get any grenades
I tested it and it's working as expected.

Check the value of these cvars ("sm_cvar" "x"):
sm_gs_enabled
sm_gs_hegrenade
sm_gs_molotov
sm_gs_decoy

They should be equal to 1. Otherwise it means you modify them in one of your .cfg.
__________________
micapat 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 08:37.


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