AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Compiling won't stop or won't even move (https://forums.alliedmods.net/showthread.php?t=156839)

razieljohn619 05-12-2011 21:00

Compiling won't stop or won't even move
 
hey guys please help me with this i know you guys are good at this.. the compiling of this .sma won't stop..it even won't move a thng..what this plugin does is it emits a low hp hearbeat when you have less hp and also displays a sprite when you have low hp.the sound and sprite will only be shown/hear to those who have less hp like 30..
heres the code

PHP Code:

================================================================================*/ 

#include <amxmodx> 
#include <fakemeta> 
#include <cstrike> 

#define lowhp "mw2/mw2lowhp.spr 
/*================================================================================ 
 [Plugin Customization] 
=================================================================================*/ 

// Constants 
new const g_heartbeat[] = "player/heartbeat1.wav" 

/*============================================================================*/ 

new cvar_heartbeathp 
new time_show_set[5.0
new 
spr_current[5.0

public 
plugin_precache() 

    
precache_sound(g_heartbeat


public 
plugin_init() 

    
register_plugin("MW2 Low Hp""1.1""RazielJohn619."
     
    
register_event("Damage""event_damage""be""2>0"
    
register_event("DeathMsg""event_deathmsg""a"
    
register_event("ResetHUD""event_resethud""be"
    
register_event("Spectator""event_spectator""a"
     
    
cvar_heartbeathp register_cvar("heartbeat_hp""25"
     


public 
event_damage(id

    if (
get_user_health(id) > get_pcvar_num(cvar_heartbeathp) ) 
        return 
     
    
// * Replaced with emit_sound so players near us can hear it too * 
    //client_cmd(id, "spk %s", g_heartbeat) 
    //emit_sound(id, CHAN_STATIC, g_heartbeat, 0.0, 0.0, SND_STOP, PITCH_NORM)  
     
    
emit_sound(idCHAN_AUTOg_heartbeat1.0ATTN_NORM0PITCH_NORM
     
     
    if (
get_user_health(id) > get_pcvar_num(cvar_heartbeathp) ) 
          return 
    
//client_cmd(id, "show_spr", spr_lowhp) 
    //show_spr(id, set_show_time(5), spr_lowhp) 
    
set_task(0.1"show_spr"id
     
    new  
show_spr(mw2lowhp
    new  
hide_spr 


public 
event_deathmsg() 

    
emit_sound(read_data(2), CHAN_AUTOg_heartbeat1.0ATTN_NORMSND_STOPPITCH_NORM


public 
event_resethud(id

    
emit_sound(idCHAN_AUTOg_heartbeat1.0ATTN_NORMSND_STOPPITCH_NORM


public 
event_spectator() 

    
emit_sound(read_data(1), CHAN_AUTOg_heartbeat1.0ATTN_NORMSND_STOPPITCH_NORM


public 
show_spr(ididspr

    new 
sec_c get_systime() 
    
time_show_set[id] = sec_c 
     
    hide_spr
(idspr_current[id]) 
    
spr_current[id] = idspr 
     
    
new spr_name[33
        if (
idspr==1spr_name "mw2lowhp" 
            
if(!(pev(id,pev_button) & FL_ONGROUND)) 
    {     
        
message_begin(MSG_ONE,iconstatus,{0,0,0},id); 
        
write_byte(1); // status (0=hide, 1=show, 2=flash) 
        
write_string(spr_name); // sprite name 
        
message_end(); 
        
spr_current[id] = 




public 
hide_spr(ididspr

     
    new 
spr_name[33
        if (
idspr==1spr_name "mw2lowhp" 

     
    
if(!(pev(id,pev_button) & FL_ONGROUND)) 
    {     
        
message_begin(MSG_ONE,iconstatus,{0,0,0},id); 
        
write_byte(0); // status (0=hide, 1=show, 2=flash) 
        
write_string(spr_name); // sprite name 
        
message_end(); 
        
spr_current[id] = 
         


and heres the sprite that will be shown http://www.mediafire.com/?azqva78uwz9urih
please guys i want this code to be fix and compiled without anything wrong..

fysiks 05-12-2011 21:45

Re: Compiling won't stop or won't even move
 
The reason it was hung while compiling was that you tried to give an array a non-integer size. Once you fix this it will give you a million errors.

razieljohn619 05-13-2011 01:13

Re: Compiling won't stop or won't even move
 
Quote:

Originally Posted by fysiks (Post 1468327)
The reason it was hung while compiling was that you tried to give an array a non-integer size. Once you fix this it will give you a million errors.

ok i don't know what that part is could you correct that for me..i'm a noob with this..pls..

Hunter-Digital 05-13-2011 01:35

Re: Compiling won't stop or won't even move
 
Remove the "new" before calling show_spr() and hide_spr(), "new" is for creating variables.

Also fix your "mw2lowhp" define, you forgot the " at the end.

And another thing, I think you're lacking a } over there and you placed { instead of } at the end... it's hard to understand something when everything is randomly aligned, please indent your code.

razieljohn619 05-13-2011 06:41

Re: Compiling won't stop or won't even move
 
Quote:

Originally Posted by Hunter-Digital (Post 1468385)
Remove the "new" before calling show_spr() and hide_spr(), "new" is for creating variables.

Also fix your "mw2lowhp" define, you forgot the " at the end.

And another thing, I think you're lacking a } over there and you placed { instead of } at the end... it's hard to understand something when everything is randomly aligned, please indent your code.

the code should look like this right

PHP Code:

================================================================================*/ 

#include <amxmodx> 
#include <fakemeta> 
#include <cstrike> 

#define lowhp "mw2/mw2lowhp.spr" 
/*================================================================================ 
 [Plugin Customization] 
=================================================================================*/ 

// Constants 
new const g_heartbeat[] = "player/heartbeat1.wav" 

/*============================================================================*/ 

new cvar_heartbeathp 
new time_show_set[5.0
new 
spr_current[5.0

public 
plugin_precache() 

    
precache_sound(g_heartbeat


public 
plugin_init() 

    
register_plugin("MW2 Low Hp""1.1""RazielJohn619."
     
    
register_event("Damage""event_damage""be""2>0"
    
register_event("DeathMsg""event_deathmsg""a"
    
register_event("ResetHUD""event_resethud""be"
    
register_event("Spectator""event_spectator""a"
     
    
cvar_heartbeathp register_cvar("heartbeat_hp""25"
     


public 
event_damage(id

    if (
get_user_health(id) > get_pcvar_num(cvar_heartbeathp) ) 
        return 
     
    
// * Replaced with emit_sound so players near us can hear it too * 
    //client_cmd(id, "spk %s", g_heartbeat) 
    //emit_sound(id, CHAN_STATIC, g_heartbeat, 0.0, 0.0, SND_STOP, PITCH_NORM)  
     
    
emit_sound(idCHAN_AUTOg_heartbeat1.0ATTN_NORM0PITCH_NORM
     
     
    if (
get_user_health(id) > get_pcvar_num(cvar_heartbeathp) ) 
          return 
    
//client_cmd(id, "show_spr", spr_lowhp) 
    //show_spr(id, set_show_time(5), spr_lowhp) 
    
set_task(0.1"show_spr"id
     
    
show_spr(mw2lowhp
    
hide_spr 


public 
event_deathmsg() 

    
emit_sound(read_data(2), CHAN_AUTOg_heartbeat1.0ATTN_NORMSND_STOPPITCH_NORM


public 
event_resethud(id

    
emit_sound(idCHAN_AUTOg_heartbeat1.0ATTN_NORMSND_STOPPITCH_NORM


public 
event_spectator() 

    
emit_sound(read_data(1), CHAN_AUTOg_heartbeat1.0ATTN_NORMSND_STOPPITCH_NORM


public 
show_spr(ididspr

    new 
sec_c get_systime() 
    
time_show_set[id] = sec_c 
     
    hide_spr
(idspr_current[id]) 
    
spr_current[id] = idspr 
     
    
new spr_name[33
        if (
idspr==1spr_name "mw2lowhp" 
            
if(!(pev(id,pev_button) & FL_ONGROUND)) 
    {     
        
message_begin(MSG_ONE,iconstatus,{0,0,0},id); 
        
write_byte(1); // status (0=hide, 1=show, 2=flash) 
        
write_string(spr_name); // sprite name 
        
message_end(); 
        
spr_current[id] = 




public 
hide_spr(ididspr

     
    new 
spr_name[33
        if (
idspr==1spr_name "mw2lowhp" 

     
    
if(!(pev(id,pev_button) & FL_ONGROUND)) 
    {     
        
message_begin(MSG_ONE,iconstatus,{0,0,0},id); 
        
write_byte(0); // status (0=hide, 1=show, 2=flash) 
        
write_string(spr_name); // sprite name 
        
message_end(); 
        
spr_current[id] = 
         


and is the code of loading the sprite right? and is there any problems of this code? please I really want this plugin to work..

razieljohn619 05-13-2011 06:51

Re: Compiling won't stop or won't even move
 
sorry for double post..but the compiling is still not moving or won't stop..and what is that integer stuff said by fysiks..can someone fix that part for me..I don't know anything about that..

Hunter-Digital 05-13-2011 09:03

Re: Compiling won't stop or won't even move
 
No.

This is indented and (quickly) fixed, untested.

Code:

#include <amxmodx>
#include <fakemeta>
#include <cstrike>

/* define removed because it couldn't be used anyway */

new const g_heartbeat[] = "player/heartbeat1.wav"

new cvar_heartbeathp
new iconstatus // this variable was used but it wasn't created, so I did.

public plugin_precache()
{
    precache_sound(g_heartbeat)
}

public plugin_init()
{
    register_plugin("MW2 Low Hp", "1.1", "RazielJohn619.")

    register_event("Damage", "event_damage", "be", "2>0")
    register_event("DeathMsg", "event_deathmsg", "a")
    register_event("ResetHUD", "event_resethud", "be")
    register_event("Spectator", "event_spectator", "a")

    iconstatus = get_user_msgid("StatusIcon") // statusicon's id stored in iconstatus variable

    cvar_heartbeathp = register_cvar("heartbeat_hp", "25")
}

public event_damage(id)
{
    if(get_user_health(id) > get_pcvar_num(cvar_heartbeathp))
        return
   
    sound_heartbeat(id)
    show_spr(id)
    set_task(4.0, "hide_spr", id)
}

public event_deathmsg()
    sound_heartbeat(read_data(2))

public event_resethud(id)
    sound_heartbeat(id)

public event_spectator()
    sound_heartbeat(read_data(1))

public show_spr(id)
{
    message_begin(MSG_ONE_UNRELIABLE, iconstatus, _, id)
    write_byte(1) // status (0=hide, 1=show, 2=flash)
    write_string("dmg_rad"); // sprite name - can't be custom !!!
    write_byte(255) // R
    write_byte(0) // G
    write_byte(0) // B
    message_end()
}

public hide_spr(id)
{
    message_begin(MSG_ONE_UNRELIABLE, iconstatus, _, id)
    write_byte(0) // status (0=hide, 1=show, 2=flash)
    write_string("dmg_rad") // sprite name
    // colors not needed when hiding icon
    message_end()
}

sound_heartbeat(id)
    emit_sound(id, CHAN_AUTO, g_heartbeat, 1.0, ATTN_NORM, SND_STOP, PITCH_NORM)

The cause of your compiler stall may have been any of the fixes I made, even the first "=====..." which wasn't commented out could've been the issue.

Also, this:
Code:

if(!(pev(id,pev_button) & FL_ONGROUND))
Is stupid... why are you checking player's buttons against ONGROUND flag ? FL_* are for pev_flags and IN_* are for pev_button, you can find list of them in includes/hlsdk_const.inc.

You're also checking if player has above 25 hp twice... why ?!

And don't use MSG_ONE for unimportant stuff like an icon, in laggy conditions the server would force itself to send that and could crash players... so just use MSG_ONE_UNRELIABLE for all non-important messages.


EDIT:
Out of curiousity I progresively removed and re-compiled your code, it seems that your float value size for array was the issue, so don't use float as variable array size !

razieljohn619 05-13-2011 21:28

Re: Compiling won't stop or won't even move
 
Quote:

Originally Posted by Hunter-Digital (Post 1468536)
No.

This is indented and (quickly) fixed, untested.

Code:

#include <amxmodx>
#include <fakemeta>
#include <cstrike>

/* define removed because it couldn't be used anyway */

new const g_heartbeat[] = "player/heartbeat1.wav"

new cvar_heartbeathp
new iconstatus // this variable was used but it wasn't created, so I did.

public plugin_precache()
{
    precache_sound(g_heartbeat)
}

public plugin_init()
{
    register_plugin("MW2 Low Hp", "1.1", "RazielJohn619.")

    register_event("Damage", "event_damage", "be", "2>0")
    register_event("DeathMsg", "event_deathmsg", "a")
    register_event("ResetHUD", "event_resethud", "be")
    register_event("Spectator", "event_spectator", "a")

    iconstatus = get_user_msgid("StatusIcon") // statusicon's id stored in iconstatus variable

    cvar_heartbeathp = register_cvar("heartbeat_hp", "25")
}

public event_damage(id)
{
    if(get_user_health(id) > get_pcvar_num(cvar_heartbeathp))
        return
   
    sound_heartbeat(id)
    show_spr(id)
    set_task(4.0, "hide_spr", id)
}

public event_deathmsg()
    sound_heartbeat(read_data(2))

public event_resethud(id)
    sound_heartbeat(id)

public event_spectator()
    sound_heartbeat(read_data(1))

public show_spr(id)
{
    message_begin(MSG_ONE_UNRELIABLE, iconstatus, _, id)
    write_byte(1) // status (0=hide, 1=show, 2=flash)
    write_string("dmg_rad"); // sprite name - can't be custom !!!
    write_byte(255) // R
    write_byte(0) // G
    write_byte(0) // B
    message_end()
}

public hide_spr(id)
{
    message_begin(MSG_ONE_UNRELIABLE, iconstatus, _, id)
    write_byte(0) // status (0=hide, 1=show, 2=flash)
    write_string("dmg_rad") // sprite name
    // colors not needed when hiding icon
    message_end()
}

sound_heartbeat(id)
    emit_sound(id, CHAN_AUTO, g_heartbeat, 1.0, ATTN_NORM, SND_STOP, PITCH_NORM)

The cause of your compiler stall may have been any of the fixes I made, even the first "=====..." which wasn't commented out could've been the issue.

Also, this:
Code:

if(!(pev(id,pev_button) & FL_ONGROUND))
Is stupid... why are you checking player's buttons against ONGROUND flag ? FL_* are for pev_flags and IN_* are for pev_button, you can find list of them in includes/hlsdk_const.inc.

You're also checking if player has above 25 hp twice... why ?!

And don't use MSG_ONE for unimportant stuff like an icon, in laggy conditions the server would force itself to send that and could crash players... so just use MSG_ONE_UNRELIABLE for all non-important messages.


EDIT:
Out of curiousity I progresively removed and re-compiled your code, it seems that your float value size for array was the issue, so don't use float as variable array size !


thanks man..the .sma now is compiled and there is no error and I checked the code the the code..the line 36, 42, 45, 48, and 70 is an invalid function call, why is that?but compilation is fine..and is the showing of sprite still there? this sprite ..and thanks again man..

razieljohn619 05-13-2011 21:42

Re: Compiling won't stop or won't even move
 
and man..i really want my sprite to be loaded when you have low hp..and in the code :
write_string("dmg_rad"); // sprite name - can't be custom !!!
so does that mean my sprite can't be loaded..that the sprite name can't be custom??..
i've seen lots of plugin that have their own sprite..pls.. man..
and in this line:

public show_spr(id)
{
message_begin(MSG_ONE_UNRELIABLE, iconstatus, _, id)
write_byte(1) // status (0=hide, 1=show, 2=flash)
write_string("dmg_rad"); // sprite name - can't be custom !!!
write_byte(255) // R
write_byte(0) // G
write_byte(0) // B
message_end()
}
did you just replace my sprite with another one?
PS: I haven't tested the plugin yet I just compile it see if there's something wrong..so I really don't know if my sprite is loaded..

Hunter-Digital 05-14-2011 02:31

Re: Compiling won't stop or won't even move
 
AFAIK statusicon's sprite can't be custom, you could just use a HUD message instead of that sprite because it's just a text.

Still, what plugins have their own HUD sprites that do not require clients to replace files on their game ?

And what do you mean invalid call, who says that ?


All times are GMT -4. The time now is 04:18.

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