DarkRP Fix Requests

G’day, I’m having some issues with setting multiple jobs for weapons/ammo on dark RP. Here’s what I have tried:


GM:AddAmmoType("pistol", "Pistol ammo", "models/Items/BoxSRounds.mdl", 30, 24, function( ply ) return ply:Team() == TEAM_GUN or TEAM_HITMAN end) 


GM:AddAmmoType("pistol", "Pistol ammo", "models/Items/BoxSRounds.mdl", 30, 24, function( ply ) return ply:Team() == TEAM_GUN, TEAM_HITMAN end) 

Any help appreciated. Second issue, setting multiple jobs for shipments:

I’d like gun dealers to be only able to spawn ships of AWPs, but the hitman to be able to purchese a single AWP, here’s the code:


AddCustomShipment("AWP", {
	model = "models/weapons/w_snip_awp.mdl",
	entity = "weapon_mad_awp",
	price = 4000,
	amount = 10,
	seperate = false,
	pricesep = 500,
	noship = false,
	allowed = {("TEAM_SPECDEALER")}

Lastly, kind of related to DarkRP, I have a taser installed that can be abused by dying or leaving the server. From what I’ve gathered, the tased player doesn’t revive if the player with the taser died or disconnected. Here is the SWEP code:




if ( SERVER ) then

	AddCSLuaFile( "shared.lua" )
	
	SWEP.Weight				= 2
	SWEP.AutoSwitchTo		= true
	SWEP.AutoSwitchFrom		= true
	SWEP.HoldType			= "pistol"
	SWEP.Category = "Taser"
	SWEP.Spawnable			= false
	SWEP.AdminSpawnable		= true
	end

if ( CLIENT ) then

	SWEP.PrintName = "Taser";
	SWEP.Slot = 3;
	SWEP.SlotPos = 1;
	SWEP.DrawAmmo = false;
	SWEP.DrawCrosshair = true;
	SWEP.Category = "Taser"
	SWEP.Spawnable			= true
	SWEP.AdminSpawnable		= true
end


SWEP.Author = "Emmemad";
SWEP.Contact = "";
SWEP.Purpose = "Tasering";
SWEP.Instructions = "Left click to bring down.";

//SWEP.Spawnable			= true
//SWEP.AdminSpawnable		= true

SWEP.ViewModel			= "models/weapons/v_pistol.mdl"
SWEP.WorldModel			= "models/weapons/w_pistol.mdl"

SWEP.Primary.ClipSize		= 1
SWEP.Primary.DefaultClip	= 1
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo			= "357"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= ""

local taseredrags = {}
local taseruniquetimer1 = 0
//local taseruniquetimer2 = 0

 function SWEP:Reload()
self.Weapon:DefaultReload( ACT_VM_RELOAD ) //animation for reloading
end 
 
 function SWEP:PrimaryAttack()
 if ( !self:CanPrimaryAttack() ) then return end
 local eyetrace = self.Owner:GetEyeTrace(); 
 if !eyetrace.Entity:IsPlayer() then 
  if !eyetrace.Entity:IsNPC() then return end       // Check to see if what the player is aiming at is an NPC or Player
  end
  
self.Weapon:EmitSound( "Weapon_StunStick.Activate")  
self.BaseClass.ShootEffects( self ) 
self:TakePrimaryAmmo(1) 

 
 if (!SERVER) then return end 
 
 if eyetrace.Entity:IsPlayer() then
 self:tasePlayer(eyetrace.Entity)    // If the it is a player then bring them down tranqPlayer()
 end
 if eyetrace.Entity:IsNPC() then
 self:taseNPC(eyetrace.Entity, self.Owner)    // If the it is a NPC then bring them down with tranqNPC()
 end
  end 


function SWEP:tasePlayer(ply)
	-- create ragdoll
	local rag = ents.Create( "prop_ragdoll" )
    if not rag:IsValid() then return end

	-- build rag
	rag:SetModel( ply:GetModel() )
    rag:SetKeyValue( "origin", ply:GetPos().x .. " " .. ply:GetPos().y .. " " .. ply:GetPos().z )
	rag:SetAngles(ply:GetAngles())
			
	-- player vars
	rag.taseredply = ply
	table.insert(taseredrags, rag)
		
	-- "remove" player
	ply:StripWeapons()
	ply:DrawViewModel(false)
	ply:DrawWorldModel(false)
	ply:Spectate(OBS_MODE_CHASE)
	ply:SpectateEntity(rag)
	
	-- finalize ragdoll
    rag:Spawn()
    rag:Activate()
	
	-- make ragdoll fall
	rag:GetPhysicsObject():SetVelocity(4*ply:GetVelocity())
	
	-- bring the motherfucker back

     self:setrevivedelay(rag)
	
end

function SWEP:taseNPC(npc, npcShooter)
	-- get info about npc
	local skin = npc:GetSkin()
	local wep = ""
	local possibleWep = ents.FindInSphere(npc:GetPos(),0.01) -- find anything in the center basically
	for k, v in pairs(possibleWep) do 
		if string.find(v:GetClass(),"weapon_") == 1 then 
			wep = v:GetClass()
		end
	end

	local citType = "" -- citizen type
	local citMed = 0 -- is it a medic? assume no
	if npc:GetClass() == "npc_citizen" then
		citType = string.sub(npc:GetModel(),21,21) -- get group number (e.g. models/humans/group0#/whatever)
		if string.sub(npc:GetModel(),22,22) == "m" then citMed = 1 end -- medic skins have an "m" after the number
	end

	-- make ragdoll now that all info is gathered	
	local rag = ents.Create( "prop_ragdoll" )
    if not rag:IsValid() then return end
	
	-- build rag
	rag:SetModel( npc:GetModel() )
    rag:SetKeyValue( "origin", npc:GetPos().x .. " " .. npc:GetPos().y .. " " .. npc:GetPos().z )
	rag:SetAngles(npc:GetAngles())
	
	-- npc vars
	rag.tasewasNPC = true
	rag.tasenpcType = npc:GetClass()
	rag.tasenpcWep = wep
	rag.tasenpcCitType = citType
	rag.tasenpcCitMed = citMed
	rag.tasenpcSkin = skin
	rag.tasenpcShooter = npcShooter
	table.insert(taseredrags, rag)
	
	--finalize
	rag:Spawn()
    rag:Activate()
	
	-- make ragdoll fall
  rag:GetPhysicsObject():SetVelocity(8*npc:GetVelocity())
		
	--remove npc
	npc:Remove()

 self:setrevivedelay(rag)

	
	end

function SWEP:setrevivedelay(rag)
if taseruniquetimer1 > 30 then
taseruniquetimer1 = 0
end
taseruniquetimer1 = taseruniquetimer1 + 1

timer.Create("revivedelay"..taseruniquetimer1, 10, 1, function() self:taserevive(rag) end) ---------------------------------------------
end

function SWEP:taserevive(ent)
	-- revive player
	if !ent then return end
	
	if ent.taseredply then
   if ( !ent.taseredply:IsValid() ) then return end
   local phy = ent:GetPhysicsObject()
		phy:EnableMotion(false)
		ent:SetSolid(SOLID_NONE)
   	ent.taseredply:DrawViewModel(true)
	ent.taseredply:DrawWorldModel(true)
	ent.taseredply:Spawn()
	ent.taseredply:SetPos(ent:GetPos())
	ent.taseredply:SetVelocity(ent:GetPhysicsObject():GetVelocity())


	-- revive npc
	elseif ent.tasewasNPC then
		local npc = ents.Create(ent.tasenpcType) -- create the entity
		
		util.PrecacheModel(ent:GetModel()) -- precache the model
		npc:SetModel(ent:GetModel()) -- and set it
		local spawnPos = ent:GetPos()+Vector(0,0,0) -- position to spawn it
		
		npc:SetPos(spawnPos) -- position
		npc:SetSkin(ent.tasenpcSkin)
		npc:SetAngles(Angle(0,ent:GetAngles().y,0))
		
		if ent.tasenpcWep != "" then -- if it's an NPC and we found a weapon for it when it was spawned, then
			npc:SetKeyValue("additionalequipment",ent.tasenpcWep) -- give it the weapon
		end
		
		if ent.taseentType == "npc_citizen" then
			npc:SetKeyValue("citizentype",ent.tasenpcCitType) -- set the citizen type - rebel, refugee, etc.
			if ent.tasenpcCitType == "3" && ent.tasenpcCitMed==1 then -- if it's a rebel, then it might be a medic, so check that
				npc:SetKeyValue("spawnflags","131072") -- set medic spawn flag
			end
		end
				
		npc:Spawn()
		npc:Activate()
		
cleanup.Add (uplayer, "NPC", npc);

undo.Create ("Tasered NPC");
undo.AddEntity (npc);
undo.SetPlayer (ent.tasenpcShooter);

undo.Finish();

		
	-- don't deal with other ents
	else 
		return
	end
	
		for k, v in pairs(taseredrags) do 
		if v == ent then 
			 table.remove( taseredrags, k ) 
		end
	end
	ent:Remove()

end



I would appreciate any help with any of the questions above.

There’s a massive DarkRP help thread, it might already contain your answer, if not, that’s the best spot to post :slight_smile:

http://forum.facepunch.com/showthread.php?t=1249475&page=19

Thanks mate, I’ll check it out.

I wouldn’t think the function on ammo types would help, as you can control in the darkRP config if only gun dealer can sell ammo or not. I haven’t tried, but that’s what I would have thought

Yeah, I have it disabled. If I try to set two jobs to buy ammo, every job can buy the ammo.

What.

Badly explained, sorry. This is what I meant:


TEAM_GUN or TEAM_HITMAN

You have just gave me two class names, but im assuming that you are looking said classes to be able to buy ammo if im assuming the correct then this is how.

[lua] GM:AddAmmoType(“pistol”, “Pistol ammo”, “models/Items/BoxSRounds.mdl”, 30, 24, function( ply ) return ply:Team() == TEAM_GUN or ply:Team() == TEAM_HITMAN end)[/lua]

Yeah that’s what I was trying to do. My apologies for the broken sentences I was half awake while writing them. I’ll try that out as soon as I can, thanks for the help.