Results 1 to 9 of 9

Thread: Regen health help with script

  1. #1

    Default Regen health help with script

    Script won't run this way. It's precalled in mike_torso and in dmprecache too.
    Code:
    main local.kneel:
    
    if(self == NULL || self == NIL)
    	end
    
    self.iscrouching = local.kneel
    if(self.iscrouching != "1")
    	end
    
    if(self.startCrouchLoop == 1)
    	end
    self.startCrouchLoop = 1
    
    thread crouchLoop self
    
    end
    
    crouchLoop local.player:	
    	while(1) {
    		if(local.player == NULL || local.player == NIL)
    			end
    		//1 health-point gets added every 0.3 second
    		if(local.player.iscrouching == "1" && isAlive local.player)
    			local.player heal 0.05
    		wait 0.3
    	}
    end
    code didn't look right so i tried this; somehow it loads but says failed due to object player. :| What am i doing wrong?
    Code:
    main:
    
    end
    
    local.kneel:
    
    if(self == NULL || self == NIL)
    	end
    
    self.iscrouching = local.kneel
    if(self.iscrouching != "1")
    	end
    
    if(self.startCrouchLoop == 1)
    	end
    self.startCrouchLoop = 1
    
    thread crouchLoop self
    
    end
    
    crouchLoop local.player:	
    	while(1) {
    		if(local.player == NULL || local.player == NIL)
    			end
    		//1 health-point gets added every 0.3 second
    		if(local.player.iscrouching == "1" && isAlive local.player)
    			local.player heal 0.05
    		wait 0.3
    	}
    end

  2. #2

    Default

    Is not working because you putting the variable local.kneel outside of the main thread.

    Has to be together like this:



    main local.kneel:

    if(self == NULL || self == NIL)
    end

    self.iscrouching = local.kneel
    if(self.iscrouching != "1")
    end

    if(self.startCrouchLoop == 1)
    end
    self.startCrouchLoop = 1

    thread crouchLoop self

    end

    crouchLoop local.player:
    while(1) {
    if(local.player == NULL || local.player == NIL)
    end
    //1 health-point gets added every 0.3 second
    if(local.player.iscrouching == "1" && isAlive local.player)
    local.player heal 0.05
    wait 0.3
    }
    end

  3. #3

    Default

    Tried that still doesn't work.

  4. #4

    Default

    On the script put a message on the while loop to see if the script is running.

    The script to run properly the player need to have the self.iscrouching to 1 and self.startCrouchLoop to 0 or NIL.

  5. #5

    Default

    Quote Originally Posted by DoubleKill View Post
    On the script put a message on the while loop to see if the script is running.

    The script to run properly the player need to have the self.iscrouching to 1 and self.startCrouchLoop to 0 or NIL.
    Thanks when I get home from work I will try. Thinking back on this there is a message script that should be running to and it isnít, so I might have some dmprecache collusion going on somewhere will have to investigate.

  6. #6
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,256

    Default

    How is this called? Can you show us the calling file as well, it means we can try it locally.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  7. #7

    Default

    There are a few things that I did notice:
    1. Are your sure these variables local.player.iscrouching/self.iscrouching are of the type string ?
    If you are unsure, convert it into int and compare it as int value, I recommend conversion for all
    vars that contain a purly numeric value.
    PHP Code:
    if( int(local.player.iscrouching) == 
    2. You can check in the loop head, since you exit the func anyway after the loop
    PHP Code:
     while(local.player != NIL && local.player != NULL
    3. I had lots of troubles with this command (isAlive local.player) working right,
    maybe I did it wrong, and I have not tested if it really works in multi for a player
    since then. I am using now health instead.
    PHP Code:
    local.player.health 

  8. #8

    Default

    isAlive works fine. I'd recommend using it where you can. It checks both that the entity exists and that it isn't dead. Something to bear in mind though, is that a player is still classed as alive when in spectator. They will also have 100 health in spectator.
    if (local.player != NIL && local.player != NULL && local.player.health > 0)
    is the same as
    if (isAlive local.player)


    By the way, you don't need to check for crouching by running this script from the state machine (mike_torso). The states are already checked by the game and exposed as functions (getmovement & getposition). You will want getposition.

    So you can call this script every time a new player connects or spawns, and then do:


    main:

    if(self.startCrouchLoop == 1)
    end
    self.startCrouchLoop = 1

    thread crouchLoop self

    end

    crouchLoop local.player:
    while(local.player) {

    //1 health-point gets added every 0.3 second
    if(local.player getposition == "crouching" && isAlive local.player)
    local.player heal 0.05

    wait 0.3
    }
    end
    Last edited by 1337Smithy; January 16th, 2020 at 04:42 AM.

  9. #9

    Default

    Quote Originally Posted by 1337Smithy View Post
    isAlive works fine. I'd recommend using it where you can. It checks both that the entity exists and that it isn't dead. Something to bear in mind though, is that a player is still classed as alive when in spectator. They will also have 100 health in spectator.
    if (local.player != NIL && local.player != NULL && local.player.health > 0)
    is the same as
    if (isAlive local.player)


    By the way, you don't need to check for crouching by running this script from the state machine (mike_torso). The states are already checked by the game and exposed as functions (getmovement & getposition). You will want getposition.

    So you can call this script every time a new player connects or spawns, and then do:


    main:

    if(self.startCrouchLoop == 1)
    end
    self.startCrouchLoop = 1

    thread crouchLoop self

    end

    crouchLoop local.player:
    while(local.player) {

    //1 health-point gets added every 0.3 second
    if(local.player getposition == "crouching" && isAlive local.player)
    local.player heal 0.05

    wait 0.3
    }
    end
    Thank you! I appreciate the explanation.
    I’ve been reading and watching a ton of videos over the last few weeks and it’s always nice to see an explanation behind code posted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •