Garry's Mod

Garry's Mod

View Stats:
LazyTavi Aug 4, 2015 @ 9:41pm
Confusion with LUA | How do I use "ply' correctly?
I've been seeing "ply" all over the Garry's Mod wiki, and I don't know what it is or how to use it. I don't recall specifically seeing it in the Developer Tutorials, but from the looks of it, it appears to be a variable of some sort, and quite a common one too.

However, whenever I try to put "ply" in a code, Garry's Mod either

1.) pretends the whole local text box doesn't exist or
2.) calls "ply" null.
It's most likely possible I'm using the code wrong, due to my lack of understanding of what it really is.

This is the code I'm trying to use it in. This won't quite cover all of the problems I'm having, since I keep experimenting with codes until it works, which usually lead to problems 1 and 2. This example is only to show what I'm doing and what is wrong.

Example based off of an excerpt from the Garry's Mod wiki[wiki.garrysmod.com]

function CLASS:OnSpawn( pl ) local colorClear = Color( 225, 225, 225, 60 ) for key, ply in pairs( team.GetPlayers ( 1 ) ) do ply:SetColor( colorClear ) -- Sets the players color to translucent ply:SetRenderMode( RENDERMODE_TRANSALPHA ) end

[An attempt to make all players in a class appear translucent. There is only one class on the team.]

Hopefully, based off of what I have, someone can help point me in the right direction.
Thank you in advance
Last edited by LazyTavi; Aug 5, 2015 @ 8:54am
< >
Showing 1-3 of 3 comments
LazyTavi Aug 5, 2015 @ 8:58am 
1. Thanks, I had no idea that I could do that.
2. No errors are reported in the console, but it looks like every code the whole lua is overlooked, inlcuding a code much further up the list that sets the class's playermodel. When the provided code is deleted, however, the playermodel changes to what it's set to. This makes me believe that the problem is in the provided code.

[EDIT] After scrolling up a little, this was found shortly after the server loaded.

[ERROR] gamemodes/game/gamemode/player_class/player.lua:57: 'end' expected (to close 'function' at line 27) near '<eof>' 1. unknown - gamemodes/game/gamemode/player_class/player.lua:0

But the thing is, there already is an "end" for line 27 (the first line of the provided code) Do you know the reason why it can't be found?
Last edited by LazyTavi; Aug 5, 2015 @ 11:07am
LazyTavi Aug 5, 2015 @ 11:59am 
Originally posted by Byte:
Also, why does your CLASS:OnSpawn meta function take a pl parameter? That seems like it would be run on every player spawn then, no?

In all honesty, in the case of the pl, I really have no idea what I'm doing. I was following a tutorial here[maurits.tv]. I suppose I should take a better look at how functions work then. "Ply" is what I really have no clue of what it is, since I've never seen an explanation for it. If it's simply an example variable, then that might answer my question. It'd just be nice if the wiki would've made that more clear.
LazyTavi Aug 5, 2015 @ 12:14pm 
Originally posted by Byte:


You should probably get yourself a better grip on Lua before jumping into huge projects like making an entire Fretta gamemode, honestly.
pl, ply, etc are just variables. They can be called anything, but their value is the same assuming they're set the same.

If you need some basic resources to get started with basic Lua scripting, I wrote a nice little repository of stuff here.

Well, thanks for the helpful advice. I'm dissapointed that I couldn't figure it out. It seemed easy at first, considering my insufficient prior knowledge in scripting, but I guess there's still much to learn. I'll do some reading and get back to work once I know more about what I'm doing.

Thanks again for your help.
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Aug 4, 2015 @ 9:41pm
Posts: 3