AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Heal When Not Moving? (https://forums.alliedmods.net/showthread.php?t=93828)

Zombie Lurker 06-03-2009 02:57

Heal When Not Moving?
 
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!

zwfgdlc 06-03-2009 05:04

Re: Heal When Not Moving?
 
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


Sylwester 06-03-2009 06:20

Re: Heal When Not Moving?
 
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



Zombie Lurker 06-03-2009 09:10

Re: Heal When Not Moving?
 
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.

Bugsy 06-03-2009 09:23

Re: Heal When Not Moving?
 
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" );
                }
            }
        }
    }



Zombie Lurker 06-03-2009 10:08

Re: Heal When Not Moving?
 
Thanks for your idea bugsy but I'm gonna test it tomorrow.

Sylwester 06-03-2009 13:50

Re: Heal When Not Moving?
 
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.

Zombie Lurker 06-03-2009 21:10

Re: Heal When Not Moving?
 
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.

Bugsy 06-03-2009 21:42

Re: Heal When Not Moving?
 
Quote:

Originally Posted by Sylwester (Post 840886)
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.

Zombie Lurker 06-04-2009 02:09

Re: Heal When Not Moving?
 
Ok bugsy. Still trying to test with bots. (A little complicated lol)


All times are GMT -4. The time now is 14:01.

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