I Require Some LUA Help

I would like to make a car system similar to PERP’s, to where if someone buys a gamemode (from an NPC), the car spawns out back (or in a garage) and can be claimed again after the server crashes. I will be very thankful to anyone who answers this. Thank you,
-Mr Films

This should offer basic help on how to set up and snpc :smiley:

Thank you for the assistance, but I would still like to know how to make a system to whwere they could reclaim the car. :stuck_out_tongue:

for it to be claimed after a server crash, you might want to set a variable like <carname> = 0 and if they buy a car then it equals 1. then you would check if the variable is 1 and give them the car if it is :D.

NOTE: you might want to use a table and make it rphascar = <number of the car in your table>. It might be a little more complicated than the first, but will keep your code clean.

Itches Head. Ow. I am confused. Anyone who could provide a code? That would be REALLY helpful.

Don’t listen to that guy.

Does your gamemode use SQL?

umm, I could provide an example off the top of my head…

[lua]
function savecar( ply )
– set car number through derma here
end
function givecar( ply )
if RPhascar == 1 then
– give car 1
end
if RPhascar == 2 then
– give car 2
end
end
[/lua]
that isn’t using tables if you want a tables version ask :smiley:

you can use sql to store info about the car etc in string or a number up to you, also if your using different types of cars you can set if the player has one or more in the form of a string table (i think) ie. “jeep”,“airboat” or 1,2 if they are named by numbers

[lua]
sql.Query( “CREATE TABLE IF NOT EXISTS ‘player_cars’ (‘steamid’ TEXT NOT NULL PRIMARY KEY, ‘cars’ TEXT NOT NULL );”)
[/lua]

code for when they buy the car
[lua]
sql.Query(“INSERT INTO ‘player_cars’ WHERE ‘steamid’ =” …sql.SQLStr(ply:SteamID) …";")
[/lua]

hope thats all ok

why did you tell him not to listen to me that is how I save cars on my rp gamemode…

Oh you wanted a sql version?

I do not use SQL on my gamemode. And I hate to say it guys, but I am running on DarkRP 2.4.1. I am trying to make DarkRP more realistic/better, and not full of minges. I am sorry if I made you guys mad because most of you facepunch users hate DarkRP, but, anyways, just a code would be nice. I already have the Entitie for the NPC to purchase the car, but I need to know how to make it so that the car would spawn and so that people can reclaim them. Thanks for the help guys.
(By the way, I do not use SQL.)

if your using darkrp you can use sql

I do not know how to use it, though.

[lua]
–In your derma menu set this networked integer …dermachoicenumber is the choice of the derma menu.
ply:SetNWInt(“RPhascar”, …dermachoicenumber)

function givecar( ply )
self:GetNWInt( “RPhascar” )
if ply:RPhascar = “1” do
–Give them car1, look in your gamemode for the function to do so.
end

if ply:RPhascar = "2" do
	--Give them car2
end

end
[/lua]
If that’s to sloppy for you don’t use it.

That should do just fine. So basically, I can just copy/paste this into the SNPC Derma Menu (which is actually located in the cl_init.lua)?

ok… em use this in the bit where the player buys the car, or its spawned

[lua]
local hascar sql.QueryRow(“SELECT ‘cars’ FROM ‘player_cars’ WHERE ‘steamid’ =” …sql.SQLStr(activator:SteamID()) …";")
if(!hascar) then
sql.Query(“INSERT INTO ‘player_cars’ VALUES(” …sql.SQLStr(activator:SteamID()) …",(code to identify the car));")
end
[/lua]

again… i hope thats all ok :stuck_out_tongue:

I don’t use SQL…

sorry just seen your reply to FpsGlock there ok never mind then

umm no it’s not ready to go you have to fill in some functions like the function to give the player a car, and the dermachoice thing I put in needs to be changed to fit your derma menu.

I would also put a console command or a say command in for that last function. (givecar function) I also set a networked function so that you could put it in a different file…

kamern never posted why to not listen to me. I think it might have been cause my first code was a little off, I forgot you were using a derma menu to give the car.

Because this won’t save over from a server crash, show him how to save it to a text file.

oh, I was thinking of that when deciding to show him the sql version of my post.

When you (OP) said everyone hates darkrp, alot of user would recommend it to new coders because it’s a very easy to code script. a gamemode like cider is very fragile, one bad line or something would just blow the whole thing to pieces.