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

Solved Need some correction in code for giving nades


Post New Thread Reply   
 
Thread Tools Display Modes
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-18-2017 , 14:51   Re: Need some correction in code for giving nades
Reply With Quote #31

Quote:
Originally Posted by wickedd View Post
So what if he did? There's nothing wrong with giving players nades when they spawn, but in his plugin it's useless.
Yeah I see.
DarthMan is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-19-2017 , 00:58   Re: Need some correction in code for giving nades
Reply With Quote #32

Quote:
Originally Posted by wickedd View Post
Give some details like....
Who are you trying to give nades to?
When do you want them to receive them and how often?

Edit:

FYI..this is poorly coded
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)
    
RegisterHam(Ham_Spawn"player""Fwd_PlayerSpawn_Post"1);
    
register_clcmd("say /nade""give_nades")
}

public 
Fwd_PlayerSpawn_Post(id)
{
    if((!(
get_user_flags(id) & 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__"b")
}

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
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/ 
I was making a support plugin for my vip mod
and to answer your second question
delay is 15 seconds
__________________
And I Am Back.
TheSpaniard is offline
Old 09-19-2017, 01:16
TheSpaniard
This message has been deleted by TheSpaniard.
wickedd
Veteran Member
Join Date: Nov 2009
Old 09-19-2017 , 09:38   Re: Need some correction in code for giving nades
Reply With Quote #33

Quote:
Originally Posted by TheSpaniard View Post
and its advantages:-
1.with client_putinserver you can check if the player is alive or not and set task.
2.with client_disconnect you dont need to go through confusing task_exists() function and directly remove task.
3.hamspawn confirms compatibility with csdm and other respawn using plugins.

now you say its poorly coded can you give some optimizations or correction.
if yes, thank you in advance.
1. Checking if a player is alive in client_putinserver is useless. They will never alive there.

2. So what's your point? You probably don't even need a task but since you didn't answer my questions we'll never know.

3. What?? I don't understand what you're trying to say.

You are making a very simple plugin more complicated than it has to be.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-19-2017 , 10:30   Re: Need some correction in code for giving nades
Reply With Quote #34

FYI @TheSpaniard the one i posted hasnt any disadvantages its a simple plugin will never throw any error not like yours which you have wierd checks about the nades and idk what this condition must mean for you '<<' but its meanless

You either are stupid or idiot one of those for not accepting the reality
__________________
@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-19-2017 at 10:33.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 09-19-2017 , 16:39   Re: Need some correction in code for giving nades
Reply With Quote #35

Quote:
Originally Posted by TheSpaniard View Post
wickedd for your information
The code natesh posted :-
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

its disadvantages:-
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.

code suggested by darthman:-

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  

i made some changes in it:-
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
    
RegisterHam(Ham_Spawn"player""Fwd_PlayerSpawn_Post"1); 
    
register_clcmd("say /nade""give_nades"


public 
Fwd_PlayerSpawn_Post(id

    if((!(
get_user_flags(id) & 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__"b"


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 

and its advantages:-
1.with client_putinserver you can check if the player is alive or not and set task.
2.with client_disconnect you dont need to go through confusing task_exists() function and directly remove task.
3.hamspawn confirms compatibility with csdm and other respawn using plugins.

now you say its poorly coded can you give some optimizations or correction.
if yes, thank you in advance.
you should stop giving scripting advice, you're doing more damage than good
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
Old 09-20-2017, 03:45
TheSpaniard
This message has been deleted by TheSpaniard. Reason: Now Happy??
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:12.


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