Raised This Month: $ Target: $400
 0% 

Heal When Not Moving?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-03-2009 , 02:57   Heal When Not Moving?
Reply With Quote #1

I'd like someone to give me an example of how to make all players heal when not moving for three seconds. I have tried it myself but my horrible job makes my game have insane lag and crash. Here's my code :
PHP Code:
public HPBase(idHEAL) {
 static 
itarget
 
static Float:velocity[3]
 static 
Float:speed
 
 
for(i=1i<=g_maxplayersi++) {
  
target pev(ipev_iuser1) == pev(ipev_iuser2) : i
  pev
(targetpev_velocityvelocity)
 
  
speed vector_length(velocity)
 
  if (
speed == 0)
   
set_task(3.0"HPBase"id__"b")
   else 
remove_task(HEAL)
 }
 
 new 
cur_hp get_user_health(id)
 new 
am_hp 200
 
if (speed == && is_user_alive(id))
  if (
cur_hp max_hp)
   
set_user_health(victimcur_hp am_hp)

All help appreciated!
__________________
Zombie Lurker is offline
zwfgdlc
Senior Member
Join Date: May 2006
Old 06-03-2009 , 05:04   Re: Heal When Not Moving?
Reply With Quote #2

try Ham_IsMoving
PHP Code:
    /** 
     * Description:        Whether or not the entity is moving.
     * Forward params:    function(this);
     * Return type:        Integer.
     * Execute params:    ExecuteHam(Ham_IsMoving, this);
     */
    
Ham_IsMoving
zwfgdlc is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-03-2009 , 06:20   Re: Heal When Not Moving?
Reply With Quote #3

not tested
PHP Code:
#define HEAL_INTERVAL 3 //time (in seconds) between heals
#define TID_CP 8562
new g_max_players
public plugin_init(){
    
g_max_players get_maxplayers()
    
set_task(1.0"check_players"TID_CP__"b")
}

public 
check_players(){
    static 
origins[33][3], tmp_origin[3], counter[33]
    for(new 
i=1i<=g_max_playersi++){
        if(!
is_user_alive(i))
            continue
        
get_user_origin(itmp_origin)
        if(
tmp_origin[0] == origins[i][0] &&
        
tmp_origin[1] == origins[i][1] &&
        
tmp_origin[2] == origins[i][2]){
            
counter[i]++ //player has not moved since last check
            
if(counter[i] >= HEAL_INTERVAL){ 
                
//player was not moving during last HEAL_INTERVAL seconds
                
heal_player(i)
                
counter[i] = 0
            
}
        }else{
            
counter[i] = //player has moved since last check
            
origins[i][0] = tmp_origin[0]
            
origins[i][1] = tmp_origin[1]
            
origins[i][2] = tmp_origin[2]
        }
    }
}


public 
heal_player(id){
    
//heal this player

__________________
Impossible is Nothing

Last edited by Sylwester; 06-03-2009 at 06:22.
Sylwester is offline
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-03-2009 , 09:10   Re: Heal When Not Moving?
Reply With Quote #4

Well, I cant edit it to work properly. You see, I'm using it for a zombie infection plugin. And it makes the plugin stop working. (The zombie doesnt appear and other stuff) Could you try and give me a different one? Or is this the only one? T.T I hope there is more than 1.
__________________
Zombie Lurker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-03-2009 , 09:23   Re: Heal When Not Moving?
Reply With Quote #5

PHP Code:
new g_MaxPlayers;

public 
plugin_init() 
{
    
g_MaxPlayers get_maxplayers();
    
    
set_task1.0 "CheckMoving" 1029 __"b" );
}

public 
CheckMoving()
{
    static 
iStillCounter[33];
    static 
FloatfVelocity[3];
    static 
id;
    
    for ( 
id id <= g_MaxPlayers id++ )
    {
        if ( 
is_user_aliveid ) )
        {
            
pevid pev_velocity fVelocity );
    
            if ( 
fVelocity[0] || fVelocity[1] || fVelocity[2] )
            {
                
client_printid print_chat "You are moving" );
                
                
iStillCounter[id] = 0;
            }
            else
            {
                
client_printid print_chat "You are standing still" );
                
                if ( ++
iStillCounter[id] >= )
                {
                    
client_printid print_chat "Give health" );
                }
            }
        }
    }

__________________

Last edited by Bugsy; 06-04-2009 at 09:55.
Bugsy is offline
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-03-2009 , 10:08   Re: Heal When Not Moving?
Reply With Quote #6

Thanks for your idea bugsy but I'm gonna test it tomorrow.
__________________
Zombie Lurker is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-03-2009 , 13:50   Re: Heal When Not Moving?
Reply With Quote #7

idea? It's exactly the same as in my code. The only difference is that he checks if player has velocity instead if player origin has changed. He also forgot to check if user is alive.

I don't know how it is possible for my code to make some other plugin stop to work. If you want help then post link to code of your zombie infection plugin and tell me what did you do with my code.
__________________
Impossible is Nothing
Sylwester is offline
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-03-2009 , 21:10   Re: Heal When Not Moving?
Reply With Quote #8

Acctually, I'm not making public my zombie infection thingy because to me, its horrible so you know. And I'll try to work around with your code. Seems to be better.
__________________
Zombie Lurker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-03-2009 , 21:42   Re: Heal When Not Moving?
Reply With Quote #9

Quote:
Originally Posted by Sylwester View Post
idea? It's exactly the same as in my code. The only difference is that he checks if player has velocity instead if player origin has changed. He also forgot to check if user is alive.
Exactly the same? Let's see, we both used set_task() and a for-loop, that's about the only similarity.

If you didn't notice, my method checks to see if a player has velocity in any direction while yours compares previous to current origin. How is my method exactly the same as yours?

Zombie Lurker, I added an is_user_alive() check to the above code post. If you have any issues with getting it to work let me know and I can adjust it to accommodate your particular need.
__________________

Last edited by Bugsy; 06-04-2009 at 00:30.
Bugsy is offline
Zombie Lurker
Senior Member
Join Date: Mar 2009
Old 06-04-2009 , 02:09   Re: Heal When Not Moving?
Reply With Quote #10

Ok bugsy. Still trying to test with bots. (A little complicated lol)
__________________
Zombie Lurker 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 14:01.


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