Will this work?

Ok, I keep trying to get things to work and they don’t. So if I put this code in here will it work? garrysmod/addons/addonname/lua/autorun/server/init.lua and then make a blank cl_init.lua and a blank shared.lua?

[lua] AddCSLuaFile(“shared.lua”)

function onspawngive( ply )

hook.Add(“PlayerSpawn”, “hookname”, onspawngive) [/lua]

I just want it to give players a crowbar when they spawn. If it won’t work why not? Thanks

What the fuck
why do you need blank shared and cl_init files :confused:

Go to gamemodes/gamemode_you’re_using/init.lua

Find the GM:PlayerLoadout function and add the crowbar.
Or in autorun/server/crowbar.lua :

function crowbar(pl)

hook.Add( “PlayerLoadout”, “crowbar”, crowbar) [/lua]

Thankyou very much :smiley:
I thought that you needed the cl_init and the shared.lua for it to work lol

No, in fact I’d recommend against putting something as generic as “init.lua” as the filename. GMod will run all the Lua files in autorun/server (only on the server), autorun (runs on both), and autorun/client (only on the client), so you can have any filename you like, and if you choose a really generic name there’s a good chance it’ll conflict with another addon and one will override the other.

“hookname” is also a very generic name for the hook, don’t forget that has to be unique as well. There’s a pretty small chance someone will add a PlayerSpawn hook with exactly the same name, but just to be sure call the hook “CrowbarSpawnGive” or something.

To be honest the only thing in your script that definitely would break it is that the function doesn’t have an end to close its definition, and it would probably work absolutely fine if you added it now. But it’s always good to make sure an addon you make is compatible with others and there are no conflicts.