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

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 , 07:23   Re: Need some correction in code for giving nades
Reply With Quote #21

Quote:
Originally Posted by TheSpaniard View Post
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.
Well, problem with Ham_Spawn is that as it's name suggests, it's to be executed on client spawn. But the fucntion is executed after the client connects, and for whatever reason on mods like Half-Life for example it would not work on plugin_init. I ahven't tested it with CS yet, but on games like HL1, OP4, TFC u are instantly spawned and the Spawn is executed on 2nd spawn and then from 3rd etc the Respawn is executed. So in that case ResetHud might be a better optin. There's also a trick to use Ham_Spawn on precache, for entities it works perfectly. But since I'm not yer very familiar with CS I don't know much about how those functions work. I'll start working on a private money plug-in soon for my server so I'd require the use of the Spawn function and then I'll be able to see how well it works on CS. Also, a repetitive task is not required if you only want to give the player the required ammo once. It's usefull only if u want to give the ammo to him once every 15secs.

About the money plug-in, i'll be doing something that would decrease the amount of money u get, u won't lose cash on death, but earning cash will be a bit more complicated, like %50/kill or mby 100, to make it more complicated and attract more players and stuff. Money will be stored by SteamID for return, and there's gonna be other ways of earning money, like donating $5 for $1000. This way I'll be able to keep the host alive and sicne ppl would like to have better weapons, they would pay tog et them faster or spend more time on the server. I then also need to think of a way to make the weapons free for the once they bought them, the only method might be orpheu in this case, I guess.

Last edited by DarthMan; 09-18-2017 at 07:26.
DarthMan is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-18-2017 , 07:37   Re: Need some correction in code for giving nades
Reply With Quote #22

Quote:
Originally Posted by TheSpaniard View Post
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.
If you follow this HudMessage tutorial, u'll notice that it uses ResetHud as well.

https://www.youtube.com/watch?v=MTX09_f6R5U&t=4s
DarthMan is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-18-2017 , 09:00   Re: Need some correction in code for giving nades
Reply With Quote #23

Quote:
Originally Posted by DarthMan View Post
Well, problem with Ham_Spawn is that as it's name suggests, it's to be executed on client spawn. But the fucntion is executed after the client connects, and for whatever reason on mods like Half-Life for example it would not work on plugin_init. I ahven't tested it with CS yet, but on games like HL1, OP4, TFC u are instantly spawned and the Spawn is executed on 2nd spawn and then from 3rd etc the Respawn is executed. So in that case ResetHud might be a better optin. There's also a trick to use Ham_Spawn on precache, for entities it works perfectly. But since I'm not yer very familiar with CS I don't know much about how those functions work. I'll start working on a private money plug-in soon for my server so I'd require the use of the Spawn function and then I'll be able to see how well it works on CS. Also, a repetitive task is not required if you only want to give the player the required ammo once. It's usefull only if u want to give the ammo to him once every 15secs.

About the money plug-in, i'll be doing something that would decrease the amount of money u get, u won't lose cash on death, but earning cash will be a bit more complicated, like %50/kill or mby 100, to make it more complicated and attract more players and stuff. Money will be stored by SteamID for return, and there's gonna be other ways of earning money, like donating $5 for $1000. This way I'll be able to keep the host alive and sicne ppl would like to have better weapons, they would pay tog et them faster or spend more time on the server. I then also need to think of a way to make the weapons free for the once they bought them, the only method might be orpheu in this case, I guess.
you can use hamspawn with client_putinserver() & client_diconnect() as:-
PHP Code:
plugin_init()
{
RegisterHam(Ham_Spawn"player""Fwd_PlayerSpawn_Post"1);
}

public 
Fwd_PlayerSpawn_Post(id)
{
//your code here
}
//then with client_putinserver() we can check if the player is alive or not and set task
public client_putinserver(id)
{
    if(
is_user_connected(id)) 
        
set_task(15.0"FUNCTION"id__"b")
}
//then with client_diconnect() we can remove any task, so no need to check if task_exists
public client_disconnect(id)
{
    
remove_task(id);

so using hamspawn with client_putinserver() & client_diconnect() has triple advantage :-
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.
__________________
And I Am Back.
TheSpaniard is offline
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-18-2017 , 09:01   Re: Need some correction in code for giving nades
Reply With Quote #24

Quote:
Originally Posted by DarthMan View Post
If you follow this HudMessage tutorial, u'll notice that it uses ResetHud as well.

https://www.youtube.com/watch?v=MTX09_f6R5U&t=4s
what are you trying to say with this video you can read above why ham_spawn is better
__________________
And I Am Back.
TheSpaniard is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-18-2017 , 10:36   Re: Need some correction in code for giving nades
Reply With Quote #25

You never explained what are you trying to do


.
__________________
@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
TheSpaniard
Senior Member
Join Date: Jul 2017
Location: Hell
Old 09-18-2017 , 10:39   Re: Need some correction in code for giving nades
Reply With Quote #26

Quote:
Originally Posted by Natsheh View Post
You never explained what are you trying to do


.
Didnt you read the title or the code i posted?? it says giving nades.
__________________
And I Am Back.

Last edited by TheSpaniard; 09-18-2017 at 10:43.
TheSpaniard is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-18-2017 , 10:48   Re: Need some correction in code for giving nades
Reply With Quote #27

I read it altho you didnt clear out what are you trying to do.
__________________
@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
wickedd
Veteran Member
Join Date: Nov 2009
Old 09-18-2017 , 12:51   Re: Need some correction in code for giving nades
Reply With Quote #28

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

Edit:
Quote:
Originally Posted by TheSpaniard View Post
The code given by DearthMan is very efficient you can check it for yourself at My posted plugin
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 }
*/ 
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 09-18-2017 at 13:03.
wickedd is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 09-18-2017 , 14:21   Re: Need some correction in code for giving nades
Reply With Quote #29

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 }
*/ 
That's not my code, btw, I jsut gave hime some indications but he used Ham instead of ResetHUD.
DarthMan is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 09-18-2017 , 14:39   Re: Need some correction in code for giving nades
Reply With Quote #30

Quote:
Originally Posted by DarthMan View Post
That's not my code, btw, I jsut gave hime some indications but he used Ham instead of ResetHUD.
So what if he did? There's nothing wrong with giving players nades when they spawn, but in his plugin it's useless.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd 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 03:55.


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