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

Solved give grenade to player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 06-10-2021 , 00:43   give grenade to player
Reply With Quote #1

hi! how to use fun's give_item() properly? I'm trying to give grenades to player when he throwing 'em but it gives me only flashbangs. Can someone help me and tell where are errors here?
Code:
#include <amxmodx>
#include <fun>
#include <csx>

new pCvar

public plugin_init() {
	register_plugin("infinite_grenades", "latest", "kww")
	pCvar = register_cvar("sv_testcvar", "1", FCVAR_SERVER)
}

public grenade_throw(id, gid, wid) {
	if(!get_pcvar_num(pCvar))
		return PLUGIN_HANDLED
	
	switch(wid) {
		case CSW_HEGRENADE: give_item(id, "weapon_hegrenade")
		case CSW_FLASHBANG: give_item(id, "weapon_flashbang")
		case CSW_SMOKEGRENADE: give_item(id, "weapon_smokegrenade")
	}
	
	return PLUGIN_CONTINUE
}

Last edited by kww; 06-11-2021 at 10:34.
kww is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-10-2021 , 11:00   Re: give grenade to player
Reply With Quote #2

are you getting any error logs?

EDIT: Honestly, i think you're using the wrong id to check which grenade u threw. Try using the second param of the native (gid).
__________________

Last edited by Napoleon_be; 06-10-2021 at 11:35.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 06-10-2021 , 21:34   Re: give grenade to player
Reply With Quote #3

Quote:
Originally Posted by Napoleon_be View Post
are you getting any error logs?

EDIT: Honestly, i think you're using the wrong id to check which grenade u threw. Try using the second param of the native (gid).
I think the 2nd param return the grenade entity id, not the weapon id so the 3rd param should be correct

Code:
/**  * Called after a grenade was thrown.  *  * @note Weapon id is one of CSW_HEGRENADE, CSW_SMOKEGRENADE or CSW_FLASHBANG.  *  * @param index     Client index  * @param greindex  Grenade entity index  * @param wId       Weapon id  *  * @noreturn  */ forward grenade_throw(index, greindex, wId);
__________________
My plugin:

Last edited by Celena Luna; 06-10-2021 at 21:38.
Celena Luna is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-11-2021 , 07:09   Re: give grenade to player
Reply With Quote #4

I was thinking the exact same thing, but it wouldn't be the first time a bug occurs. Wouldn't hurt to give it a try. and log your messages....
__________________

Last edited by Napoleon_be; 06-11-2021 at 07:09.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 06-11-2021 , 09:57   Re: give grenade to player
Reply With Quote #5

i think a small delay would be an easy fix for this
jimaway is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 06-11-2021 , 10:27   Re: give grenade to player
Reply With Quote #6

Quote:
Originally Posted by Napoleon_be View Post
are you getting any error logs?
nope

Quote:
Originally Posted by jimaway View Post
i think a small delay would be an easy fix for this
dunno why but it worked. but isn't it a workaround?

Last edited by kww; 06-11-2021 at 10:34.
kww is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 06-14-2021 , 00:42   Re: give grenade to player
Reply With Quote #7

Quote:
Originally Posted by kww View Post
dunno why but it worked. but isn't it a workaround?
Try to set Ammo to 2
I think because you can only carry 1 HE/Smoke so you can't get anymore than 1 since when throwing, it technically still carrying that nade.
PHP Code:
public grenade_throw(idgidwid)
{
    
cs_set_user_bpammo(idwid2);

__________________
My plugin:
Celena Luna is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 06-16-2021 , 08:36   Re: give grenade to player
Reply With Quote #8

Quote:
Originally Posted by Celena Luna View Post
Try to set Ammo to 2
I think because you can only carry 1 HE/Smoke so you can't get anymore than 1 since when throwing, it technically still carrying that nade.
PHP Code:
public grenade_throw(idgidwid)
{
    
cs_set_user_bpammo(idwid2);

it's not working
kww is offline
Crackhead69
Member
Join Date: Feb 2021
Old 06-16-2021 , 10:22   Re: give grenade to player
Reply With Quote #9

Quote:
Originally Posted by kww View Post
it's not working
It is working on my end without any problems.

And yes, as @Celena Luna said, the bpammo amount has to be 2 in order to work properly
Crackhead69 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-17-2021 , 08:33   Re: give grenade to player
Reply With Quote #10

Or a simple task would also work. Not sure what the best option is in this case though.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
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 15:25.


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