Results 1 to 10 of 26

Thread: Multiplayer health via script

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11

    Default

    There are several ways to achieve what you want. Some of them are:

    • create your own health items via tik file
    • create your own health items via script
    • use triggers




    1. tik file:
    Code:
    TIKI
    setup
    {
    	scale 0.52
    	path models/items/healthpacks
    	skelmodel healthcanteen.skd
    	surface material1 shader healthcanteen
    }
    
    init
    {
    	server
    	{
    		classname Health
    		amount 5
    		dmamount 5
    		pickupsound med_canteen
    	}
    }
    
    animations
    {
    	idle healthcanteen.skc
    }
    
    /*QUAKED item_health_5 (0 0 0) (0 0 0) (0 0 0)
    Gives 5 Health when picked up
    */
    I just copied the canteen (25hp) file and changed all '25' values to '5'. You could then create two more for '10' and '15' hp. You could even mess around with its size or shader (texture) to give them each a slightly different appearance.

    2. health item via script:

    So, with that file above fresh in your mind, you can use that as a reference to create a health item via script using the same properties you see there inside the 'server' block. I suppose you could see tikis as an extension of the script. You can also look at the 'Item' class in Game Module Classes to see the properties you can set. For example, you see the 'set_respawn' property on the link I provided (scroll down a little bit)? That would help you if you want it to be a 'one off', as the item won't respawn after being used.

    Anyway, here is the script:

    local.health = spawn Health // this is the 'classname' shown in the tik
    local.health.model = "models/items/item_25_healthbox.tik" // this is the model to use (you could use any of the health pack models here, or use your own)
    local.health amount 5
    local.health dmamount 5
    local.health pickupsound med_canteen // self explanatory, the sound it makes when someone picks it up
    local.health origin (20 20 20) // insert your own location here
    local.health set_respawn 0 // this will set the respawn property as discussed above


    Notice how I've used local.health.model = instead of local.health model, I did this because the latter didn't work. That's usually my rule of thumb. If one way doesn't work, try the other. There are also some properties that can be set both ways, by calling the function (origin) or just setting the property directly (.origin =). In this case it's up to you how you want to do it. The parentheses (brackets) you see on Game Module Classes are optional, and only used if you're calling the function, or when setting vectors (in this case, an origin). I personally don't use them.

    3. using triggers:
    On your various trigger_use in Radiant, you can set a property we can use in the script to tell us how much the player will heal by. So, for example, we have a trigger_use with a 'setthread' of 'Heal' and a '#hp' of '5' (make sure to use the hash for custom properties).

    Then all you need is a single function that ALL of your trigger_use's can call. You can give each trigger a different '#hp' value and it will work fine.


    Heal:
    local.player = parm.other

    // we don't want the player to make this healing spot disappear if they already have full health
    if (local.player.health == local.player.max_health) end

    local.trigger = self
    local.hp = float local.trigger.hp //grab the '#hp' property '5' we set on the trigger in Radiant and make it a 'float' (turns it into 5.0). This is needed because floats are used for 'heal' below

    // divide '5.0' by 100 to get '0.05', which is the value needed for 'heal' below
    local.health = (local.hp / 100)

    // do the heal
    local.player heal local.health

    // remove the trigger as this is a 'one off'
    local.trigger remove
    end


    Bear in mind the value '5' or '5.0' are just for this example of 5hp. The other triggers will pass in whatever '#hp' value you give them and it will work. I also assumed you wanted the trigger/items to only give health to one player lucky enough to use it. If no, let me know how you want it to work e.g. as many times as the player 'uses' the trigger, or only once per player etc...

    Hope that helps!
    Last edited by 1337Smithy; February 11th, 2020 at 02:29 AM.

Posting Permissions

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