AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved give grenade to player (https://forums.alliedmods.net/showthread.php?t=332946)

kww 06-10-2021 00:43

give grenade to player
 
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
}


Napoleon_be 06-10-2021 11:00

Re: give grenade to player
 
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).

Celena Luna 06-10-2021 21:34

Re: give grenade to player
 
Quote:

Originally Posted by Napoleon_be (Post 2749436)
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);

Napoleon_be 06-11-2021 07:09

Re: give grenade to player
 
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....

jimaway 06-11-2021 09:57

Re: give grenade to player
 
i think a small delay would be an easy fix for this

kww 06-11-2021 10:27

Re: give grenade to player
 
Quote:

Originally Posted by Napoleon_be (Post 2749436)
are you getting any error logs?

nope

Quote:

Originally Posted by jimaway (Post 2749503)
i think a small delay would be an easy fix for this

dunno why but it worked. but isn't it a workaround?

Celena Luna 06-14-2021 00:42

Re: give grenade to player
 
Quote:

Originally Posted by kww (Post 2749510)
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);



kww 06-16-2021 08:36

Re: give grenade to player
 
Quote:

Originally Posted by Celena Luna (Post 2749676)
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

Crackhead69 06-16-2021 10:22

Re: give grenade to player
 
Quote:

Originally Posted by kww (Post 2749962)
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

Napoleon_be 06-17-2021 08:33

Re: give grenade to player
 
Or a simple task would also work. Not sure what the best option is in this case though.


All times are GMT -4. The time now is 22:57.

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