[B]Hello[/B] im working on a DarkRP edit, and i try to do so your weapons is being saved, so you will spawn with you weapon everytime you join.
I have custom NPC shops on the map, and if you buy a weapon you are going to have the same weapon until you drop it. When you drop it/sell/delete, then the script is going to delete the saved weapons from the database...
Im not a proffesional Lua coder, but i know its not that big code to make, if some of you guys could help me a bit.
I tryied out to make it with the file.CreateDir() function and file.Write() function, but i totally failed :(
So im begging you guys... PLEASE help me..
What do you need help with exactly?
If it is the data saving you could have their data saved within their table and glon.encode() it to a file with their uniqueID or something. When the player initially spawns, then you can load their data by checking their uniqueID against all the files within the diretory you saved it in.
[QUOTE=Chessnut;34290737]What do you need help with exactly?
If it is the data saving you could have their data saved within their table and glon.encode() it to a file with their uniqueID or something. When the player initially spawns, then you can load their data by checking their uniqueID against all the files within the diretory you saved it in.[/QUOTE]
Look im using the derp inventory system.
if you buy a weapon from the npc, and leaves the server and joins it again, i wan't to load the weapon he bought into the inventory, so he doesent need to save money and buy it again. Do you understand ?
Sorry my bad english...
So you need to use a file.Write() or SQL saving system, then just do ply:Give() during spawn if their Steam ID matches your files.
Saving/loading is always a pain, but it's a simple concept. What you do is, when the player buys from the NPC, you grab the weapon class that they bought, say a P228.
You would take this, and grab the user's name and UniqueID as well, then write them to a text-file. Then, when the player reconnects, you look through your data folder for the file, read for the class inside, then give them that weapon.
I can't really provide the CODE for it, college work right now, but you just need to walk through it one step at a time, and get each part of it working. Start with saving, then try loading, then make the whole script.
[QUOTE=Killer_Steel;34294149]So you need to use a file.Write() or SQL saving system, then just do ply:Give() during spawn if their Steam ID matches your files.
Saving/loading is always a pain, but it's a simple concept. What you do is, when the player buys from the NPC, you grab the weapon class that they bought, say a P228.
You would take this, and grab the user's name and UniqueID as well, then write them to a text-file. Then, when the player reconnects, you look through your data folder for the file, read for the class inside, then give them that weapon.
I can't really provide the CODE for it, college work right now, but you just need to walk through it one step at a time, and get each part of it working. Start with saving, then try loading, then make the whole script.[/QUOTE]
Thank you soooo much, it helped me, it were really simple thought, but as i said, i just started with Lua..
Thank you one more time :) really helpful !
[editline]19th January 2012[/editline]
[QUOTE=Killer_Steel;34294149]So you need to use a file.Write() or SQL saving system, then just do ply:Give() during spawn if their Steam ID matches your files.
Saving/loading is always a pain, but it's a simple concept. What you do is, when the player buys from the NPC, you grab the weapon class that they bought, say a P228.
You would take this, and grab the user's name and UniqueID as well, then write them to a text-file. Then, when the player reconnects, you look through your data folder for the file, read for the class inside, then give them that weapon.
I can't really provide the CODE for it, college work right now, but you just need to walk through it one step at a time, and get each part of it working. Start with saving, then try loading, then make the whole script.[/QUOTE]
Just one more question to go. Do i need to put this in only serveside code? or anything in shared.lua or client side ?
The actual saving is done serverside. Depends on how the buy code was made, but all you're doing is adding a couple lines to that.
[QUOTE=Killer_Steel;34296365]The actual saving is done serverside. Depends on how the buy code was made, but all you're doing is adding a couple lines to that.[/QUOTE]
Ok :) I will try. Ill ask for help if i need anything else :) Thanks !
[QUOTE=Killer_Steel;34296365]The actual saving is done serverside. Depends on how the buy code was made, but all you're doing is adding a couple lines to that.[/QUOTE]
Ok, i need some help here,
I tried to make this,
if file.Exists("wep_save/"..ply:UniqueID().."/weapon.txt") then
local File = file.Read("wep_save/"..ply:UniqueID().."/weapon.txt")
ply:Give(File)
else
file.CreateDir("wep_save/"..ply:UniqueID().."/weapon.txt")
end
in the function
function GM:PlayerLoadout(ply)
end
but it doesent make the directory :(
Please help :(
[editline]22nd January 2012[/editline]
[QUOTE=linslusa;34346012]Ok, i need some help here,
I tried to make this,
if file.Exists("wep_save/"..ply:UniqueID().."/weapon.txt") then
local File = file.Read("wep_save/"..ply:UniqueID().."/weapon.txt")
ply:Give(File)
else
file.CreateDir("wep_save/"..ply:UniqueID().."/weapon.txt")
end
in the function
function GM:PlayerLoadout(ply)
end
but it doesent make the directory :(
Please help :([/QUOTE]
I just noticed i can't create the actually file when doing file.CreateDir().
Can i do file.Write("wep_save/..ply:UniqueID()../THEN CREATE THE FILE HER ??????")
You can't make a file with file.CreateDir. You have to use file.Write instead. The directory will be made if it doesn't exist already.
[QUOTE=Chessnut;34346792]You can't make a file with file.CreateDir. You have to use file.Write instead. The directory will be made if it doesn't exist already.[/QUOTE]
ok, also file.Write("wep_save/..ply:UniqueID()../weapon.txt","CONTENT TO SAVE")
???
Yes.
[QUOTE=Chessnut;34348385]Yes.[/QUOTE]
when you buy a weapon, a console command liek this is being called
RunConsoleCommand("save_wep")
and the function that is being called is:
function wep_sav(ply, weapon)
if file.Exists("/wep_save/"..ply:UniqueID().."/weapon.txt") then
return false
else
local ply = weapon:GetOwner()
file.CreateDir("/wep_save/"..ply:UniqueID())
file.Write("/wep_save/"..ply:UniqueID().."/weapon.txt",weapon:GetClass())
end
end
concommand.Add("save_wep",wep_sav)
BUT!! I do get this error:
[gamemodes\darkrp\gamemode\sv_gamemode_functions.lua:585] attempt to call method
'UniqueID' (a nil value)
???
[editline]23rd January 2012[/editline]
[QUOTE=Chessnut;34348385]Yes.[/QUOTE]
when you buy a weapon, a console command liek this is being called
RunConsoleCommand("save_wep")
and the function that is being called is:
function wep_sav(ply, weapon)
if (SERVER) then
if file.Exists("/wep_save/"..ply:UniqueID().."/weapon.txt") then
return
else
local ply = weapon:GetOwner()
file.CreateDir("/wep_save/"..ply:UniqueID())
file.Write("/wep_save/"..ply:UniqueID().."/weapon.txt",weapon:GetClass())
end
end
end
concommand.Add("save_wep",wep_sav)
BUT!! I do get this error:
[gamemodes\darkrp\gamemode\sv_gamemode_functions.lua:585] attempt to call method
'UniqueID' (a nil value)
???
-snip-
[QUOTE=Greatie;34354264]-snip-[/QUOTE]
huh...?
[lua]
concommand.Add("save_wep", function(client, command, arguments)
local wep = client:GetActiveWeapon();
if ( ValidEntiy(wep) ) thrn
local class = wep:GetClass();
file.Write("wep_save/"..client:UniqueID().."/weapon.txt", class);
end;
end);
[/lua]
[QUOTE=Chessnut;34356936][lua]
concommand.Add("save_wep", function(client, command, arguments)
local wep = client:GetActiveWeapon();
if ( ValidEntiy(wep) ) thrn
local class = wep:GetClass();
file.Write("wep_save/"..client:UniqueID().."/weapon.txt", class);
end;
end);
[/lua][/QUOTE]
i love you man, thanks.. i learned something rosat :F
[editline]24th January 2012[/editline]
[QUOTE=linslusa;34370795]i love you man, thanks.. i learned something today :D[/QUOTE]
Also, please use lua tags next time.
Ok, im still getting an error, and its this
[gamemodes\darkrp\gamemode\sv_gamemode_functions.lua:586] attempt to call method
'GetActiveWeapon' (a nil value)
With this Lua script
[CODE]
concommand.Add("save_wep", function(client, command, arguments)
local wep = client:GetActiveWeapon();
if ( ValidEntiy(wep) ) then
local class = wep:GetClass();
file.Write("wep_save/"..client:UniqueID().."/weapon.txt", class);
end;
end);
[/CODE]
[QUOTE=linslusa;34393886]Ok, im still getting an error, and its this
[gamemodes\darkrp\gamemode\sv_gamemode_functions.lua:586] attempt to call method
'GetActiveWeapon' (a nil value)
With this Lua script
[CODE]
concommand.Add("save_wep", function(client, command, arguments)
local wep = client:GetActiveWeapon();
if ( ValidEntiy(wep) ) then
local class = wep:GetClass();
file.Write("wep_save/"..client:UniqueID().."/weapon.txt", class);
end;
end);
[/CODE][/QUOTE]
What is client?
client is the same as ply, pl, and what not.
So, can somone help me with that error ?
Are you dead
Sorry, you need to Log In to post a reply to this thread.