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

[FUN] Player out of range (0)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheLinxSWE
Junior Member
Join Date: Sep 2007
Old 10-25-2007 , 10:03   [FUN] Player out of range (0)
Reply With Quote #1

Hello.
I have made something for my server, an HP on Frag plugin (Feel free to use, but not publish under your name)

Anyway, I get errors.

Quote:
Originally Posted by Errors
L 10/23/2007 - 17:45:57: [FUN] Player out of range (0)
L 10/23/2007 - 17:45:57: [AMXX] Displaying debug trace (plugin "amx_healthonfrag.amxx")
L 10/23/2007 - 17:45:57: [AMXX] Run time error 10: native error (native "set_user_health")
L 10/23/2007 - 17:45:57: [AMXX] [0] amx_healthonfrag.sma::client_death (line 26)
The source:

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <fun> #define PLUGIN "Health on frag" #define VERSION "1.0" #define AUTHOR "TheLinx" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_cvar("amx_healthonfrag_enabled", "1")     register_cvar("amx_healthonfrag_health", "25")     register_cvar("amx_healthonfrag_health_max", "175")     register_cvar("amx_healthonfrag_health_extra_hs", "25")         register_event("DeathMsg", "client_death", "a", "1>0")     register_event("DeathMsg", "client_death_hs", "a", "3=1") } public client_death(id) { // Line 26     increase_hp(id, 0)     check_hp(id)     return PLUGIN_CONTINUE } public client_death_hs(id) {     new cvar_hpextraonhs = get_cvar_num("amx_healthonfrag_health_extra_hs")     increase_hp(id, cvar_hpextraonhs)     check_hp(id)     return PLUGIN_CONTINUE } public increase_hp(id, arg_extrahp) {     new id_health = get_user_health(id)     new cvar_healthonfrag = get_cvar_num("amx_healthonfrag_health")     set_user_health(id, id_health + cvar_healthonfrag + arg_extrahp) } public check_hp(id) {     new id_health = get_user_health(id)     new cvar_maxhealth = get_cvar_num("amx_healthonfrag_health_max")     if (id_health > cvar_maxhealth)     {         set_user_health(id, cvar_maxhealth)     } }

Please tell me what I am doing wrong!
TheLinxSWE is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 10-25-2007 , 10:15   Re: [FUN] Player out of range (0)
Reply With Quote #2

Make shure that the player is connected! if(!is_user_connected(id)) return; add this check in "increase_hp" and "check_hp" publics...at the top.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-25-2007 , 10:29   Re: [FUN] Player out of range (0)
Reply With Quote #3

Tha't not the matter Alka.

DeathMsg is a global event. Id can not be passed by this way.

Code:
public client_death() {     new killer = read_data( 1 );     new victim = read_data( 2 );    // }
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-25-2007 , 10:36   Re: [FUN] Player out of range (0)
Reply With Quote #4

Also client_death is the name of a csx forward, you should use another name for this event.

I would use pcvars and fakemeta.

Code:
#include <amxmodx> #include <fakemeta> #define PLUGIN "Health on frag" #define VERSION "1.0" #define AUTHOR "TheLinx" #define OFFSET_TEAM  114 #define user_team(%1)   get_pdata_int(%1, OFFSET_TEAM) // pcvars holders new healthonfrag_enabled, healthonfrag_health, healthonfrag_health_extra_hs, healthonfrag_health_max // max players var new g_max_clients public plugin_init() {          register_plugin(PLUGIN, VERSION, AUTHOR)              healthonfrag_enabled = register_cvar("amx_healthonfrag_enabled", "1")     healthonfrag_health = register_cvar("amx_healthonfrag_health", "0")     healthonfrag_health_extra_hs = register_cvar("amx_healthonfrag_health_extra_hs", "25")     healthonfrag_health_max = register_cvar("amx_healthonfrag_health_max", "175")     register_event("DeathMsg", "eDeathMsg", "a", "1>0") } public plugin_cfg() {     // get max players     g_max_clients = global_get(glb_maxClients) } public eDeathMsg()  // this is a global event so you need to check id's below {     if(!get_pcvar_num(healthonfrag_enabled)) // plugin is disabled         return     new killer = read_data(1)     if(killer > g_max_clients) // killer is not a player (entity)         return     new victim = read_data(2)     if(user_team(victim) == user_team(killer)) // team kill         return     new headshot = read_data(3)  // 1 = headshot, 0 = normal kill     new Float:health_to_give     switch(headshot)     {         case 0:health_to_give = get_pcvar_float(healthonfrag_health)         case 1:health_to_give = get_pcvar_float(healthonfrag_health_extra_hs)     }     if(!health_to_give)         return     new Float:health     pev(killer, pev_health, health)     new Float:max_health = get_pcvar_float(healthonfrag_health_max)     if(health == max_health)         return     if(max_health - health_to_give > health)         set_pev(killer, pev_health, health + health_to_give)     else         set_pev(killer, pev_health, max_health) }

Last edited by ConnorMcLeod; 10-25-2007 at 10:40.
ConnorMcLeod is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 10-25-2007 , 10:47   Re: [FUN] Player out of range (0)
Reply With Quote #5

Quote:
Originally Posted by arkshine View Post
Tha't not the matter Alka.

DeathMsg is a global event. Id can not be passed by this way.
Yeah, you'r right! lul...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
TheLinxSWE
Junior Member
Join Date: Sep 2007
Old 10-25-2007 , 11:40   Re: [FUN] Player out of range (0)
Reply With Quote #6

Thank you very much connorr!
(And thank you, Alka, and arkshine for helping out too!)

You should release that! Im just off to test it

I made some modifications to the code though, to make it neater. Here it is:

Code:
/******************************************************** *                     * *         Health on Frag   * *      By TheLinx ([email protected])    * *                     * *   Credits:               * *   connorr - Telling how to do all these FM thingys.   * *                     * ********************************************************/ #include <amxmodx> #include <fakemeta> #define PLUGIN "Health on Frag" #define VERSION "1.0" #define AUTHOR "TheLinx" #define OFFSET_TEAM  114 #define user_team(%1)   get_pdata_int(%1, OFFSET_TEAM) /* Set PCVars */ new pcvar_enabled, pcvar_health, pcvar_health_max, pcvar_health_extra_hs, pcvar_givehp_tk /* Other Variables */ new g_max_clients public plugin_init() { // Initiate the plugin.     register_plugin(PLUGIN, VERSION, AUTHOR)         /* Define PCVars */     pcvar_enabled =  register_cvar("amx_hponfrag_enabled", "1")     pcvar_health =    register_cvar("amx_hponfrag_health", "25")     pcvar_health_max =  register_cvar("amx_hponfrag_health_max", "175")     pcvar_health_extra_hs = register_cvar("amx_hponfrag_health_extra_hs", "25")     pcvar_givehp_tk =   register_cvar("amx_hponfrag_givehp_tk", "1")         /* Events */     register_event("DeathMsg", "event_death", "a", "1>0") } public plugin_cfg() { // On plugin load     g_max_clients = global_get(glb_maxClients) } public event_death() { // On frag     if (!get_pcvar_num(pcvar_enabled))         return // The plugin is disabled, cancel.         new id_killer = read_data(1)     if (id_killer > g_max_clients)         return // Killer is not a player, cancel.         new id_victim = read_data(2)     if (!get_pcvar_num(pcvar_givehp_tk))     { // Ignoring giving HP if it was a TK is enabled.         if (user_team(id_victim) == user_team(id_killer))             return // It was a TK, cancel.     }         new var_headshot = read_data(3) // Was it a HS?         new Float:var_hptogive     switch (var_headshot)     {         case 0: var_hptogive = get_pcvar_float(pcvar_health)         case 1: var_hptogive = get_pcvar_float(pcvar_health_extra_hs)     }         if (!var_hptogive)         return // Something went wrong, cancel.         new Float:id_killer_hp     pev(id_killer, pev_health, id_killer_hp)         new Float:var_maxhp = get_pcvar_float(pcvar_health_max)         if (id_killer_hp == var_maxhp)         return // The client have the maximum HP already, cancel.         if (var_maxhp - var_hptogive > id_killer_hp)         set_pev(id_killer, pev_health, id_killer_hp + var_hptogive)     else         set_pev(id_killer, pev_health, var_maxhp) }

I also added an CVar to set if you should abort the giving HP if it was a TK, pretty useful if you, like me, are running an FFA server ;)

Last edited by TheLinxSWE; 10-25-2007 at 11:41. Reason: Changing code a bit...
TheLinxSWE is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-25-2007 , 11:50   Re: [FUN] Player out of range (0)
Reply With Quote #7

Code:
    if (!var_hptogive)         return // Something went wrong, cancel.

You didn't understand this, in case you would give HP only for HS, and not for normal kills, cvar amx_hponfrag_health would be set to 0, then var_hptogive would be 0, so this -> if (!var_hptogive) would match.

I don't understand why you set both hp cvars to 25, in that case you don't have to check if it's a HS or not ;)

Quote:
Originally Posted by TheLinxSWE View Post
You should release that! Im just off to test it
http://forums.alliedmods.net/showthread.php?t=29196

Last edited by ConnorMcLeod; 10-25-2007 at 12:49.
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

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 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode