Is there a script that allows me to add permanent weapons to certain users and the customCheck for the weapons would be by SteamID and not ULX Group? If someone could help me out here that would be great.
I just wrote this for another guy, here you go. It would be great if you learned what the functions did so you are actually learning something. It is untested.
[code]
local AssaultIDs = {}
hook.Add("Initialize", "load", function()
if file.Exists("ids.dat", "DATA") then
AssaultIDs = string.ToTable(file.Read("ids.dat", "DATA"))
end
end)
hook.Add("PlayerLoadout", "Assault Kit", function(ply)
for _, id in pairs(AssaultIDs) do
if ply:SteamID() == id then
ply:Give("m9k_m416")
break
end
end
end)
concommand.Add("addid",function(ply, cmd, args, argStr)
if player.GetBySteamID(args[1]):IsValid() then
table.insert(AssaultIDs, args[1])
file.Write("ids.dat", table.ToString(AssaultIDs))
end
end)
[/code]
[QUOTE=Cornfinder;49886316]I just wrote this for another guy, here you go. It would be great if you learned what the functions did so you are actually learning something. It is untested.
[code]
local AssaultIDs = {}
hook.Add("Initialize", "load", function()
if file.Exists("ids.dat", "DATA") then
AssaultIDs = string.ToTable(file.Read("ids.dat", "DATA"))
end
end)
hook.Add("PlayerLoadout", "Assault Kit", function(ply)
for _, id in pairs(AssaultIDs) do
if ply:SteamID() == id then
ply:Give("m9k_m416")
break
end
end
end)
concommand.Add("addid",function(ply, cmd, args, argStr)
if player.GetBySteamID(args[1]):IsValid() then
table.insert(AssaultIDs, args[1])
file.Write("ids.dat", table.ToString(AssaultIDs))
end
end)
[/code][/QUOTE]
I would put this file in lua/autorun/server correct?
Sorry if I sound like a scrub, I'm just not used to creating my own scripts:/
[QUOTE=bbdcmf;49886415]I would put this file in lua/autorun/server correct?
Sorry if I sound like a scrub, I'm just not used to creating my own scripts:/[/QUOTE]
Yup.
[QUOTE=Cornfinder;49886316]I just wrote this for another guy, here you go. It would be great if you learned what the functions did so you are actually learning something. It is untested.
[code]
local AssaultIDs = {}
hook.Add("Initialize", "load", function()
if file.Exists("ids.dat", "DATA") then
AssaultIDs = string.ToTable(file.Read("ids.dat", "DATA"))
end
end)
hook.Add("PlayerLoadout", "Assault Kit", function(ply)
for _, id in pairs(AssaultIDs) do
if ply:SteamID() == id then
ply:Give("m9k_m416")
break
end
end
end)
concommand.Add("addid",function(ply, cmd, args, argStr)
if player.GetBySteamID(args[1]):IsValid() then
table.insert(AssaultIDs, args[1])
file.Write("ids.dat", table.ToString(AssaultIDs))
end
end)
[/code][/QUOTE]
Yea this code isn't working. There aren't any errors, it just doesn't give me the weapon.
[QUOTE=bbdcmf;49886447]Yea this code isn't working. There aren't any errors, it just doesn't give me the weapon.[/QUOTE]
It doesn't magically work... I encouraged you to look at the functions. There is a console command that is added called addid. If you type: addid MYSTEAMID and put in your steamid, it should work.
[QUOTE=Cornfinder;49886543]It doesn't magically work... I encouraged you to look at the functions. There is a console command that is added called addid. If you type: addid MYSTEAMID and put in your steamid, it should work.[/QUOTE]
Oh, my bad, I just misunderstood what you were saying. But, when I tried it it didn't do anything.
[QUOTE=Cornfinder;49886543]It doesn't magically work... I encouraged you to look at the functions. There is a console command that is added called addid. If you type: addid MYSTEAMID and put in your steamid, it should work.[/QUOTE]
why are you giving him bad examples just asking?
[QUOTE=bbdcmf;49886718]Oh, my bad, I just misunderstood what you were saying. But, when I tried it it didn't do anything.[/QUOTE]
Oh the hook used in is wrong for this case. Just replace where it says
[Code]hook.Add("PlayerLoadout", "Assault Kit", function[/Code]
With:
[Code]hook.Add("PlayerSpawn", "Assault Kit", function[/Code]
Sorry, I didn't read what you wanted all the way. If it doesn't work after that then I'm not sure.
[QUOTE=Cornfinder;49887534]Oh the hook used in is wrong for this case. Just replace where it says
[Code]hook.Add("PlayerLoadout", "Assault Kit", function[/Code]
With:
[Code]hook.Add("PlayerSpawn", "Assault Kit", function[/Code]
Sorry, I didn't read what you wanted all the way. If it doesn't work after that then I'm not sure.[/QUOTE]
Yea, that's not working still :/
[editline]7th March 2016[/editline]
Bump
[QUOTE=bbdcmf;49887903]Yea, that's not working still :/
[editline]7th March 2016[/editline]
Bump[/QUOTE]
-snip- That code was bad, here is the fixed version:
[code]
local KitIDS = {}
hook.Add("Initialize", "load", function()
if file.Exists("kitids.dat", "DATA") then
KitIDS = util.JSONToTable(file.Read("kitids.dat", "DATA"))
PrintTable(KitIDS)
end
end)
local KitWeapons = {
"weapon_ar2",
"weapon_bugbait" -- Make sure not to have a comma at the end of the last item.
}
hook.Add("PlayerSpawn", "Assault Kit", function(ply)
for _, id in pairs(KitIDS) do
if ply:SteamID() == id then
for _, weps in pairs(KitWeapons) do
ply:Give(weps)
end
break
end
end
end)
concommand.Add("addid",function(ply, cmd, args, argStr)
if player.GetBySteamID(args[1]):IsValid() then
table.insert(KitIDS, args[1])
file.Write("kitids.dat", util.TableToJSON(KitIDS))
end
end)
[/code]
In singleplayer, your steamid is always going to be STEAM:0:0:0. When adding a ID, do it like this: addid "STEAM ID HERE" After adding a ID, next time they spawn, they will get the guns. To add or change the guns they get, change the table KitWeapons:
[code]
local KitWeapons = {
"weapon_ar2",
"weapon_bugbait"
}
[/code]
So if I wanted to get rid of the other items and add a 357, crossbow, and smg, I would go to the weapons tab and for each gun, right click and press Copy To Clipboard and put them like so:
[code]
local KitWeapons = {
"weapon_357",
"weapon_smg1",
"weapon_crossbow"
}
[/code]
Here is a another example with a rpg:
[code]
local KitWeapons = {
"weapon_rpg"
}
[/code]
Hope this helps!
[QUOTE=Cornfinder;49888328]-snip- That code was bad, here is the fixed version:
[code]
local KitIDS = {}
hook.Add("Initialize", "load", function()
if file.Exists("kitids.dat", "DATA") then
KitIDS = util.JSONToTable(file.Read("kitids.dat", "DATA"))
PrintTable(KitIDS)
end
end)
local KitWeapons = {
"weapon_ar2",
"weapon_bugbait" -- Make sure not to have a comma at the end of the last item.
}
hook.Add("PlayerSpawn", "Assault Kit", function(ply)
for _, id in pairs(KitIDS) do
if ply:SteamID() == id then
for _, weps in pairs(KitWeapons) do
ply:Give(weps)
end
break
end
end
end)
concommand.Add("addid",function(ply, cmd, args, argStr)
if player.GetBySteamID(args[1]):IsValid() then
table.insert(KitIDS, args[1])
file.Write("kitids.dat", util.TableToJSON(KitIDS))
end
end)
[/code]
In singleplayer, your steamid is always going to be STEAM:0:0:0. When adding a ID, do it like this: addid "STEAM ID HERE" After adding a ID, next time they spawn, they will get the guns. To add or change the guns they get, change the table KitWeapons:
[code]
local KitWeapons = {
"weapon_ar2",
"weapon_bugbait"
}
[/code]
So if I wanted to get rid of the other items and add a 357, crossbow, and smg, I would go to the weapons tab and for each gun, right click and press Copy To Clipboard and put them like so:
[code]
local KitWeapons = {
"weapon_357",
"weapon_smg1",
"weapon_crossbow"
}
[/code]
Here is a another example with a rpg:
[code]
local KitWeapons = {
"weapon_rpg"
}
[/code]
Hope this helps![/QUOTE]
Would this code allow me to add multiple IDs and give each ID a different weapon, because that is what I was looking for? Also I'm getting this error:
[ERROR] lua/autorun/server/permaweapon.lua:26: attempt to index a boolean value
1. unknown - lua/autorun/server/permaweapon.lua:26
2. unknown - lua/includes/modules/concommand.lua:69
[lua]
for k, v in pairs(player:GetAll()) do
if v:SteamID() == STEAM:0:0:0 then
v:Give("weapon_fists")
end
end
[/lua]
Seems to not work. Not sure why.
Bump
[lua]
hook.Add("PlayerSpawn", "ajifnauiownf", function()
for k, v in pairs(player:GetAll()) do
if v:SteamID() == ENTER YOUR STEAMID HERE then
ply:Give("ENTER THE WEAPON HERE")
break
end
end
end)
[/lua]
Try this, not sure if it'll work. But try it and let me know.
[QUOTE=Percipience;49889919][lua]
hook.Add("PlayerSpawn", "ajifnauiownf", function()
for k, v in pairs(player:GetAll()) do
if v:SteamID() == ENTER YOUR STEAMID HERE then
ply:Give("ENTER THE WEAPON HERE")
break
end
end
end)
[/lua]
Try this, not sure if it'll work. But try it and let me know.[/QUOTE]
pls dont, if you cant see the errors dont try
[QUOTE=Sir TE5T;49889966]pls dont, if you cant see the errors dont try[/QUOTE]
You do realize he can test right?
:speechless:
[QUOTE=Percipience;49889919][lua]
hook.Add("PlayerSpawn", "ajifnauiownf", function()
for k, v in pairs(player:GetAll()) do
if v:SteamID() == ENTER YOUR STEAMID HERE then
ply:Give("ENTER THE WEAPON HERE")
break
end
end
end)
[/lua]
Try this, not sure if it'll work. But try it and let me know.[/QUOTE]
Completely broke jobs when players join the server. Everyone is just a grey model without any weapons
Screenshot: [url]http://steamcommunity.com/profiles/76561198049496474/screenshot/498017719620294427[/url]
[QUOTE=Percipience;49889977]You do realize he can test right?
:speechless:[/QUOTE]
*wastes time trying to use shitty code* :goodjob:
[QUOTE=Sir TE5T;49890010]*wastes time trying to use shitty code* :goodjob:[/QUOTE]
It's not wasting time if we're progressing :P
[QUOTE=bbdcmf;49890016]It's not wasting time if we're progressing :P[/QUOTE]
your taking steps back, not forward
[QUOTE=Sir TE5T;49890010]*wastes time trying to use shitty code* :goodjob:[/QUOTE]
Call it what you will.
Anyways, OP I've tested the following:
[lua]
local function spawn( ply )
for k, v in pairs( player.GetAll() ) do
if v:SteamID() == "STEAM_0:0:0" then
v:Give( "weapon_fists" )
end
end
end
hook.Add( "PlayerSpawn", "awifjnaiu", spawn )
[/lua]
Replace all that code with that.
Tested and working.
A silly mistake on me haha. It returns v:SteamID() as a string lel.
Anyways, replace weapon_fists with your weapon, and STEAM_0:0:0 with your steamid.
Don't mind that other guy. Some people are just simple-minded.
[QUOTE=Percipience;49890021]Call it what you will.
Anyways, OP I've tested the following:
[lua]
local function spawn( ply )
for k, v in pairs( player.GetAll() ) do
if v:SteamID() == "STEAM_0:0:0" then
v:Give( "weapon_fists" )
end
end
end
hook.Add( "PlayerSpawn", "awifjnaiu", spawn )
[/lua]
Replace all that code with that.
Tested and working.
A silly mistake on me haha. It returns v:SteamID() as a string lel.
Anyways, replace weapon_fists with your weapon, and STEAM_0:0:0 with your steamid.
Don't mind that other guy. Some people are just simple-minded.[/QUOTE]
could just make it easier for him and actually make 2 tables, or just rewrite it <-- best option
[QUOTE=Percipience;49890021]Call it what you will.
Anyways, OP I've tested the following:
[lua]
local function spawn( ply )
for k, v in pairs( player.GetAll() ) do
if v:SteamID() == "STEAM_0:0:0" then
v:Give( "weapon_fists" )
end
end
end
hook.Add( "PlayerSpawn", "awifjnaiu", spawn )
[/lua]
Replace all that code with that.
Tested and working.
A silly mistake on me haha. It returns v:SteamID() as a string lel.
Anyways, replace weapon_fists with your weapon, and STEAM_0:0:0 with your steamid.
Don't mind that other guy. Some people are just simple-minded.[/QUOTE]
IT WORKED, THANK YOU SO MUCH!!!!
[QUOTE=bbdcmf;49890054]IT WORKED, THANK YOU SO MUCH!!!![/QUOTE]
Of course, let me know if I can do anything else for you :)
[QUOTE=Percipience;49890056]Of course, let me know if I can do anything else for you :)[/QUOTE]
How would I give another player a different weapon, while giving myself one?
NEVERMIND, I figured it out myself. Thanks anyway :P
[QUOTE=Sir TE5T;49887488]why are you giving him bad examples just asking?[/QUOTE]
I wrote that for something completely else and I thought it would point him in the right direction. You don't complain about free help. Also, I am not on my computer 24/7 and can't test it. If you have ever wrote a script, 99% of the time it doesn't work the first try. Again, this was for something completely else. I thought he would look at it and use it to point him in the right direction to do it himself
Sorry, you need to Log In to post a reply to this thread.