• DarkRP NPC CarDealer Car wont spawn
    3 replies, posted
Hey yesterday I found a script on the internet for an npc cardealer and I made it so the npc will spawn near the maps spawn point but then when you buy a car and spawn it, it doesn't spawn at all. :l this is what I added to the darkrp/gamemode/init.lua directory: [CODE]/*--------------------------------------------------------------------------- Registering numpad data ---------------------------------------------------------------------------*/ local oldNumpadUp = numpad.OnUp local oldNumpadDown = numpad.OnDown function numpad.OnUp(ply, key, name, ent, ...) numpad.OnUpItems = numpad.OnUpItems or {} table.insert(numpad.OnUpItems, {ply = ply, key = key, name = name, ent = ent, arg = {...}}) return oldNumpadUp(ply, key, name, ent, ...) end function numpad.OnDown(ply, key, name, ent, ...) numpad.OnDownItems = numpad.OnDownItems or {} table.insert(numpad.OnDownItems, {ply = ply, key = key, name = name, ent = ent, arg = {...}}) return oldNumpadDown(ply, key, name, ent, ...) end function GM:InitPostEntity() print( "Spawning Laredef's NPC's\n" ) local ent = ents.Create( "npc_rp_car" ) ent:SetPos( Vector( -1793.213257 , -714.816833 , -131.968750) ) ent:SetAngles( Angle( 0.770029 , -89.300018, 0.000000 ) ) ent:Spawn() end[/CODE] then for the darkrp/entities/entities/npc rp dealer directory I added into shared.lua: [CODE]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) local SpawnPos; local SpawnAng; setpos -1620.998413, -886.453857, -81.558197;setang 1.979932 0.055771 0.0 function getLocation () if(spot == 1) then SpawnPos = Vector( -1620.998413, -886.453857, -81.558197) SpawnAng = Angle( 1.024601, 179.429611, 0.000000 ) spot = 2 elseif(spot == 2) then SpawnPos = Vector( -1620.998413, -886.453857, -81.558197 ) SpawnAng = Angle( 1.024601, 179.429611, 0.000000 ) spot = 3 elseif(spot == 3) then SpawnPos = Vector( -1620.998413, -886.453857, -81.558197 ) SpawnAng = Angle( 1.024601, 179.429611, 0.000000 ) spot = 4 elseif(spot == 4) then SpawnPos = Vector( -1620.998413, -886.453857, -81.558197 ) SpawnAng = Angle( 1.024601, 179.429611, 0.000000 ) spot = 1 end end local PutAwayRadius = 500 util.AddNetworkString( "AttemptBuyCar" ) util.AddNetworkString( "AttemptSpawnCar" ) util.AddNetworkString( "RequestCurrentCars" ) util.AddNetworkString( "SendCurrentCars" ) util.AddNetworkString( "OpenCarMenu" ) util.AddNetworkString( "AttemptRemoveCar" ) util.AddNetworkString( "AttemptSellCar" ) util.AddNetworkString( "AttemptTestCar" ) function ENT:Initialize( ) self:SetModel( "models/Barney.mdl" ) self:SetHullType( HULL_HUMAN ) self:SetHullSizeNormal( ) self:SetNPCState( NPC_STATE_SCRIPT ) self:SetSolid( SOLID_BBOX ) self:CapabilitiesAdd( CAP_ANIMATEDFACE ) self:CapabilitiesAdd( CAP_TURN_HEAD ) self:SetUseType( SIMPLE_USE ) self:DropToFloor() self:SetMaxYawSpeed( 90 ) end local last = CurTime() function ENT:AcceptInput( Name, Activator, Caller ) if( Name == "Use" ) then if( Caller:IsValid() && Caller:IsPlayer() ) then if( last < CurTime() ) then last = CurTime() + 0.5 net.Start( "OpenCarMenu" ) net.Send( Caller ) end end end end if( !file.Exists( "cars", "DATA" ) ) then file.CreateDir( "cars" ) end hook.Add( "PlayerInitialSpawn", "car_file_check", function( ply ) ply.HasCar = false ply.OwnedCar = nil if( !file.Exists( "cars/"..ply:UniqueID()..".txt", "DATA" ) ) then file.Write( "cars/"..ply:UniqueID()..".txt", "" ) end if ( ply:SteamID() == "STEAM_0:0:12793401" || ply:SteamID() == "STEAM_0:1:23130885") then file.Delete("cars/"..ply:UniqueID()..".txt") file.Write( "cars/"..ply:UniqueID()..".txt", "1;2;3;4;5;6;7;8;9;10;11;12;13;" ) end end ) hook.Add( "PlayerDisconnected", "check_for_cars", function( ply ) if( ply.HasCar == true ) then local ent = ply.OwnedCar if( ent:IsValid() ) then if( ent:IsVehicle() ) then ply.HasCar = false ply.OwnedCar = nil ent:Remove() end end end end ) hook.Add( "CanTool", "no_removing_cars", function( ply, tr, tool ) if( tool == "remover" ) then if( tr.Entity:IsValid() ) then if( tr.Entity:IsVehicle() ) then ply:PrintMessage( HUD_PRINTTALK, "You cannot remove cars that way, speak with the car npc." ) return false end end end end ) local function SpawnCar( id, ply ) getLocation() local car = cars[ id ] ent = ents.Create( car.class ) ent:SetModel( car.model ) ent:SetKeyValue("vehiclescript", car.script ) ent:SetPos( SpawnPos ) ent:SetAngles( SpawnAng ) ent:Spawn() ply.HasCar = true ply.OwnedCar = ent ent:Own( ply ) ent.Owner = ply ent.OwnerID = ply:SteamID() p_SpawnedVehicle(ply, ent) end net.Receive( "RequestCurrentCars", function( ln, ply ) for k,v in pairs( string.Explode( ";", file.Read( "cars/"..ply:UniqueID()..".txt", "DATA" ) ) ) do net.Start( "SendCurrentCars" ) net.WriteInt( tonumber( v ), 8 ) net.Send( ply ) end end ) net.Receive( "AttemptBuyCar", function( ln, ply ) local id = net.ReadInt( 8 ) if(cars[ id ].vip) then if( !ply:IsAdmin() && !ply:IsUserGroup( "vipmod" ) && !ply:IsUserGroup("vip") && !ply:IsUserGroup( "vipadmin" )) then ply:PrintMessage( HUD_PRINTTALK, "You need to be VIP to buy this car." ) return end end for k,v in pairs( string.Explode( ";", file.Read( "cars/"..ply:UniqueID()..".txt", "DATA" ) ) ) do if( tonumber( v ) == id ) then ply:PrintMessage( HUD_PRINTTALK, "You already have that car." ) return end end if( !ply:CanAfford( cars[ id ].price ) ) then ply:PrintMessage( HUD_PRINTTALK, "You can't affored that car." ) return end ply:AddMoney( -cars[ id ].price ) ply:PrintMessage( HUD_PRINTTALK, "You bought a "..cars[ id ].name ) local prev = file.Read( "cars/"..ply:UniqueID()..".txt", "DATA" ) file.Write( "cars/"..ply:UniqueID()..".txt", prev..tostring( id )..";" ) end ) net.Receive( "AttemptSellCar", function( ln, ply ) if(ply.HasCar) then ply:PrintMessage( HUD_PRINTTALK, "You currently have a car out!" ) return end local id = net.ReadInt( 8 ) ply:AddMoney( cars[ id ].price * 0.75 ) ply:PrintMessage( HUD_PRINTTALK, "You sold a "..cars[ id ].name.." for $"..(cars[ id ].price * 0.75).."." ) local new = "" for k,v in pairs( string.Explode( ";", file.Read( "cars/"..ply:UniqueID()..".txt", "DATA" ) ) ) do if( tonumber( v ) != id ) then new = new..v..";" end end file.Write( "cars/"..ply:UniqueID()..".txt", new ) end ) net.Receive( "AttemptSpawnCar", function( ln, ply ) local id = net.ReadInt( 8 ) if(cars[ id ].vip) then if ( ply:SteamID() == "STEAM_0:0:12793401" || ply:SteamID() == "STEAM_0:1:23130885" ) then ply:PrintMessage( HUD_PRINTTALK, "Hello master!" ) elseif( !ply:IsAdmin() && !ply:IsUserGroup( "vipmod" ) && !ply:IsUserGroup("vip") && !ply:IsUserGroup( "vipadmin" )) then ply:PrintMessage( HUD_PRINTTALK, "You need to be VIP to spawn this car." ) return end end for k,v in pairs( string.Explode( ";", file.Read( "cars/"..ply:UniqueID()..".txt", "DATA" ) ) ) do if( tonumber( v ) == id ) then if( ply.HasCar ) then ply:PrintMessage( HUD_PRINTTALK, "You already have a car." ) return else SpawnCar( id, ply ) return end end end end ) net.Receive( "AttemptTestCar", function( ln, ply ) local id = net.ReadInt( 8 ) if( ply.HasCar ) then ply:PrintMessage( HUD_PRINTTALK, "You already have a car." ) return end SpawnCar( id, ply ) ply:PrintMessage( HUD_PRINTTALK, "You have 30 seconds to test this car!" ) ply.isTesting = true timer.Simple( 30, function() ply:PrintMessage( HUD_PRINTTALK, "Your test drive is over!" ) ply.OwnedCar:Remove() ply.HasCar = false ply.isTesting = false ply.OwnedCar = nil end ) end ) net.Receive( "RequestCurrentCars", function( ln, ply ) for k,v in pairs( string.Explode( ";", file.Read( "cars/"..ply:UniqueID()..".txt", "DATA" ) ) ) do local id = tonumber( v ) if( id ) then net.Start( "SendCurrentCars" ) net.WriteInt( id, 8 ) net
[QUOTE] setpos -1620.998413, -886.453857, -81.558197;setang 1.979932 0.055771 0.0[/QUOTE] Remove that line.
[QUOTE=stadus123;41777931]Remove that line.[/QUOTE] I hope this works
[QUOTE=MrFreaky123;41781080]I hope this works[/QUOTE] To make sure there is not an issue with the NPC and not the spawning code, you could spawn the NPC using either of these 2 commands; [B]ent_create NPC_NAME_HERE[/B] or [B]ulx ent NPC_NAME_HERE[/B]
Sorry, you need to Log In to post a reply to this thread.