1. Check out the Store if you're looking to Buy HL2RP or other schemas for your server. You can click Buy Schemas on the very top navigation bar to visit the store.
  2. Use the Plugin Center to easily subscribe to and auto-install Clockwork plugins to your server, or submit and share plugins you have developed.
  3. Having trouble setting up or developing with Clockwork? Check out the Wiki or post in the Support Forum for advice from fellow users.
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. 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. Anyone?
  3. cold

    cold here we go yo, so what's the scenario Active Member

    local PLUGIN = PLUGIN;
    function PLUGIN:PlayerFlagsGiven(player, flags)
        if (player:Alive() and string.find(flags, "flag")) then 
    I dunno if PlayerFlagsGiven is run every tick or what but it should give you the weapon each time you spawn.
  4. Thank you :)
  5. 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. cold

    cold here we go yo, so what's the scenario Active Member

    • Like Like x 1
  7. Viz


    PlayerFlagsGiven is only called when a player has been given flags.
    -- 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");
        if (string.find(flags, "t") and player:Alive()) then
            self.player:GiveSpawnWeapon(player, "gmod_tool");
        player:SetSharedVar("flags", player:GetFlags());
    The thing that's actually causing the player to get the weapon every time they spawn is PlayerLoadout, or PlayerGiveWeapons.
    -- 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");
    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 at 2:18 AM
  8. So last question, where would I put this in the server files?
  9. 8bitMafia

    8bitMafia Active Member

    sv_hooks.lua ctrl f find the function
    • Disagree Disagree x 1
  10. Again where do I put these?
  11. Viz


    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. cold

    cold here we go yo, so what's the scenario Active Member


    You would put it in sv_hooks.lua in this format.
    • Informative Informative x 1