1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

HL2RP How to assign flags to weapons.

Discussion in 'Development' started by BetaDesh, Jun 16, 2017.

  1. BetaDesh

    BetaDesh The fuck's a BetaDesh? Clockwork Customer

    Does anyone know how to assign flags to weapons the same way that flags are assigned to the physgun and/or toolgun for characters? I want to be able to give conscripts weapons that they spawn with but only after they've completed training.
     
  2. BetaDesh

    BetaDesh The fuck's a BetaDesh? Clockwork Customer

    Anyone?
     
  3. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    Code:
    local PLUGIN = PLUGIN;
    
    function PLUGIN:PlayerFlagsGiven(player, flags)
        if (player:Alive() and string.find(flags, "flag")) then 
            player:Give("nameofwep")
        end;
    end;
    
    I dunno if PlayerFlagsGiven is run every tick or what but it should give you the weapon each time you spawn.
     
  4. BetaDesh

    BetaDesh The fuck's a BetaDesh? Clockwork Customer

    Thank you :)
     
  5. BetaDesh

    BetaDesh The fuck's a BetaDesh? Clockwork Customer

    Wait before I try to use this does this apply to the player or the character? Cause I need it to apply only to a character. Don't want someone getting teh weapon flag as an MPF and then spawning in as a citizen with an MP7 or something.
     
  6. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    @Viz
     
    • Like Like x 1
  7. Viz

    Viz Legend Clockwork Customer

    PlayerFlagsGiven is only called when a player has been given flags.
    Code:
    -- Called when a player has been given flags.
    function Clockwork:PlayerFlagsGiven(player, flags)
        if (string.find(flags, "p") and player:Alive()) then
            self.player:GiveSpawnWeapon(player, "weapon_physgun");
        end;
       
        if (string.find(flags, "t") and player:Alive()) then
            self.player:GiveSpawnWeapon(player, "gmod_tool");
        end;
       
        player:SetSharedVar("flags", player:GetFlags());
    end;
    
    The thing that's actually causing the player to get the weapon every time they spawn is PlayerLoadout, or PlayerGiveWeapons.
    Code:
    -- Called when a player's weapons should be given.
    function Schema:PlayerGiveWeapons(player)
        if (player:GetFaction() == FACTION_MPF) then
            Clockwork.player:GiveSpawnWeapon(player, "cw_stunstick");
        end;
    end;
    
    So you'd need to use both of these to get the result you're trying to achieve.
    Flags are stored on the character not the player, so yes it's fine to use this in the way you intend to.
     
    • Like Like x 1
    Last edited: Jun 18, 2017
  8. BetaDesh

    BetaDesh The fuck's a BetaDesh? Clockwork Customer

    So last question, where would I put this in the server files?
     
  9. sv_hooks.lua ctrl f find the function
     
    • Disagree Disagree x 1
  10. BetaDesh

    BetaDesh The fuck's a BetaDesh? Clockwork Customer

    Again where do I put these?
     
  11. Viz

    Viz Legend Clockwork Customer

    You don't put those anywhere, I'm just explaining what the functions do.
    You can use those functions inside a plugin to achieve what you're trying to.
     
  12. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    /cwhl2rp/
    -/plugins/
    --/wepflags/
    ---plugin.ini
    ---/plugin/
    ----sv_hooks.lua

    You would put it in sv_hooks.lua in this format.
     
    • Informative Informative x 1
  13. You've improved a lot, good job.
     
    • Friendly Friendly x 1

Previous Readers (Total: 0)