Le gamemode de DarkRP propose déjà cette options de faire payer un props. Mais le script suivant présente une petit fenêtre qui demande au joueurs de valider leur choix par "Oui" ou par "Non", ce qui est plus joli visuellement.

Tutoriel proposé par Nicolas22

Installation du script

Il vous suffira de créer un dossier paytospawn dans votre dossier addons.

Ensuite dans le dossier paytospawn de recréer un dossier nommé lua et encore un autre dossier nommé autorun .

Ajouter ce code dans un fichier nommé shared.lua :

lmmpropcost = 75 -- Changer le prix du spawn d'un objet (A)

if (SERVER) then
  util.AddNetworkString("LMMPlayerSpawnPropCL")
  util.AddNetworkString("LMMPlayerSpawnPropCLBack")
  hook.Add( "PlayerSpawnProp", "LMMPlayerSpawnProp", function( ply, mdl )
    if ply:GetNWBool("LMMCanSpawnProp") then
      return true
    else
      net.Start("LMMPlayerSpawnPropCL")
        net.WriteString(mdl)
      net.Send(ply)
    end
  end )

  net.Receive("LMMPlayerSpawnPropCLBack",function(len, ply)
    local mdl = net.ReadString()
    ply:addMoney(-lmmpropcost)
    ply:SetNWBool("LMMCanSpawnProp",true)
    ply:ConCommand("gm_spawn "..mdl)
    timer.Simple(1,function()
      ply:SetNWBool("LMMCanSpawnProp",false)
    end)
  end)
end

if (CLIENT) then
  surface.CreateFont( "DRPTitleFont", {
      font = "Arial",
      size = 25,
      weight = 5000,
      blursize = 0,
      scanlines = 0,
      antialias = true,
  })

  surface.CreateFont( "DRPLabelFont", {
      font = "Arial",
      size = 20,
      weight = 5000,
      blursize = 0,
      scanlines = 0,
      antialias = true,
  })

  surface.CreateFont( "DRPBtnLabelFont", {
      font = "Arial",
      size = 15,
      weight = 5000,
      blursize = 0,
      scanlines = 0,
      antialias = true,
  })

  net.Receive("LMMPlayerSpawnPropCL",function()
    local mdl = net.ReadString()
    local DFrame = vgui.Create( "DFrame" )
    DFrame:SetSize( 450, 100 )
    DFrame:Center()
    DFrame:SetTitle( "" )
    DFrame:SetDraggable( false )
    DFrame:ShowCloseButton(false)
    DFrame:MakePopup()
    function DFrame:Paint(w, h)
      draw.RoundedBox(2, 0, 0, self:GetWide(), self:GetTall(), Color(35, 35, 35, 250))
      draw.RoundedBox(2, 0, 0, self:GetWide(), 30, Color(0, 102, 255, 250))
      draw.SimpleText( "Payer pour spawn un props!", "DRPTitleFont", self:GetWide() / 2, 15, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
    end

    local Label1 = vgui.Create("DLabel", DFrame)
    Label1:SetPos(30,40)
    Label1:SetSize(400,20)
    Label1:SetText("Etes-vous sûre de payer "..DarkRP.formatMoney(lmmpropcost).." pour le faire spawn?")
    Label1:SetTextColor(Color(255,255,255,255))
    Label1:SetFont("DRPLabelFont")

    local YesBTN = vgui.Create("DButton", DFrame)
    YesBTN:SetPos(30, 70)
    YesBTN:SetSize(150, 20)
    YesBTN:SetText("Oui")
    YesBTN:SetFont("DRPBtnLabelFont")
    YesBTN.OnCursorEntered = function(self)
      self.hover = true
    end
    YesBTN.OnCursorExited = function(self)
      self.hover = false
    end
    YesBTN.Paint = function( self, w, h )
      if self.IsClose then
        draw.RoundedBox(0, 0, 0, w, h, (self.hover and Color(88,0,0,250) or Color(255,255,255,255))) -- Paints on hover
      else
        draw.RoundedBox(0, 0, 0, w, h, (self.hover and Color(0,160,255,250) or Color(255,255,255,255))) -- Paints on hover
      end
      self:SetTextColor(self.hover and Color(255,255,255,255) or Color(0,0,0,250))
    end
    YesBTN.DoClick = function()
      net.Start("LMMPlayerSpawnPropCLBack")
        net.WriteString(mdl)
      net.SendToServer()
      DFrame:Close()
    end

    local NoBTN = vgui.Create("DButton", DFrame)
    NoBTN:SetPos(220, 70)
    NoBTN:SetSize(150, 20)
    NoBTN:SetText("Non")
    NoBTN.IsClose = true
    NoBTN:SetFont("DRPBtnLabelFont")
    NoBTN.OnCursorEntered = function(self)
      self.hover = true
    end
    NoBTN.OnCursorExited = function(self)
      self.hover = false
    end
    NoBTN.Paint = function( self, w, h )
      if self.IsClose then
        draw.RoundedBox(0, 0, 0, w, h, (self.hover and Color(88,0,0,250) or Color(255,255,255,255))) -- Paints on hover
      else
        draw.RoundedBox(0, 0, 0, w, h, (self.hover and Color(0,160,255,250) or Color(255,255,255,255))) -- Paints on hover
      end
      self:SetTextColor(self.hover and Color(255,255,255,255) or Color(0,0,0,250))
    end
    NoBTN.DoClick = function()
      DFrame:Close()
    end
  end)
end