Raised This Month: $59 Target: $400
 14% 

Check if player has grenade/equip on spawn


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MatoBoost
Junior Member
Join Date: Apr 2016
Old 03-31-2019 , 17:14   Check if player has grenade/equip on spawn
Reply With Quote #1

Hello, I have a plugin (I modified HexVips a little bit) where I give all players grenades + healthshot and defuse kit on spawn, but the problem is that if someone survives with grenades and respawns, grenades stay on the ground. I wanted to prevent this, so I started digging a bit on the internet, and after some time came up with this:

Code:
public Action tDelayLife(Handle timer, any iUserId)
{
	int client = GetClientOfUserId(iUserId);
	
	if (!IsValidClient(client, false, false))
		return Plugin_Continue;
	
	SetEntProp(client, Prop_Send, "m_ArmorValue", cv_fVipSpawnArmour.IntValue);
	SetEntProp(client, Prop_Send, "m_bHasHelmet", 1);
	
	if(GetEntProp(!client, Prop_Data, "m_iAmmo", _, 11))
	GivePlayerItem(client, "weapon_hegrenade");
	
	if(GetEntProp(!client, Prop_Data, "m_iAmmo", _, 12))
	GivePlayerItem(client, "weapon_flashbang");
	
	if(GetEntProp(!client, Prop_Data, "m_iAmmo", _, 13))
	GivePlayerItem(client, "weapon_smokegrenade");
	
	if(GetEntProp(!client, Prop_Data, "m_iAmmo", _, 14))
	GivePlayerItem(client, "weapon_molotov");
	
	GivePlayerItem(client, "weapon_tagrenade");
	
	GivePlayerItem(client, "weapon_healthshot");
	
	int iSpawnHealth = GetClientHealth(client);
	SetEntityHealth(client, iSpawnHealth + cv_iVipSpawnHP.IntValue);
	return Plugin_Continue;
}
Now the problem is, I do not know how to do this for tactical grenade and healthshot. I found the values for grenades here on forums.

I also did this for defuse kit
Code:
	if (cv_bVipDefuser.BoolValue && GetClientTeam(client) == CS_TEAM_CT && !GetEntProp(client, Prop_Send, "m_bHasDefuser"))
	{
		GivePlayerItem(client, "item_defuser");
	}
I added !GetEntProp(client, Prop_Send, "m_bHasDefuser") into original if, will this work ?
MatoBoost is offline
Ilusion9
Senior Member
Join Date: Jun 2018
Location: Romania
Old 03-31-2019 , 17:44   Re: Check if player has grenade/equip on spawn
Reply With Quote #2

To give defuser:

PHP Code:

SetEntProp
(clientProp_Send"m_bHasDefuser"true); 
Remove his grenades first, then equip him.
__________________

Last edited by Ilusion9; 03-31-2019 at 17:44.
Ilusion9 is offline
MatoBoost
Junior Member
Join Date: Apr 2016
Old 03-31-2019 , 18:55   Re: Check if player has grenade/equip on spawn
Reply With Quote #3

Quote:
Originally Posted by Ilusion9 View Post
To give defuser:

PHP Code:

SetEntProp
(clientProp_Send"m_bHasDefuser"true); 
Remove his grenades first, then equip him.
Alright, I will try this, thanks! Also about removing grenades, how do I do that ? To be honest I started with SourcePawn just today, I just have some experience from C, so far I only edited easy lines of code.
MatoBoost is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 03-31-2019 , 19:20   Re: Check if player has grenade/equip on spawn
Reply With Quote #4

Quote:
Originally Posted by MatoBoost View Post
Alright, I will try this, thanks! Also about removing grenades, how do I do that ? To be honest I started with SourcePawn just today, I just have some experience from C, so far I only edited easy lines of code.

Just for example, without isclientingame check

PHP Code:

public void OnPluginStart()
{
    
HookEvent("round_end"RoundEndEventHookMode_Pre);
}


public 
Action:RoundEnd(Handle:event, const String:name[], bool:dontBroadcast

    for( new 
client=1client<=MaxClientsclient++)
    {
        new 
3;
        {  
            new 
ent
             
            while((
ent GetPlayerWeaponSlot(clienti)) != -1
            { 
                
RemovePlayerItem(clientent); 
                
AcceptEntityInput(ent"Kill");
            } 
        } 
    }    

farawayf is offline
Ilusion9
Senior Member
Join Date: Jun 2018
Location: Romania
Old 04-01-2019 , 06:16   Re: Check if player has grenade/equip on spawn
Reply With Quote #5

PHP Code:
void RemoveClientGrenades(int client)
{
      
int ent = -1;  
              
      while ((
ent GetPlayerWeaponSlot(clientCS_SLOT_GRENADE)) != -1)  // #include <cstrike> for CS_SLOT_GRENADE
      
{  
            
RemovePlayerItem(clientent);
            
RemoveEntity(ent);
      }

__________________

Last edited by Ilusion9; 04-01-2019 at 06:17.
Ilusion9 is offline
MatoBoost
Junior Member
Join Date: Apr 2016
Old 04-06-2019 , 11:26   Re: Check if player has grenade/equip on spawn
Reply With Quote #6

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

public Plugin:myinfo = 
{
	name = "Grenade strip VIP",
	author = "MatoBoost",
	description = "Removes grenades at the end of the round for VIP",
	version = "0.1",
	url = "http://games-town.eu"
}

public OnPluginStart(){
}

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

	int client = GetClientOfUserId(GetEventInt(event, "userid"))	
	int ent = -1;  
	
	for(int i = 1; i <= MaxClients; i++){
		if(((CheckCommandAccess(client, "", ADMFLAG_RESERVATION)) == 1) && IsClientInGame(i)){
		
			while ((ent = GetPlayerWeaponSlot(client, CS_SLOT_GRENADE)) != -1)
			{
				RemovePlayerItem(client, ent);
				RemoveEntity(ent);
			}
	
		}
	}
}
I've managed to make this plugin, but it does not work properly, it removes grenades only for one player (and sometimes not even that), how do I fix this please ?
MatoBoost is offline
MasterMind420
Veteran Member
Join Date: Nov 2010
Old 04-06-2019 , 11:50   Re: Check if player has grenade/equip on spawn
Reply With Quote #7

[QUOTE=MatoBoost;2646550]
Code:
#include <cstrike>
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

public Plugin:myinfo = 
{
	name = "Grenade strip VIP",
	author = "MatoBoost",
	description = "Removes grenades at the end of the round for VIP",
	version = "0.1",
	url = "http://games-town.eu"
}

public OnPluginStart(){
}

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

	int client = GetClientOfUserId(GetEventInt(event, "userid"))	
	int ent = -1;  
	
	for(int i = 1; i <= MaxClients; i++){
		if(((CheckCommandAccess(client, "", ADMFLAG_RESERVATION)) == 1) && IsClientInGame(i)){
		
			while ((ent = GetPlayerWeaponSlot(client, CS_SLOT_GRENADE)) != -1)
			{
				RemovePlayerItem(client, ent);
				RemoveEntity(ent);
			}
	
		}
	}
}
Removing entities on Round_End event is a bad idea...instead do everything your trying to do during player_activate event...if the game your doing has it. Player Spawn would work but doesn't just fire at the beginning of rounds. Player activate fires once per player when they first connect each round. Or just use player spawn event with a delay timer. Just check when the player spawns what weapons they have and adjust accordingly...Also use RemovePlayerItem(client,ent); as well as AcceptEntityInput(ent, "Kill");...i never use RemoveEntity... I'm guessing your having issues because your doing it at the end of the round...some players may not make it thru the loop. I've had weird behavior like that happen trying to do some things within round_end...also no need for that while loop...its overkill for what your doing...simply check the playerweaponslot has a grenade...if it does remove it like i showed u.
MasterMind420 is offline
MasterMind420
Veteran Member
Join Date: Nov 2010
Old 04-06-2019 , 11:55   Re: Check if player has grenade/equip on spawn
Reply With Quote #8

Code:
			if(GetPlayerWeaponSlot(client, CS_SLOT_GRENADE)) != -1)
			{
				RemovePlayerItem(client, ent);
				AcceptEntityInput(client, "Kill");
			}
                        else
                        {
                               GiveGrenade or whatever u want...
                        }
Also Round_End does not have any userid or client info at all...so the client = part at the top won't work
MasterMind420 is offline
Ilusion9
Senior Member
Join Date: Jun 2018
Location: Romania
Old 04-06-2019 , 12:58   Re: Check if player has grenade/equip on spawn
Reply With Quote #9

PHP Code:

public void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    if (
client)
    {
        if (
CheckCommandAccess(client""ADMFLAG_RESERVATIONtrue))
        {
            
RemoveClientGrenades(client);
        }
    }
}

void RemoveClientGrenades(int client)
{
    
int ent = -1;
    
    while ((
ent GetPlayerWeaponSlot(clientCS_SLOT_GRENADE)) != -1)
    {
        
RemovePlayerItem(clientent);
        
RemoveEntity(ent);
    }

Use the new syntax.
round_end it's a general thing, it's not like player_death, player_spawn, player_hurt etc, so it doesn't have "userid" param.
__________________

Last edited by Ilusion9; 04-06-2019 at 13:00.
Ilusion9 is offline
MatoBoost
Junior Member
Join Date: Apr 2016
Old 04-06-2019 , 14:06   Re: Check if player has grenade/equip on spawn
Reply With Quote #10

Thank you for your help and explanation guys, hopefully it will work this time ^^ Also learned something new, so thanks for that aswell!

I use HexVips plugin, where I added a couple of lines that give grenades and vest+helm to players, and it's slightly delayed (I think I set it to 0.5 sec after player spawn):
Code:
public Action tDelayLife(Handle timer, any iUserId)
{
	int client = GetClientOfUserId(iUserId);
	
	if (!IsValidClient(client, false, false))
		return Plugin_Continue;
	
	SetEntProp(client, Prop_Send, "m_ArmorValue", cv_fVipSpawnArmour.IntValue);
	SetEntProp(client, Prop_Send, "m_bHasHelmet", 1);
	
	GivePlayerItem(client, "weapon_hegrenade");
	GivePlayerItem(client, "weapon_flashbang");
	GivePlayerItem(client, "weapon_smokegrenade");
	GivePlayerItem(client, "weapon_molotov");
	GivePlayerItem(client, "weapon_tagrenade");
	GivePlayerItem(client, "weapon_healthshot");
	
	int iSpawnHealth = GetClientHealth(client);
	SetEntityHealth(client, iSpawnHealth + cv_iVipSpawnHP.IntValue);
	return Plugin_Continue;
}
So when players spawn they will have their grenades removed, and after a slight delay they will get them back, hopefully ^^
MatoBoost 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 10:31.


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