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

Solved Is there a better way to give multiple grenades?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kashinoda
Member
Join Date: Dec 2017
Old 06-22-2019 , 22:12   Is there a better way to give multiple grenades?
Reply With Quote #1

I have a plugin that gives players a specific number of decoy grenades when the round starts.

Is there a way to do this without looping or timers? Currently I have this, which works fine:

PHP Code:
public void EquipPlayersDecoy(Event event, const char[] namebool dontBroadcast)
{
   for (
int iClient 1iClient <= MaxClientsiClient++)
    {
        if (
IsClientConnected(iClient) && IsClientInGame(iClient))
        {
            
Client_RemoveWeapon(iClient"weapon_decoy");
            
test[iClient][1] = 0;
            
CreateTimer(0.1GiveDecoysiClientTIMER_REPEAT); 
        }
    }
}

public 
Action GiveDecoys(Handle timerany client)
{   
    if (
test[client][1] == iDecoyAmount)
    {    
        return 
Plugin_Stop;
    }
    
GivePlayerItem(client"weapon_decoy"0);
    
test[client][1] ++;
    return 
Plugin_Continue;

I did try a standard for loop but the server times out with large values.
__________________

Last edited by Kashinoda; 06-24-2019 at 19:29.
Kashinoda is offline
Wyon
Junior Member
Join Date: Mar 2018
Old 06-23-2019 , 10:14   Re: Is there a better way to give multiple grenades?
Reply With Quote #2

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

public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
	CreateTimer(0.5, GiveGrenades, event.GetInt("userid"));
}

public Action GiveGrenades(Handle timer, any data)
{
	int iClient = GetClientOfUserId(data);
	if (IsClientInGame(iClient) && IsPlayerAlive(iClient))
	{
		GivePlayerItem(iClient, "weapon_decoy");
		SetEntProp(iClient, Prop_Send, "m_iAmmo", 25, _, 18);
	}
}
Attached Images
File Type: jpg Annotation 2019-06-23 171430.jpg (5.5 KB, 48 views)
Wyon is offline
Kashinoda
Member
Join Date: Dec 2017
Old 06-23-2019 , 16:17   Re: Is there a better way to give multiple grenades?
Reply With Quote #3

Quote:
Originally Posted by Wyon View Post
Code:
public void OnPluginStart()
{
	HookEvent("player_spawn", Event_PlayerSpawn);
}

public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
	CreateTimer(0.5, GiveGrenades, event.GetInt("userid"));
}

public Action GiveGrenades(Handle timer, any data)
{
	int iClient = GetClientOfUserId(data);
	if (IsClientInGame(iClient) && IsPlayerAlive(iClient))
	{
		GivePlayerItem(iClient, "weapon_decoy");
		SetEntProp(iClient, Prop_Send, "m_iAmmo", 25, _, 18);
	}
}
Didn't consider using SetEntProp, thank you!

Works great, what is the 18 doing here? (the Element)
__________________

Last edited by Kashinoda; 06-23-2019 at 16:20.
Kashinoda is offline
Wyon
Junior Member
Join Date: Mar 2018
Old 06-23-2019 , 22:39   Re: Is there a better way to give multiple grenades?
Reply With Quote #4

Quote:
Works great, what is the 18 doing here? (the Element)
It's index in m_iAmmo table, all player ammunition count is stored in that property

Last edited by Wyon; 06-23-2019 at 22:41.
Wyon is offline
Kashinoda
Member
Join Date: Dec 2017
Old 06-24-2019 , 15:07   Re: Is there a better way to give multiple grenades?
Reply With Quote #5

Quote:
Originally Posted by Wyon View Post
It's index in m_iAmmo table, all player ammunition count is stored in that property
Thank you!

HE Grenade 14
Smoke 16
Molotov 17
Decoy 18
Snowball 25
Flashbang 15
Tag 22
Health Shot 21

How I found grenade offsets/indexes:

PHP Code:
#include <sourcemod>
#include <smlib>

char sItems[][][] = 
{
    { 
"weapon_snowball""Snowball:" },
    { 
"weapon_hegrenade""HE Grenade:" },
    { 
"weapon_smokegrenade""Smoke:" },
    { 
"weapon_flashbang""Flashbang:" },
    { 
"weapon_tagrenade""Tag Grenade:" },
    { 
"weapon_decoy""Decoy:" },
    { 
"weapon_molotov""Molotov:" },
    { 
"weapon_healthshot""Healthshot:" },
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("g_index"test"Show Grenade Index");
}

public 
Action test(int clientint args)
{
for (
int i 0sizeof(sItems); i++)
{
    
GivePlayerItem(clientsItems[i][0], 0);
    for (
int iOffsetLookup 0iOffsetLookup 29iOffsetLookup++)
    {
        
int iAmmo GetEntProp(clientProp_Send"m_iAmmo"_iOffsetLookup);
        if (
iAmmo 0)
            {
                
PrintToChat(client"%s %i"sItems[i][1], iOffsetLookup );
                
SetEntProp(clientProp_Send"m_iAmmo"0_iOffsetLookup);
                
Client_RemoveWeapon(clientsItems[i][0]);
            }                
        }
    }        

__________________

Last edited by Kashinoda; 06-24-2019 at 16:05.
Kashinoda 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:53.


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