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

[CS:GO] Remove All Weapons on Spawn


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Pavelas
Junior Member
Join Date: Oct 2016
Old 11-05-2017 , 16:57   [CS:GO] Remove All Weapons on Spawn
Reply With Quote #1

Hello guys,

I have a few problems with Client_RemoveAllWeapons() function.

Requirement: I would like to reset player weapons and money on spawn.

1st Problem: Why do we need to create a timer with small delay to remove all player weapons and give default weapons? (Otherwise it does not work)

Solution:
PHP Code:
mp_backup_round_file ""
mp_backup_round_file_last ""
mp_backup_round_file_pattern ""
mp_backup_round_auto "0" 
2nd Problem: If player drop weapon on round end a few ms before respawn, he will get this weapon next round. (It is hard to abuse, but sometimes it happens)

Maybe you have any idea how to solve this problem?
What is the best approach how I can implement this functionality?


Code:
PHP Code:

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

public 
Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast) {
    
int client GetClientOfUserId(event.GetInt("userid"));
    
ResetPlayer(client);
}

public 
void ResetPlayer(int client) {
    if (!
IsClientConnected(client) || !IsClientInGame(client))
        return;

    
Client_RemoveAllWeapons(client"weapon_c4");

    
SetEntProp(clientProp_Send"m_bHasHelmet"0);
    
SetEntProp(clientProp_Send"m_ArmorValue"0);
    
SetEntProp(clientProp_Send"m_iAccount"800);

    if (
GetClientTeam(client) == CS_TEAM_T) {
        
GivePlayerItem(client"weapon_knife_t");
        
GivePlayerItem(client"weapon_glock");
    }

    if (
GetClientTeam(client) == CS_TEAM_CT) {
        
GivePlayerItem(client"weapon_knife");
        
GivePlayerItem(client"weapon_hkp2000");
    }

Thank you!

Last edited by Pavelas; 11-05-2017 at 18:55.
Pavelas is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-05-2017 , 17:24   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #2

Try using the round_start event. This fires after player_spawn.
__________________
Neuro Toxin is offline
Pavelas
Junior Member
Join Date: Oct 2016
Old 11-05-2017 , 17:57   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #3

But in this case we will need to loop all players, is it good approach to use loops?
Sorry for stupid question, in ECMAScript people are trying to avoid loops.
Pavelas is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 11-05-2017 , 18:06   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #4

How about something like that:

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

public 
Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast) {
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    if (!
IsClientConnected(client) || !IsClientInGame(client))
        return;
    
    
CreateTimer(0.01ResetPlayerclientTIMER_FLAG_NO_MAPCHANGE);
    
    
SetEntProp(clientProp_Send"m_bHasHelmet"0);
    
SetEntProp(clientProp_Send"m_ArmorValue"0);
    
SetEntProp(clientProp_Send"m_iAccount"800);

    if (
GetClientTeam(client) == CS_TEAM_T) {
        
GivePlayerItem(client"weapon_knife_t");
        
GivePlayerItem(client"weapon_glock");
    }
    else if (
GetClientTeam(client) == CS_TEAM_CT) {
        
GivePlayerItem(client"weapon_knife");
        
GivePlayerItem(client"weapon_hkp2000");
    }
    
}

public 
Action ResetPlayer(Handle timerint client) {
    
Client_RemoveAllWeapons(client"weapon_c4");

P.S: I'm not sure if 0.01 is possible.
__________________

Last edited by PinHeaDi; 11-05-2017 at 18:13.
PinHeaDi is offline
Pavelas
Junior Member
Join Date: Oct 2016
Old 11-05-2017 , 18:14   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #5

Thank you very much for quick response! I will try this solution, but maybe it is possible to implement this feature without timer?

P.S. This function does not work without timer with this event.
PHP Code:
SetEntProp(clientProp_Send"m_iAccount"800); 
Pavelas is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 11-05-2017 , 18:18   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #6

Try this without a timer:

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

public 
Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast) {
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    if (!
IsClientConnected(client) || !IsClientInGame(client))
        return;
    
    
Client_RemoveAllWeapons(client"weapon_c4");
    
    if (
GetClientTeam(client) == CS_TEAM_T) {
        
GivePlayerItem(client"weapon_knife_t");
        
GivePlayerItem(client"weapon_glock");
    }
    else if (
GetClientTeam(client) == CS_TEAM_CT) {
        
GivePlayerItem(client"weapon_knife");
        
GivePlayerItem(client"weapon_hkp2000");
    }
    
    
SetEntProp(clientProp_Send"m_iAccount"800);
    
SetEntProp(clientProp_Send"m_bHasHelmet"0);
    
SetEntProp(clientProp_Send"m_ArmorValue"0);

or

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

public 
Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast) {
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    if (!
IsClientConnected(client) || !IsClientInGame(client))
        return;
    
    
SetEntProp(client);
    
RemoveWeapons(client);
}


public 
void RemoveWeapons(int client)
{
    
Client_RemoveAllWeapons(client"weapon_c4");
    if (
GetClientTeam(client) == CS_TEAM_T) {
        
GivePlayerItem(client"weapon_knife_t");
        
GivePlayerItem(client"weapon_glock");
    }
    else if (
GetClientTeam(client) == CS_TEAM_CT) {
        
GivePlayerItem(client"weapon_knife");
        
GivePlayerItem(client"weapon_hkp2000");
    }
}

public 
void SetEntProp(int client)
{
    
SetEntProp(clientProp_Send"m_iAccount"800);
    
SetEntProp(clientProp_Send"m_bHasHelmet"0);
    
SetEntProp(clientProp_Send"m_ArmorValue"0);

__________________

Last edited by PinHeaDi; 11-05-2017 at 18:26.
PinHeaDi is offline
Pavelas
Junior Member
Join Date: Oct 2016
Old 11-05-2017 , 18:35   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #7

Thank you for your response, however money did not change next round on spawn.
Pavelas is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 11-05-2017 , 18:48   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #8

Quote:
Originally Posted by Pavelas View Post
Thank you for your response, however money did not change next round on spawn.
How about that:

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

public 
Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast) {
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    if (!
IsValidClient(client))
        return;
    
    
SetEntProp(client);
    
RemoveWeapons(client);
}


public 
void RemoveWeapons(int client)
{
    
Client_RemoveAllWeapons(client"weapon_c4");
    if (
GetClientTeam(client) == CS_TEAM_T) {
        
GivePlayerItem(client"weapon_knife_t");
        
GivePlayerItem(client"weapon_glock");
    }
    else if (
GetClientTeam(client) == CS_TEAM_CT) {
        
GivePlayerItem(client"weapon_knife");
        
GivePlayerItem(client"weapon_hkp2000");
    }
}

public 
void SetEntProp(int client)
{
    
CreateTimer(0.01ResetPlayerclientTIMER_FLAG_NO_MAPCHANGE);
    
    
SetEntProp(clientProp_Send"m_bHasHelmet"0);
    
SetEntProp(clientProp_Send"m_ArmorValue"0);
}

public 
Action ResetPlayer(Handle timerint client) {
    
SetEntProp(clientProp_Send"m_iAccount"800); 
}  

stock bool IsValidClient(int client) { 
    return (
<= client <= MaxClients && IsClientInGame(client)); 

It has a time though.
__________________
PinHeaDi is offline
Pavelas
Junior Member
Join Date: Oct 2016
Old 11-05-2017 , 18:51   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #9

Thank you very much for your help, however the solution was very stupid.

You need to have these CVAR's:
PHP Code:
mp_backup_round_file ""
mp_backup_round_file_last ""
mp_backup_round_file_pattern ""
mp_backup_round_auto "0" 
In this case we can reset player money and weapons directly on player_spawn hook.

However I think that that 2nd Problem still exists and somehow we need to write extra code to solve this problem.
Pavelas is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-05-2017 , 19:06   Re: [CS:GO] Remove All Weapons on Spawn
Reply With Quote #10

Quote:
Originally Posted by Pavelas View Post
But in this case we will need to loop all players, is it good approach to use loops?
Sorry for stupid question, in ECMAScript people are trying to avoid loops.
Yes. Looping players is fine. You need to move away from the player_spawn approach to resolve your issues.
__________________
Neuro Toxin 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 20:51.


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