1. Sign up for news, events and more!

    You're currently visiting the official DarkRP Forums as a guest. Sign up now to participate in our community and we'll let you know when we have news.

Save weapons

Discussion in 'DarkRP Modding Questions & Help' started by Pypsikan, Feb 5, 2015.

  1. Pypsikan

    Pypsikan New Member

    How to keep a weapon at spawn.
     
  2. Matryan

    Matryan Well-Known Member

    For an individual job? for everyone? We're going to need some more information...
     
  3. Pypsikan

    Pypsikan New Member

    When change jobs
    When spawn server
    When leave from the server
     
  4. Matryan

    Matryan Well-Known Member

    So you want it to save people's weapons when they leave and change job?
     
  5. Pab14567

    Pab14567 Well-Known Member

    I think what he's trying to say is how to save a weapon on the map, even after a server restart, or when the player who spawned the weapon leaves the server, it's still there
     
  6. Pypsikan

    Pypsikan New Member

    Yes.
     
    Last edited: Feb 7, 2015
  7. Pypsikan

    Pypsikan New Member

    bump.
     
  8. [XRAY]Blake

    [XRAY]Blake Active Member

  9. Pypsikan

    Pypsikan New Member

  10. Pypsikan

    Pypsikan New Member

  11. [XRAY]Blake

    [XRAY]Blake Active Member

  12. Pypsikan

    Pypsikan New Member

  13. Pab14567

    Pab14567 Well-Known Member

    Okay let me try to explain what pypsikan is trying to say here, as his translations are probably bad, and should use a efficient translator, to learn some things as we'll

    Pypsikan wants a permanent weapon addon, where the weapon is permanently stored to a persons load out.
    When they leave the server, the gun saves, and when the player comes back on, it's automatically added to their weapon loadout,
    Now, there used to be one a NPC, one where you can buy with in game money, and set donator weapons, but I can't find it.


    Pypsikan, start trying to practice complete sentences. We can't fully understand you or help you good, with short phrases, that give little to no detail of what you need entirely.
     
  14. [XRAY]Blake

    [XRAY]Blake Active Member

  15. Matryan

    Matryan Well-Known Member

    Last edited: Feb 10, 2015
  16. Cake

    Cake Active Member

  17. Matryan

    Matryan Well-Known Member

  18. Cake

    Cake Active Member

  19. Matryan

    Matryan Well-Known Member

    Ah yes! I didn't even see it.
    But nah, I won't break anything too bad... ;)

    EDIT:
    Alright, it's done.
    Throw it in addons\darkrpmodification-master\lua\darkrp_modules\saveloadout\sv_saveloadout.lua.
    Code (Text):
    local meta = FindMetaTable("Player")

    local loadguns = {}
    local gunsave = {}


    function meta:saveLoadout()

        if not self:IsPlayer() or not self:Alive() then return end

        table.Empty(gunsave)

        for k, v in pairs(self:GetWeapons()) do

            if not GAMEMODE.Config.DisallowDrop[v:GetClass()] then
       
                table.insert(gunsave, v:GetClass())

            end

        end

        if gunsave then

            self:SetPData("weploadout", table.concat(gunsave, " "))

        else

            self:RemovePData("weploadout")

        end

    end
    concommand.Add("saveloadout", function(ply, cmd) ply:saveLoadout() end)

    function meta:loadLoadout()

        if not self:GetPData("weploadout") then return end

        loadguns = string.Explode(" ", self:GetPData("weploadout"))

        for k, v in pairs(loadguns) do
       
            self:Give(v)

        end

    end
    hook.Add("PlayerSpawn", "giveloadoutweps", function(ply) ply:loadLoadout() end)
    hook.Add("OnPlayerChangedTeam", "loadloadoutwepsteam", function(ply) ply:loadLoadout() end)
    concommand.Add("loadloadout", function(ply, cmd) ply:loadLoadout() end)
    hook.Add("onDarkRPWeaponDropped", "stopyourdupingcheaters", function(ply, spawned, wep)

        ply:saveLoadout()

    end)
    hook.Add("PlayerPickupDarkRPWeapon", "saveloadoutweppickup", function(ply, spawned, wep)

        timer.Simple(0.1, function() ply:saveLoadout() end)

    end)

    function meta:removeLoadout()


        if not self:GetPData("weploadout") then return end
       
        self:RemovePData("weploadout")

    end
    hook.Add("PlayerDeath", "removeloadoutweps", function(ply) ply:removeLoadout() end
    Now, THIS ISN'T THE MOST PERFECT CODE, nor do I expect that you'd expect it would be. Be aware, people can (at this point of time) dupe weapons using this, but I'll fix it tomorrow. All this very messy code does is save peoples weapons when they pick them up, and unsaves them when they are dropped. After a weapon is saved (In PData, SQL), they can leave the server, or change jobs, and keep the weapon. I know I don't have to say this (Atheos...) but feel free to throw some Constructive criticism at me and help neaten this monstrosity of code up. I've added in two commands for saving and loading, don't worry about them, I's just using them for debugging purposes. but as I said before, the load command can be used for duplicating any weapons.

    THIS HAS BEEN TESTED BUT I DO NOT RECOMMEND USING IT AS OF YET. LET ME FIX THE DUPE, THEN YOU CAN.
    Everything should be working.
     
    Last edited: Feb 12, 2015

Share This Page