I ran into a few problems but someone managed to help me earlier and now i have no idea whats wrong
The guy who originally made this addon had it programmed like this
[CODE]function BuyPistol(ply, ent)
if not ply:CanAfford(200) then
Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "Gun")) return "" else
ply:AddMoney(-200)
local pistol = ents.Create("weapon_pistol")
local trace = ply:GetEyeTraceNoCursor()
pistol:SetPos( trace.HitPos )
pistol:Spawn()
end
end
concommand.Add("buy_prius", BuyPistol)[/CODE]
And that was just for guns but im modifying it so you can buy, save and load cars but for some reason im getting this error
[CODE][ERROR] gamemodes/darkrp/entities/entities/parking_garage_manager/init.lua:46: attempt to call global 'LocalPlayer' (a nil value)
1. unknown - gamemodes/darkrp/entities/entities/parking_garage_manager/init.lua:46
2. unknown - lua/includes/modules/concommand.lua:69[/CODE]
And this is what i changed the script to
[CODE]function BuyVehicle(name, price, model, entity)
--setpos -4305.939453 -10535.313477 135.178558;setang 2.420009 -5.639963 0.000000
local ply = LocalPlayer()
if not ply:CanAfford(price) then
Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "Vehicle - " .. name)) return "" else
ply:AddMoney(-price)
local car = ents.Create(entity)
car:SetPos( -4305.939453, -10535.313477, 135.178558 )
car:Spawn()
ply:EnterVehicle(car)
end
end
concommand.Add("buy_vehicle", BuyVehicle)
[/CODE]
Is there a different way to call the player in a serverside script?
This script is serverside, LocalPlayer is used on clientside.
You could try this [UNTESTED]:
[LUA]function BuyVehicle(ply, name, price, model, entity)
--setpos -4305.939453 -10535.313477 135.178558;setang 2.420009 -5.639963 0.000000
if not ply:CanAfford(price) then
Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "Vehicle - " .. name)) return "" else
ply:AddMoney(-price)
local car = ents.Create(entity)
car:SetPos( -4305.939453, -10535.313477, 135.178558 )
car:Spawn()
ply:EnterVehicle(car)
end
end
concommand.Add("buy_vehicle", BuyVehicle)[/LUA]
I hope this can help you pal ;)
LocalPlayer() doesn't exit on servers.
try this:
[code]
function BuyVehicle(ply,_,args)
--setpos -4305.939453 -10535.313477 135.178558;setang 2.420009 -5.639963 0.000000
local name = args[1]
local price = args[2]
local model = args[3]
local entity = args[4]
if not ply:CanAfford(price) then
Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "Vehicle - " .. name)) return "" else
ply:AddMoney(-price)
local car = ents.Create(entity)
car:SetPos( -4305.939453, -10535.313477, 135.178558 )
car:Spawn()
ply:EnterVehicle(car)
end
end
concommand.Add("buy_vehicle", BuyVehicle)
[/code]
However, This could be exploitable easily... Try storing item data server side, So that the values don't get processed by the client other than for GUI.
At least now im getting somewhere so thanks but now its saying its a bad argument, so then i decided to go to my clientside script and put LocalPlayer() in for its argument where i run the command and it still says its a bad arguement
[CODE]TradeButton:AddOption("Yes.", function() RunConsoleCommand("buy_vehicle", LocalPlayer(), name, price, model, entity) TradeFrame:Close() end )
[/CODE]
Ill try your method now dingusnin
Alright thank you so much now its just saying i tried to use a null entity, am i spawning the car in a wrong way?
[QUOTE='[SI] Nynex;41410181']At least now im getting somewhere so thanks but now its saying its a bad argument, so then i decided to go to my clientside script and put LocalPlayer() in for its argument where i run the command and it still says its a bad arguement
[CODE]TradeButton:AddOption("Yes.", function() RunConsoleCommand("buy_vehicle", LocalPlayer(), name, price, model, entity) TradeFrame:Close() end )
[/CODE]
Ill try your method now dingusnin[/QUOTE]
Honestly, I think you should rethink how this is done right now. Because just at looking at this code, I can make other players buy vehicles, And on top of that, I can put a negative value for price, And both gain money and a car.
RunConsoleCommand requires text as an argument.
If you want to continue with the way you are doing things, The only way you could do it is to pass the EntID instead of the entity object.
Heres what you should be doing:
Store car data (Unique Item ID, Price, Model, Position...) Shared, Both include it on the client and the server so that: The client can use it for the GUI and buying stuff, But you will only have to pass the car ID. This will prevent the exploits i have pointed out.
As for passing the player entity, On the server, The first argument in the callback function is the Player running the command.
Hope this helps.
Alright thank you ill attempt to make it differently
Sorry, you need to Log In to post a reply to this thread.