Raised This Month: $32 Target: $400
 8% 

Solved Need some correction in code for giving nades


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-17-2017 , 10:02   Need some correction in code for giving nades
Reply With Quote #1

Made a simple code for giving nades for support with another mod but its not working here is the code:-
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <hamsandwich>
#include <fun>

#define PLUGIN "FreeNadesGiver"
#define VERSION "1.0"
#define AUTHOR "TheSpaniard"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""Fwd_PlayerSpawn_Post"1);
    
register_clcmd("say /nade""give_nades")
}

public 
Fwd_PlayerSpawn_Post(id)
{
    if(
is_user_alive(id) && !is_user_bot(id))
    {
        return 
PLUGIN_CONTINUE
    
}
    
set_task(15.0"give_nades"0__"b")
    return 
PLUGIN_CONTINUE
}

public 
give_nades(id
{
    
give_item(id"weapon_hegranade")
    
cs_set_user_bpammo(idCSW_HEGRENADE2)
    
give_item(id"weapon_smokegranade")
    
cs_set_user_bpammo(idCSW_SMOKEGRENADE2)
    
give_item(id"weapon_flashbang")
    
cs_set_user_bpammo(idCSW_FLASHBANG4)
    return 
PLUGIN_HANDLED

Any Help Appreciated.
The Spaniard.
__________________
And I Am Back.

Last edited by TheSpaniard; 09-17-2017 at 11:59. Reason: Solved
TheSpaniard is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-17-2017 , 10:22   Re: Need some correction in code for giving nades
Reply With Quote #2

Quote:
Originally Posted by TheSpaniard View Post
Made a simple code for giving nades for support with another mod but its not working here is the code:-
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <hamsandwich>
#include <fun>

#define PLUGIN "FreeNadesGiver"
#define VERSION "1.0"
#define AUTHOR "TheSpaniard"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""Fwd_PlayerSpawn_Post"1);
    
register_clcmd("say /nade""give_nades")
}

public 
Fwd_PlayerSpawn_Post(id)
{
    if(
is_user_alive(id) && !is_user_bot(id))
    {
        return 
PLUGIN_CONTINUE
    
}
    
set_task(15.0"give_nades"0__"b")
    return 
PLUGIN_CONTINUE
}

public 
give_nades(id
{
    
give_item(id"weapon_hegranade")
    
cs_set_user_bpammo(idCSW_HEGRENADE2)
    
give_item(id"weapon_smokegranade")
    
cs_set_user_bpammo(idCSW_SMOKEGRENADE2)
    
give_item(id"weapon_flashbang")
    
cs_set_user_bpammo(idCSW_FLASHBANG4)
    return 
PLUGIN_HANDLED

Any Help Appreciated.
The Spaniard.
Use the ResetHud event. Also, if you want the task to repeat every 15 seconds it's better to check if user has the weapon and check it's ammo. For example, in the 1st case, for weapon_hegrenade, u might want to check if user has it and if the bpammo is 2.The weapon name might be wrong as well, I guess it's weapon_hegrenade and not weapon_hegranade. To check if the user has the weapon use user_has_weapon. And finally, if you want a repeating task you must better define a task, for example #define TASKID 1450 and on the task replace 0 with TASKID+id. On the task, in case of public give_nades(taskid) the id would be taskid - TASKID. Before creating the task on player spawn, you must first check if it exists. On client disconenct, u must remove the task.
https://www.amxmodx.org/api/amxmodx/user_has_weapon

For example, when checking for bpammo you could do:

Code:
if (cs_get_user_bpammo(id, CSW_HEGRENADE) != 2)         cs_set_user_bpammo(id, CSW_HEGRENADE, 2)

Last edited by DarthMan; 09-17-2017 at 10:28.
DarthMan is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-17-2017 , 10:26   Re: Need some correction in code for giving nades
Reply With Quote #3

Quote:
Originally Posted by DarthMan View Post
Use the ResetHud event. Also, if you want the task to repeat every 15 seconds it's better to check if user has the weapon and check it's ammo. For example, in the 1st case, for weapon_hegrenade, u might want to check if user has it and if the bpammo is 2.The weapon name might be wrong as well, I guess it's weapon_hegrenade and not weapon_hegranade. And finally, to check if the user has the weapon use user_has_weapon.

https://www.amxmodx.org/api/amxmodx/user_has_weapon

For example, when checking for bpammo you could do:

Code:
if (cs_get_user_bpammo(id, CSW_HEGRENADE) != 2)         cs_set_user_bpammo(id, CSW_HEGRENADE, 2)
thanks man will do the foll and will post the result
__________________
And I Am Back.
TheSpaniard is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-17-2017 , 10:29   Re: Need some correction in code for giving nades
Reply With Quote #4

Quote:
Originally Posted by TheSpaniard View Post
thanks man will do the foll and will post the result
No problem, I updated the post a little bit.
DarthMan is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-17-2017 , 10:39   Re: Need some correction in code for giving nades
Reply With Quote #5

Quote:
Originally Posted by DarthMan View Post
No problem, I updated the post a little bit.
What is ResetHud event.

Quote:
Originally Posted by DarthMan View Post
On the task, in case of public give_nades(taskid) the id would be taskid - TASKID. Before creating the task on player spawn, you must first check if it exists. On client disconenct, u must remove the task.
didnt understand this.
__________________
And I Am Back.
TheSpaniard is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-17-2017 , 10:45   Re: Need some correction in code for giving nades
Reply With Quote #6

Quote:
Originally Posted by TheSpaniard View Post
What is ResetHud event.


didnt understand this.
Code:
register_event("ResetHUD", "forwardResetHud", "be"); public forwardResetHud(i_Client) { // your code goes here }

Last edited by DarthMan; 09-17-2017 at 10:46.
DarthMan is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 09-17-2017 , 10:46   Re: Need some correction in code for giving nades
Reply With Quote #7

Explain what you are trying to do.

PHP Code:
if(is_user_alive(id) && !is_user_bot(id))
    {
        return 
PLUGIN_CONTINUE
    
}
    
set_task(15.0"give_nades"0__"b")
    return 
PLUGIN_CONTINUE 
Why this?
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-17-2017 , 10:49   Re: Need some correction in code for giving nades
Reply With Quote #8

Quote:
Originally Posted by wickedd View Post
Explain what you are trying to do.

PHP Code:
if(is_user_alive(id) && !is_user_bot(id))
    {
        return 
PLUGIN_CONTINUE
    
}
    
set_task(15.0"give_nades"0__"b")
    return 
PLUGIN_CONTINUE 
Why this?
Wanted to give the plugin admin flags but decided against it.
__________________
And I Am Back.
TheSpaniard is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 09-17-2017 , 10:59   Re: Need some correction in code for giving nades
Reply With Quote #9

Quote:
Originally Posted by wickedd View Post
Explain what you are trying to do.
And what game is this for?
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 09-17-2017 at 10:59.
wickedd is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-17-2017 , 11:00   Re: Need some correction in code for giving nades
Reply With Quote #10

Quote:
Originally Posted by wickedd View Post
Explain what you are trying to do.

PHP Code:
if(is_user_alive(id) && !is_user_bot(id))
    {
        return 
PLUGIN_CONTINUE
    
}
    
set_task(15.0"give_nades"0__"b")
    return 
PLUGIN_CONTINUE 
Why this?
It must be if((!is_user_connected(id)) && (!is_user_bot(id)))

It's still good to check if the user is conencted, jsut in case. On TFC for example this check must be there, else it would sometimes throw an error in the game console, I am not sure about CS. And I believe that he didn't want to set a repetitive task, just a task that happens once every spawn after 15 secs, but even then, using a task check and removing on client disconnect would be usefull in case he leaves before the 15secs elapsed since last spawn/respawn.
DarthMan 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 00:17.


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