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. Dismiss Notice
  3. Dismiss Notice
  4. Use the Plugin Center to easily subscribe to and auto-install Clockwork plugins to your server, or submit and share plugins you have developed.
  5. 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. BetaDesh

    BetaDesh The fuck's a BetaDesh? Clockwork Customer Active Member

    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 Active Member

    Anyone?
     
  3. cold

    cold yeezy yeezy yeezy Active Member

    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 Active Member

    Thank you :)
     
  5. BetaDesh

    BetaDesh The fuck's a BetaDesh? Clockwork Customer Active Member

    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 yeezy yeezy yeezy Active Member

    @Viz
     
    • Like Like x 1
  7. Viz

    Viz Active Member

    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 Active Member

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

    BetaDesh The fuck's a BetaDesh? Clockwork Customer Active Member

    Again where do I put these?
     
  11. Viz

    Viz Active Member

    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 yeezy yeezy yeezy Active Member

    /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)