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

Solved Need some correction in code for giving nades


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

Quote:
Originally Posted by wickedd View Post
And what game is this for?
cs 1.6
__________________
And I Am Back.
TheSpaniard is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-17-2017 , 11:09   Re: Need some correction in code for giving nades
Reply With Quote #12

Quote:
Originally Posted by TheSpaniard View Post
cs 1.6
Yeah I know, I was just saying about TFC. Normally, this should not be required because register_event contains the flags autoamtically and is oinly registered if the user is connected.
DarthMan is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-17-2017 , 11:17   Re: Need some correction in code for giving nades
Reply With Quote #13

Quote:
Originally Posted by DarthMan View Post
Yeah I know, I was just saying about TFC. Normally, this should not be required because register_event contains the flags autoamtically and is oinly registered if the user is connected.
is this right it is compiling without errors

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"
#define TASKID 1440

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("ResetHUD""forwardResetHud""be");
    
register_clcmd("say /nade""give_nades")
}

public 
forwardResetHud(i_Client)
{
    if(!(
get_user_flags(i_Client) & ADMIN_LEVEL_H))
    {
        return 
PLUGIN_HANDLED
    
}
    
set_task(15.0"give_nades"TASKID+i_Client__"b")
    return 
PLUGIN_CONTINUE
}

public 
give_nades(id
{
    new 
henade user_has_weapon(id4, -1)
    new 
heammo cs_get_user_bpammo(idCSW_HEGRENADE)
    new 
smokenade user_has_weapon(id9, -1)
    new 
smokeammo cs_get_user_bpammo(idCSW_SMOKEGRENADE)
    new 
flashnade user_has_weapon(id25, -1)
    new 
flashammo cs_get_user_bpammo(idCSW_FLASHBANG)
    if(
henade == && heammo << 2)
    {
        
cs_set_user_bpammo(idCSW_HEGRENADE2)
    }
    else
    {
        
give_item(id"weapon_hegrenade")
        
cs_set_user_bpammo(idCSW_HEGRENADE2)
    }
    if(
smokenade == && smokeammo << 2)
    {
        
cs_set_user_bpammo(idCSW_SMOKEGRENADE2)
    }
    else
    {
        
give_item(id"weapon_smokegrenade")
        
cs_set_user_bpammo(idCSW_SMOKEGRENADE2)
    }
    if(
flashnade == && flashammo << 2)
    {
        
cs_set_user_bpammo(idCSW_FLASHBANG4)
    }
    else
    {
        
give_item(id"weapon_flashbang")
        
cs_set_user_bpammo(idCSW_FLASHBANG4)
    }
    
    return 
PLUGIN_HANDLED

__________________
And I Am Back.
TheSpaniard is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-17-2017 , 11:38   Re: Need some correction in code for giving nades
Reply With Quote #14

Quote:
Originally Posted by TheSpaniard View Post
is this right it is compiling without errors

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"
#define TASKID 1440

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("ResetHUD""forwardResetHud""be");
    
register_clcmd("say /nade""give_nades")
}

public 
forwardResetHud(i_Client)
{
    if(!(
get_user_flags(i_Client) & ADMIN_LEVEL_H))
    {
        return 
PLUGIN_HANDLED
    
}
    
set_task(15.0"give_nades"TASKID+i_Client__"b")
    return 
PLUGIN_CONTINUE
}

public 
give_nades(id
{
    new 
henade user_has_weapon(id4, -1)
    new 
heammo cs_get_user_bpammo(idCSW_HEGRENADE)
    new 
smokenade user_has_weapon(id9, -1)
    new 
smokeammo cs_get_user_bpammo(idCSW_SMOKEGRENADE)
    new 
flashnade user_has_weapon(id25, -1)
    new 
flashammo cs_get_user_bpammo(idCSW_FLASHBANG)
    if(
henade == && heammo << 2)
    {
        
cs_set_user_bpammo(idCSW_HEGRENADE2)
    }
    else
    {
        
give_item(id"weapon_hegrenade")
        
cs_set_user_bpammo(idCSW_HEGRENADE2)
    }
    if(
smokenade == && smokeammo << 2)
    {
        
cs_set_user_bpammo(idCSW_SMOKEGRENADE2)
    }
    else
    {
        
give_item(id"weapon_smokegrenade")
        
cs_set_user_bpammo(idCSW_SMOKEGRENADE2)
    }
    if(
flashnade == && flashammo << 2)
    {
        
cs_set_user_bpammo(idCSW_FLASHBANG4)
    }
    else
    {
        
give_item(id"weapon_flashbang")
        
cs_set_user_bpammo(idCSW_FLASHBANG4)
    }
    
    return 
PLUGIN_HANDLED

Try < instead of <<, also replace public give_nades(id) with public give_nades(taskid) and on the enxt line after { type new id = taskid-TASKID. Before set_task(15.0, "give_nades", TASKID+i_Client, _, _, "b") do a if(!task_exists(TASKID+i_Client)).

For public client_disconnect(id) check if task exists, remove_task(TASKID+id).
Also, remvoe this: #include <hamsandwich> .

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

Quote:
Originally Posted by DarthMan View Post
Try < instead of <<, also replace public give_nades(id) with public give_nades(taskid) and on the enxt line after { type new id = taskid-TASKID. Before set_task(15.0, "give_nades", TASKID+i_Client, _, _, "b") do a if(!task_exists(TASKID+i_Client)).

For public client_disconnect(id) check if task exists, remove_task(TASKID+id).
Also, remvoe this: #include <hamsandwich> .
PHP Code:
/* Plugin generated by AMXX-Studio */

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

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

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("ResetHUD""forwardResetHud""be");
    
register_clcmd("say /nade""give_nades")
}

public 
forwardResetHud(i_Client)
{
    if((!(
get_user_flags(i_Client) & ADMIN_LEVEL_H)))
    {
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE
}

public 
client_putinserver(id)
{
    if(
is_user_connected(id)) 
        
set_task(15.0"give_nades"id TASKID)
}

public 
client_disconnect(id)
{
    
remove_task(id TASKID);
}

public 
give_nades(id
{
    new 
henade user_has_weapon(id TASKID4, -1)
    new 
heammo cs_get_user_bpammo(id TASKIDCSW_HEGRENADE)
    new 
smokenade user_has_weapon(id TASKID9, -1)
    new 
smokeammo cs_get_user_bpammo(id TASKIDCSW_SMOKEGRENADE)
    new 
flashnade user_has_weapon(id TASKID25, -1)
    new 
flashammo cs_get_user_bpammo(id TASKIDCSW_FLASHBANG)
    if(
henade == && heammo << 2)
    {
        
cs_set_user_bpammo(id TASKIDCSW_HEGRENADE2)
    }
    else
    {
        
give_item(id TASKID"weapon_hegrenade")
        
cs_set_user_bpammo(id TASKIDCSW_HEGRENADE2)
    }
    if(
smokenade == && smokeammo << 2)
    {
        
cs_set_user_bpammo(id TASKIDCSW_SMOKEGRENADE2)
    }
    else
    {
        
give_item(id TASKID"weapon_smokegrenade")
        
cs_set_user_bpammo(id TASKIDCSW_SMOKEGRENADE2)
    }
    if(
flashnade == && flashammo << 2)
    {
        
cs_set_user_bpammo(id TASKIDCSW_FLASHBANG4)
    }
    else
    {
        
give_item(id TASKID"weapon_flashbang")
        
cs_set_user_bpammo(id TASKIDCSW_FLASHBANG4)
    }
    
    return 
PLUGIN_HANDLED

This Worked for me
__________________
And I Am Back.
TheSpaniard is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-17-2017 , 11:56   Re: Need some correction in code for giving nades
Reply With Quote #16

Any Way thanks for your help man
__________________
And I Am Back.
TheSpaniard is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-17-2017 , 11:56   Re: Need some correction in code for giving nades
Reply With Quote #17

+karma for your help
__________________
And I Am Back.
TheSpaniard is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-18-2017 , 02:09   Re: Need some correction in code for giving nades
Reply With Quote #18

Quote:
Originally Posted by DarthMan View Post
Try < instead of <<, also replace public give_nades(id) with public give_nades(taskid) and on the enxt line after { type new id = taskid-TASKID. Before set_task(15.0, "give_nades", TASKID+i_Client, _, _, "b") do a if(!task_exists(TASKID+i_Client)).

For public client_disconnect(id) check if task exists, remove_task(TASKID+id).
Also, remvoe this: #include <hamsandwich> .

You do realize that what you are posting is a total bullshit....

Please if you dont know nothing just shush stop spreading the bullshit...
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-18-2017 , 02:13   Re: Need some correction in code for giving nades
Reply With Quote #19

Here you go...


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""Fwd_PlayerSpawn_Post"


public 
Fwd_PlayerSpawn_Post(id

    if(!
is_user_alive(id) || !(get_user_flags(id) & ADMIN_LEVEL_H)) 
    { 
        return 

    

    
set_task(1.0"give_nades"id
    return 



public 
give_nades(id)  
{
    if(!
is_user_alive(id)) return;
    
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

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 09-18-2017 at 02:23.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-18-2017 , 02:59   Re: Need some correction in code for giving nades
Reply With Quote #20

Quote:
Originally Posted by Natsheh View Post
Here you go...


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""Fwd_PlayerSpawn_Post"


public 
Fwd_PlayerSpawn_Post(id

    if(!
is_user_alive(id) || !(get_user_flags(id) & ADMIN_LEVEL_H)) 
    { 
        return 

    

    
set_task(1.0"give_nades"id
    return 



public 
give_nades(id)  
{
    if(!
is_user_alive(id)) return;
    
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

The code given by DearthMan is very efficient you can check it for yourself at My posted plugin
the code you posted is very small but it can result in crash as it wont check user ammo and add grenades every 15 seconds and if weapon strip is not included in any loaded plugin the player who did not die that round would have huge no of grenades at round start and server can crash. Although the edit you quoted is wrong but before that he gave me right directions.
__________________
And I Am Back.

Last edited by TheSpaniard; 09-18-2017 at 04:32.
TheSpaniard 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 21:33.


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