Issue with /buyjeep command.

Hey guys,

I have an issue with the ‘/buyjeep’ command that locololo2 and Falco worked out (I think).

Basically, I’ve edited the script a little to change the prices, and I’ve made it so that you can buy the Airboat, too. My only issue is when you type /buyjeep or /buyboat, it spawns… in you.

I was wondering if there’s a way for it to spawn in front of you, or where you’re looking.

Here’s the current code I’m using from main.lua (Jeep and Airboat) - please note: It’s still not done. Just got a little bit more editing to do.


function BuyJeep(ply)  
    if args == "" then return "" end  
      
    local trace = { }  
    trace.start = ply:EyePos()  
    trace.endpos = trace.start + ply:GetAimVector() * 85  
    trace.filter = ply  
  
    if RPArrestedPlayers[ply:SteamID()] then return "" end  
    local tr = util.TraceLine(trace)  
  
    local cost = 190  
      
    if not ply:CanAfford(cost) then  
        Notify(ply, 1, 4, "Cannot afford this!")  
        return ""  
    end  
  
    if ply:GetNWInt("maxvehicles") == CfgVars["maxvehicles"] then    // This might not work. I added it to admincc.lua but it still might not work  
        // If you don't want a restriction, just remove it.  [Notify(ply, 1, 3, "Max Vehicles reached!")]
        return ""  
    end  
  
    if ply:Team() == TEAM_CAR then  
        ply:AddMoney(-190)  
        Notify(ply, 1, 3, "You bought a Jeep for $190")  
        local car = ents.Create("prop_vehicle_jeep_old")  
        car:SetModel("models/buggy.mdl")  
        car:SetKeyValue("vehiclescript","scripts/vehicles/jeep_test.txt")  
        car:SetNWEntity("owning_ent", ply)  
        car:SetNWString("Owner", "Shared")  
        car:SetPos(tr.HitPos)  
        car.nodupe = true  
        car:Spawn()  
        car.SID = ply.SID  
        return ""  
    else  
        Notify(ply, 1, 3, "You must be a Car Dealer to buy this.")  
    end  
    return ""  
end  
AddChatCommand("/buyjeep", BuyJeep)  

function BuyAirboat(ply)  
    if args == "" then return "" end  
      
    local trace = { }  
    trace.start = ply:EyePos()  
    trace.endpos = trace.start + ply:GetAimVector() * 85  
    trace.filter = ply  
  
    if RPArrestedPlayers[ply:SteamID()] then return "" end  
    local tr = util.TraceLine(trace)  
  
    local cost = 140  
      
    if not ply:CanAfford(cost) then  
        Notify(ply, 1, 4, "Cannot afford this!")  
        return ""  
    end  
  
    if ply:GetNWInt("maxvehicles") == CfgVars["maxvehicles"] then    // This might not work. I added it to admincc.lua but it still might not work  
        // If you don't want a restriction, just remove it.  [Notify(ply, 1, 3, "Max Vehicles reached!")]
        return ""  
    end  
  
    if ply:Team() == TEAM_CAR then  
        ply:AddMoney(-140)  
        Notify(ply, 1, 3, "You bought an Airboat for $140")  
        local car = ents.Create("prop_vehicle_airboat")  
        car:SetModel("models/airboat.mdl")  
        car:SetKeyValue("vehiclescript","scripts/vehicles/airboat.txt")  
        car:SetNWEntity("owning_ent", ply)  
        car:SetNWString("Owner", "Shared")  
        car:SetPos(tr.HitPos)  
        car.nodupe = true  
        car:Spawn()  
        car.SID = ply.SID  
        return ""  
    else  
        Notify(ply, 1, 3, "You must be a Car Dealer to buy this.")  
    end  
    return ""  
end  
AddChatCommand("/buyairboat", BuyAirboat)
AddChatCommand("/buyboat", BuyAirboat)  

I’m looking for any reply that might help me fix this issue.

Thanks in advance.

EDIT: I think it’s something to do with “car:SetPos(tr.HitPos)” but I’m not quite sure what to do…

set ‘85’ to ‘512’.
I will also just point out that this is a very badly written function. :3:

I remember that in my old thread… Thats very old… Too old. Falco has added a way of buying new cars in the DarkRP svn.

This thread should be locked now. I found the problem.

I failed with the addentities.lua file. It now all comes up in the F4 menu.

Thanks for your help, though! :smiley: