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.

need ply:changeTeam help for Job NPC

Discussion in 'DarkRP Modding Questions & Help' started by MilesDaDark♐♐♐, Aug 8, 2017.

  1. So I have been working with an npc framework I bought to make an npc that changes your job
    but heres the problem with that after using the function ply:changeTeam(TEAM_PRES,true) i soon realized that I need a function that stops people from joining teams more than once....I have a president class in my server and after having a friend test my npc You can become president more than once which your not supposed to be able to do..... I need a function or something that checks if there already is a person in an existing job or checks if the maximum amount of people are already in that job and changes them back to citizen or something to prevent people from spamming a job bc otherwise I am going to hire admins to regulate this kinda traffic which i really don't want to do...I am in a discord under code blue and some guy told me about loops and I get the concept but have no idea how to use them or use them for what i need here


    -- This sets the model for the NPC.
    NPC.model = "models/player/group01/male_05.mdl"
    -- This is for player models that support player colors. The values range from 0-1.
    NPC.color = Vector(1, 0, 0)

    -- Uncomment to make the NPC sit.
    --NPC.sequence = "sit"

    -- This receives the ignite message from cl_init.lua
    -- client is the player that sent the message.
    -- As you can see, the seconds argument is available.
    function NPC:eek:nIgnite(ply,client, seconds)
    --client:Ignite(tonumber(seconds) or 5)
    ply:changeTeam(TEAM_PRES,true)

    ply:printTable( team.GetPlayers( ply:Team() ) )


    -- for k, v in pairs(player.GetAll() ) do
    -- print(k .. " " .. v:GetName()) --prints the key and the value(the player)'s name ---using this makes the fucking npc not even work god damn it

    end


    --end

    -- Called when the entity for the NPC has been created.
    -- This allows you to modify the NPC itself.
    function NPC:eek:nEntityCreated(entity)
    --print(entity)
    --entity:Ignite(5)
    end
    --- Double Post Merged, Aug 8, 2017 ---
    why are there emojis in my text ugggggg
    --- Double Post Merged, Aug 8, 2017 ---
    also what does something like this do this isnt my code but i found this on another forum
    for k,v in pairs(RPExtrateams) do if k = TEAM_POLICE then local policemodel = v.model; end end

    what does RPExtrateams do?
    --- Double Post Merged, Aug 8, 2017 ---
    ALSO!!!!!

    what would be a function or something to create a vote for changeTeam(TEAM_PRES,true)?
     
    Last edited: Aug 8, 2017
  2. Sir Klutch

    Sir Klutch Active Member

    You could try http://wiki.garrysmod.com/page/team/NumPlayers
    if job x amount then return end

    Looks like someone is trying to return the model string for TEAM_POLICE, but getting the table id instead(v.model). Here is how I am doing it;

    Code (Lua):

    function Klutch_GetPlayerModel(model)
        if isstring(model) then
            return model
        end

        if istable(model) then
            return table.Random(model)
        end
    end

    local function Klutch_PlayerUnArrested(criminal, actor)
        local pModel = RPExtraTeams[criminal:Team()].model
        pModel = Klutch_GetPlayerModel(pModel)

        timer.Simple(0.2, function()
            criminal:SetModel(pModel)
        end)

        if not IsValid(actor) then
            return
        end

        if not IsValid(criminal) then
            return
        end

        if IsValid(criminal) then
            local niglet = actor:Nick()
            st.chatNotify("You have been unarrested by " .. niglet .. ".", criminal)
        end
    end

    hook.Add("playerUnArrested", "unjail_model", Klutch_PlayerUnArrested)
     
    RPExtraTeams returns the job table.
     
  3. where is the info on RPExtraTeams so i can read more about this
    is it on gmod wiki or darkrp bc i couldnt find it
    --- Double Post Merged, Aug 9, 2017 ---
    I have someone working on 2 scripts that do what I want so i'm waiting on that I mainly need to know how to make some kind of loop that boots a person from a job if there is already someone in that job....also if possible I would like to figure out how to put that into a script that can go into addons that would run in the backround because I have an npc script that isnt exactly cooperating with me....I will continue talking about this tomorrow because I have to wake up early for something
     
    Last edited: Aug 9, 2017

Share This Page