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.

How do make custom commands? Run commands though f4 menu?

Discussion in 'DarkRP Modding Questions & Help' started by Lacaze, Sep 1, 2017.

  1. Lacaze

    Lacaze New Member

    A player in my darkrp server wanted to make a custom class which their special ability was to spawn zombies for a cost of in game money. How would I make a custom command or maybe even put something in the f4 menu for a way for the players to do this. I want to be able to let the players spawn the zombies through a command and it would subtract the money from their name. Help me out?
     
  2. Sir Klutch

    Sir Klutch Active Member

    Try this place in lua/autorun after you made your edits
    Code (Lua):

    concommand.Add("some_command_name",  function(ply)
        if not ply:SteamID() == "STEAM_ID_HERE" then
            return
        end -- Add the players steam ID here.

        local zombie = ents.Create("npc_zombie") -- zombie class

        if not IsValid(zombie) then
            return
        end

        zombie:SetModel("zombie.mdl") -- Make sure to get said zombies model path
        zombie:SetPos(ply:GetEyeTrace().HitPos)
        zombie:Spawn()
    end)
     
    Last edited: Sep 1, 2017
  3. Lacaze

    Lacaze New Member

    Thank you a lot I diddnt expect someone to post actual script. I'll try it later today thanks a lot man :)
     
    Richard Hammer likes this.
  4. Klutch is pro man :)
     
  5. Lacaze

    Lacaze New Member

    In the script you put ply:steamid is there a way to put it to a certain class insted of a id?
    also how would i make it to where you would lose money on the command to "purchase" spawning the zombie
     
    Last edited: Sep 2, 2017
  6. Just use (I think)
    Code (Text):
     ply:Team() == TEAM_MAYOR
    Instead.

    Or if you want user group in future do
    Code (Text):
    ply:GetUserGroup == "vip"
    As far as money I know
    Code (Text):
    ply:addMoney( 1000 )
    is a thing, imagine opposite is ply:subtractMoney? If that doesn't work maybe try add money but input negative number LOL I'm curious as well, never had a need to do this myself.
     
    Last edited: Sep 2, 2017
  7. Sir Klutch

    Sir Klutch Active Member

    Oi, teams are not strings.

    Code (Lua):
    ply:Team() == TEAM_MAYOR
     
    Richard Hammer likes this.
  8. Lmao I didn't even catch that. Think I was in string mode from other options xD

    FIXED... Told you he's pro :p
     
  9. Sir Klutch

    Sir Klutch Active Member

    @Lacaze
    Code (Lua):

    local zombie_spawn_amount = 5000 -- edit cost

    local zombie_buy_teams = {
        [TEAM_MAYOR] = true,
        [TEAM_ETC] = true
    } -- add/edit or remove teams

    concommand.Add("some_command_name", function(ply)
        local zombie_teams = zombie_buy_teams[ply:Team()] -- cache the result of the table so that you don't have to call ply:Team() or access the table multiple times.

        if not zombie_teams then
            return
        end

        if not ply:canAfford(zombie_spawn_amount) then
            ply:ChatPrint("You can't afford to spawn a zombie.")

            return
        end

        ply:addMoney(-zombie_spawn_amount)
        local zombie = ents.Create("npc_zombie") -- zombie class

        if not IsValid(zombie) then
            return
        end

        zombie:SetModel("zombie.mdl") -- Make sure to get said zombies model path
        zombie:SetPos(ply:GetEyeTrace().HitPos)
        zombie:Spawn()
    end)
     
  10. Lacaze

    Lacaze New Member

    local zombie_spawn_amount = 8000 -- edit cost

    local zombie_buy_teams = {
    [TEAM_SCIENTIST] = true,
    } -- add/edit or remove teams

    concommand.Add("createzombie", function(ply)
    local zombie_teams = zombie_buy_teams[ply:Team()] -- cache the result of the table so that you don't have to call ply:Team() or access the table multiple times.

    if not zombie_teams then
    return
    end

    if not ply:canAfford(zombie_spawn_amount) then
    ply:ChatPrint("You can't afford to create a zombie.")

    return
    end

    ply:addMoney(-8000)
    local zombie = ents.Create("npc_zombie") -- zombie class

    if not IsValid(zombie) then
    return
    end

    zombie:SetModel("models/player/zombie_classic.mdl") -- Make sure to get said zombies model path
    zombie:SetPos(ply:GetEyeTrace().HitPos)
    zombie:Spawn()
    end)





    Above is what I put and I get this error



    [ERROR] lua/autorun/spawnzombie.lua:4: table index is nil 1. unknown - lua/autorun/spawnzombie.lua:4
     
  11. Sir Klutch

    Sir Klutch Active Member

    @Lacaze
    lua/autorun/spawnzombie.lua:4: table index is nil 1. unknown - lua/autorun/spawnzombie.lua:4[/QUOTE]
    Sounds like either the table is not loading in time or the job does not exist. Check your spelling for the TEAM. If that doesn't work, try this...

    Code (Lua):

    concommand.Add("some_command_name", function(ply)
        zombie_buy_teams = {
            [TEAM_MAYOR] = true,
            [TEAM_ETC] = true
        }

        -- add/edit or remove teams
        local zombie_teams = zombie_buy_teams[ply:Team()] -- cache the result of the table so that you don't have to call ply:Team() or access the table multiple times.

        if not zombie_teams then
            return
        end

        if not ply:canAfford(zombie_spawn_amount) then
            ply:ChatPrint("You can't afford to spawn a zombie.")

            return
        end

        ply:addMoney(-zombie_spawn_amount)
        local zombie = ents.Create("npc_zombie") -- zombie class

        if not IsValid(zombie) then
            return
        end

        zombie:SetModel("zombie.mdl") -- Make sure to get said zombies model path
        zombie:SetPos(ply:GetEyeTrace().HitPos)
        zombie:Spawn()
    end)
     
     
  12. Lacaze

    Lacaze New Member

    Code (Lua):

    concommand.Add("createzombie", function(ply)
        zombie_buy_teams = {
            [TEAM_SCIENTIST] = true
        }

        -- add/edit or remove teams
        local zombie_teams = zombie_buy_teams[ply:Team()] -- cache the result of the table so that you don't have to call ply:Team() or access the table multiple times.

        if not zombie_teams then
            return
        end

        if not ply:canAfford(zombie_spawn_amount) then
            ply:ChatPrint("You can't afford to create a zombie.")

            return
        end

        ply:addMoney(-8000)
        local zombie = ents.Create("npc_zombie") -- zombie class

        if not IsValid(zombie) then
            return
        end

        zombie:SetModel("models/player/zombie_classic.mdl") -- Make sure to get said zombies model path
        zombie:SetPos(ply:GetEyeTrace().HitPos)
        zombie:Spawn()
    end)

     
    [/QUOTE]

    ok ill try this ^^

    also what would be the command prefix? like ! / or console or something?
     
  13. Sir Klutch

    Sir Klutch Active Member

    ok ill try this ^^

    also what would be the command prefix? like ! / or console or something?[/QUOTE]
    This is just a console command, would you like a chat command?
     
  14. Lacaze

    Lacaze New Member

    This is just a console command, would you like a chat command?[/QUOTE]
    Yea? how would i do that?
    Can u get what i pasted add it to that? I can try that
     
  15. Sir Klutch

    Sir Klutch Active Member

    @Lacaze
    Code (Lua):

    local zombie_spawn_amount = 5000 -- edit cost
    local zombie_buy_teams
    -- add/edit or remove teams
    local zombie_buy_chat_command = "/buyzombie"

    concommand.Add("some_command_name", function(ply)
        zombie_buy_teams = {
            [TEAM_MAYOR] = true,
            [TEAM_ETC] = true
        }

        local zombie_teams = zombie_buy_teams[ply:Team()] -- cache the result of the table so that you don't have to call ply:Team() or access the table multiple times.

        if not zombie_teams then
            return
        end

        if not ply:canAfford(zombie_spawn_amount) then
            ply:ChatPrint("You can't afford to spawn a zombie.")

            return
        end

        ply:addMoney(-zombie_spawn_amount)
        local zombie = ents.Create("npc_zombie") -- zombie class

        if not IsValid(zombie) then
            return
        end

        zombie:SetModel("zombie.mdl") -- Make sure to get said zombies model path
        zombie:SetPos(ply:GetEyeTrace().HitPos)
        zombie:Spawn()
    end)

    if SERVER then
        hook.Add("PlayerSay", "spawn_zombie", function(ply, zomb, team)
            zombie_buy_teams = {
                [TEAM_MAYOR] = true,
                [TEAM_ETC] = true
            }

            local zombie_teams = zombie_buy_teams[ply:Team()] -- cache the result of the table so that you don't have to call ply:Team() or access the table multiple times.

            if not zombie_teams then
                return
            end

            zomb = string.lower(zomb)

            if zomb == zombie_buy_chat_command then
                if not ply:canAfford(zombie_spawn_amount) then
                    ply:ChatPrint("You can't afford to create a zombie.")

                    return
                end

                ply:addMoney(-zombie_spawn_amount)
                local zombie = ents.Create("npc_zombie") -- zombie class

                if not IsValid(zombie) then
                    return
                end

                zombie:SetModel("models/player/zombie_classic.mdl") -- Make sure to get said zombies model path
                zombie:SetPos(ply:GetEyeTrace().HitPos)
                zombie:Spawn()
            end
        end)
    end
     
     

Share This Page