My weapon loadout function is not giving anyone weapons when the player spawns,
[lua]
function GM:PlayerLoadout( ply )
if ply:IsAdmin() then
ply:Give( "weapon_physcannon" ) // A Gravity gun
ply:Give( "weapon_physgun" ) // A Physics gun
ply:Give( "gmod_tool" ) // and don't forget the tool gun!
elseif ply:IsSuperAdmin() then
ply:Give( "weapon_physcannon" ) // A Gravity gun
ply:Give( "weapon_physgun" ) // A Physics gun
ply:Give( "weapon_pistol" )
ply:Give( "weapon_ar2" )
ply:Give( "weapon_smg1" )
ply:Give( "weapon_357" )
ply:Give( "gmod_tool" ) // and don't forget the tool gun!
else
ply:Give( "weapon_physcannon" ) //Assuming he is, then give him Gravity gun
ply:Give( "weapon_physgun" ) // Physics gun
ply:Give( "gmod_tool" ) // and the gmod tool
end
return true
end
[/lua]
Any ideas?
Make sure you are running it on the server (init.lua or any file it includes), also you do not need to return anything.
You do need to return true.
[B][URL="http://wiki.garrysmod.com/?title=Gamemode.PlayerLoadout"]Gamemode.PlayerLoadout [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B]
[QUOTE=Teddi Orange;20554871]You do need to return true.
[B][URL="http://wiki.garrysmod.com/?title=Gamemode.PlayerLoadout"]Gamemode.PlayerLoadout [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B][/QUOTE]
No you don't.
You return true only when you hook the function, you do it to stop any other PlayerLoadout hooks from running. He is not hooking anything, he is overriding the actual gamemode function.
Ok, I'll try removing the true.
[QUOTE=KillerLUA;20558446]Ok, I'll try removing the true.[/QUOTE]
I doubt that will fix your problem, are you sure you are running that on the server?
Put the code with out the function in PlayerSpawn and wallah your fix is true.
[QUOTE=Cubar;20560970]Put the code with out the function in PlayerSpawn and wallah your fix is true.[/QUOTE]
You do know that PlayerLoadout is simply called in PlayerSpawn.
@OP: You might have a PlayerLoadout hook in one of your addons that is returning something and stopping this from running.
[QUOTE=Cubar;20560970]Put the code with out the function in PlayerSpawn and wallah your fix is true.[/QUOTE]
Genius, he cant get PlayerLoadout to be called, so lets just call it from PlayerSpawn instead.
We've got so many smart people here at Facepunch.
Done, it worked. Thanks for all the quick replys!
[QUOTE=KillerLUA;20572537]Done, it worked. Thanks for all the quick replys![/QUOTE]
What did you actually do to fix it?
Like you said, I renamed the function to GiveItems
and called it from PlayerInitialSpawn and PlayerSpawn.
[QUOTE=KillerLUA;20572989]Like you said, I renamed the function to GiveItems
and called it from PlayerInitialSpawn and PlayerSpawn.[/QUOTE]
I never said to do that, but if it works who cares.
[QUOTE=MakeR;20574179]I never said to do that, but if it works who cares.[/QUOTE]
Actually i said it trying to steal my idea. :science:
[QUOTE=Cubar;20576580]Actually i said it trying to steal my idea. :science:[/QUOTE]
It wasn't a good idea, the PlayerLoadout function should work as is. There is obviously something wrong with his code and doing what you suggested is just taking a hacky shortcut, which [b]may[/b], in the long run, cause more problems than it solves.
[QUOTE=Dave_Parker;20576685]It should just work properly damnit! Let's turn this into a discussion thread about if gamemode functions should be called before hooks. Unless they already do.
[editline]10:21PM[/editline]
In which case his code should have worked.[/QUOTE]
AFAIK gamemode functions are called last, after all the hooks have been run. This means that he must be returning something in one of those hooks to prevent the PlayerLoadout functions from being called.
I don't think if blah then blah works in PlayerLoadout last time i tried. >.>
[QUOTE=Cubar;20580859]I don't think if blah then blah works in PlayerLoadout last time i tried. >.>[/QUOTE]
Why wouldn't an if statement work in PlayerLoadout?
If you're making a gamemode and overwriting PlayerSpawn, then PlayerLoadout has no real reason to exist anymore, because you have to call it by yourself in PlayerSpawn anyway.
So there is nothing wrong with it.
[QUOTE=_Kilburn;20589446]If you're making a gamemode and overwriting PlayerSpawn, then PlayerLoadout has no real reason to exist anymore, because you have to call it by yourself in PlayerSpawn anyway.
So there is nothing wrong with it.[/QUOTE]
If you are making an admin script and decide to change the loadout of admins for a specific gamemode, you would want to hook into PlayerLoadout, give admins a specific weapon and return true to stop the default Loadout from running. If the gamemode doesn't have a PlayerLoadout function (read: doesn't use a PlayerLoadout function) and the loadouts are handled in the playerspawn function, returning true in the PlayerLoadout hook wouldn't prevent the default loadout from running. PlayerLoadout exists to decouple loadout logic from the spawning logic so that it can be overridden separately.
[editline]02:30PM[/editline]
If you override PlayerSpawn then you should either call the BaseClass PlayerSpawn or gamemode.call PlayerLoadout yourself.
[QUOTE=MakeR;20589570]If you are making an admin script and decide to change the loadout of admins for a specific gamemode, you would want to hook into PlayerLoadout, give admins a specific weapon and return true to stop the default Loadout from running. If the gamemode doesn't have a PlayerLoadout function (read: doesn't use a PlayerLoadout function) and the loadouts are handled in the playerspawn function, returning true in the PlayerLoadout hook wouldn't prevent the default loadout from running. PlayerLoadout exists to decouple loadout logic from the spawning logic so that it can be overridden separately.
[editline]02:30PM[/editline]
If you override PlayerSpawn then you should either call the BaseClass PlayerSpawn or gamemode.call PlayerLoadout yourself.[/QUOTE]
What if it's not an admin script, but a gamemode?
I never call BaseClass:PlayerSpawn, because it has a lot of stuff I don't want.
[QUOTE=_Kilburn;20589690]What if it's not an admin script, but a gamemode?
I never call BaseClass:PlayerSpawn, because it has a lot of stuff I don't want.[/QUOTE]
Do you use PlayerLoadout or just put your loadout logic in PlayerSpawn?
[editline]02:37PM[/editline]
[QUOTE=_Kilburn;20589690]What if it's not an admin script, but a gamemode?[/QUOTE]
What do you mean?
I am talking about gamemodes as well. I was just using the admin script as an example of when not using PlayerLoadout will prevent you from doing something.
[QUOTE=MakeR;20589697]Do you use PlayerLoadout or just put your loadout logic in PlayerSpawn?
[editline]02:37PM[/editline]
What do you mean?
I am talking about gamemodes as well. I was just using the admin script as an example of when not using PlayerLoadout will prevent you from doing something.[/QUOTE]
Oh, nevermind, I just misunderstood the admin script part. :downs:
Anyway, I just gamemode.Call PlayerLoadout from PlayerSpawn.
[QUOTE=_Kilburn;20589765]Oh, nevermind, I just misunderstood the admin script part. :downs:[/QUOTE]
Ok.
-snip-
What if I wanted to set the loadouts to set ranks? :o
Sorry, you need to Log In to post a reply to this thread.