hey anyone know a script that will change the loadout the second time u spawn
basicly my idea is that you start with an ak an deagle but after dieing are punished by giving a lower class weapon so i was wondering if anyone knows of any scripts thanx in advance
[highlight](User was banned for this post ("Undescriptive thread title" - mahalis))[/highlight]
[lua]function GM:PlayerLoadout(ply)
if ply:Deaths() == 0 then
--Loadout 1
else
--Loadout 2
end
end[/lua]
[url=http://wiki.garrysmod.com/?search=Gamemode.PlayerLoadout][I]Gamemode.PlayerLoadout[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url] <-- See this page if you're not making a gamemode
[url=http://wiki.garrysmod.com/?search=Player.Deaths][I]Player.Deaths[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
:science:
thanks im new to this forum (only been posting just today) can already tell your the best of the best but one quick noob question, heres my autorun lua so far
local weapons = {
"weapon_physcannon",
"weapon_physgun",
"gmod_tool",
"gmod_camera",
}
hook.Add("PlayerLoadout","RestrictWeapons",function(ply)
for _,v in ipairs(weapons) do ply:Give(v) end
return true
end)
using ure code would i remove this and then enter the weapons into your code where it says loadout 1 and loadout 2 or would i have to keep this code and then enter the weapons in loadout 1 and loadout 2?
Well assuming the only thing you want to change is giving a deagle on the first spawn you would do this :
[code]local weapons = {
"weapon_physcannon",
"weapon_physgun",
"gmod_tool",
"gmod_camera",
}
hook.Add("PlayerLoadout","CustomLoadout",function(ply)
if ply:Deaths() == 0 then --If the player has yet to die then
ply:Give("weapon_deagle") -- give him his sweet deagle
end
for _,v in ipairs(weapons) do --For key and value pair of the weapons table
ply:Give(v) -- Give the player the content of the value
end
return true --Returning here overrides the gamemode's default loadout.
end)[/code]
Also for readability please post your code in either [noparse] [code][/code] or [lua][/lua] [/noparse] tags.
And I'm not the best of the best!:aaa:
[QUOTE=Dave_Parker;18586283][lua]function GM:PlayerLoadout(ply)
if ply:Deaths() == 0 then
ply:Give("weapon_physgun")
ply:Give("gmod_tool")
else
ply:Give("weapon_physcannon")
ply:Give("gmod_camera")
end
end[/lua]
A bit like that, just with changed weapon entities.[/QUOTE]
That would work assuming you are using this in a gamemode, for a script you need to use hook.Add like in the example I've posted.
[url=http://wiki.garrysmod.com/?search=hook.Add][I]hook.Add[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
hey thanx for the great help guys
worked like a charm after adding this i decided to basicly make it so that ur not only stripped of your ak but rather ur stripped of it and then given another weapon in this case a crowbar so i basicly copied the code used for if player has yet to die ie if deaths = 0 with if deaths = 1 to crowbar however it isnt working i was wondering if you could tell me whats going wrong here thanx in advance
[code]
local weapons = {
"weapon_deagle",
}
hook.Add("PlayerLoadout","CustomLoadout",function(ply)
if ply:Deaths() == 0 then --If the player has yet to die then
ply:Give("weapon_AK47") -- give him his sweet AK47
end
if ply:Deaths() == 1 then --If the player has yet to die then
ply:Give("weapon_crowbar") -- give him his sweet AK47
end
for _,v in ipairs(weapons) do --For key and value pair of the weapons table
ply:Give(v) -- Give the player the content of the value
end
return true --Returning here overrides the gamemode's default loadout.
end)
[/code]
[editline]12:31AM[/editline]
bump
Sorry, you need to Log In to post a reply to this thread.