• SWEP.base explanation
    6 replies, posted
I have no idea where to start with a base for a swep. I don't know what goes in it. I have looked at some, but they are really confusing. Can someone explain what would go in a SWEP.base for me?
Think of a base as a init.lua for a gamemode... you can make other scripts include them (weapons in this case) and use their functions, and these files may even be included in another file (sub-base). All a base is is pretty much a file that you would want to derive from so that you dont have to write each function over and over in each SWEP. Thats all a base is: something to derive from so that way you can save space. Bases arent even necessary... you would just have the same functions over and over in each weapon file, resulting in each of your weapons being about 25 kilobytes. The functions are simple and are the same as any SWEP, because again... all a base is for is to be "included" in the non-based swep so that way it may use its functions. SWEP.Deploy SWEP.Holster SWEP.Initialize SWEP.Think SWEP.PrimaryFire SWEP.SecondaryFire ... pretty much all of these, which can be used in any SWEP: [URL]http://wiki.garrysmod.com/?title=Weapon_Hooks[/URL]
Ok. Now, in the base if I have the v_model and the w_model set, would I be able to change that in the SWEP?
Of course. anything you set in a base would be a default value... so its value would retain if you did not specify in the new weapon. In each weapon, if you put... say SWEP.Power = 50, and there was already a SWEP.Power = 20 on the BASE, then the Weapon would overwrite the bases default value of 20 and make it 50. Pretty much the weapon is called AFTER the base is loaded... so its like doing this: [code] SWEP.Power = 20 SWEP.Power = 50 [/code]Not sure if that probbably just made you more confused, but dont worry about it. Conflicting values in the weapon will always over-write the bases values.
No, I understand it completely now. But I see some bases with cl_init and init, what would go in these?
Again... try not to think of a base as a seperate entity think of it as an Include! they are all part of normal weapons. You would put all serverside stuff that you would like to include in other weapons in init.lua, you would want to put shared things in shared.lua that would be needed for other weapons, and clientside stuff in cl_init.lua. if you put a file called cl_init.lua in the base, and you added a file called "Weapon.lua" that included cl_init.lua, then that would be the weapon. So say you made a custom HUD that you wanted to show when you had a weapon out that derived from your base. every weapon that derived from that base would be able to run functions inside yourbase/cl_init.lua as well as yourweapon/cl_init.lua. You would put your custom hud there. And if you wanted to make changes/change variables to affect that HUD in the BASE cl_init.lua you would simply put SWEP.SomeVariable = 110. You could even get more complicated than that!!! Say some weapon you made has a scope that has NIGHTVISION! Ooooooooo! But you want it also to have your custom HUD. The cl_init.lua on the BASE would already give us the function we want for the HUD, so we dont have to copy/paste it into our WEAPONs cl_init.lua, but we would have to create a new function on the WEAPON to handle the nightvision since the BASE does not have it. Are you starting to see how the base is just a big file to be used as a function library? All it is meant for is to be derived from so that way you can use the bases functions. Same thing applies for any file you have in the base. If it is available to the base, it is available to the weapon that derives from that base. Just clarifying... say I had UB3RA1MB0T.lua in the base to give an aimbot when using the weapon. It is not part of the normal file structure, but is included in the cl_init.lua of the base, so the base loads it into memory. Now if we get a weapon that we derive from that base, then whenever you use the weapon you will have the aimbot in UB3RA1MBOT.lua since it was included in the base. Anything else you need to know?
Nope. I understand now, thanks.
Sorry, you need to Log In to post a reply to this thread.