LUA issues


function JoinCommand( pl, text, teamonly )
		    if (text == "!join") then 
			print ("WOOOOOOOOO") 
			ply:PS_GivePoints(5000)
			    
			    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has joined our Steam group via !join." )

		end
		
	end
end
hook.Add( "PlayerSay", "Chat", JoinCommand )

What I want/believe should be happening:
Player types “!join” --> console prints “WOOOOOOOO” --> Pointshop gives the ply who wrote “!join” 5000 points --> opens webpage --> end

Whats up!?

Edit= the command console’s response is:


WOOOOOOOOO

[ERROR] addons/join command/lua/autorun/jc.lua:23: attempt to index global 'ply' (a nil value)
  1. v - addons/join command/lua/autorun/jc.lua:23
   2. unknown - lua/includes/modules/hook.lua:84

Sulli: !join


This leads me to believe I need some kind of ‘self’ trigger infront of PS_GivePoints

You need to use pl, not ply.

You use variable “ply” whereas the argument name in your function is “pl”.

Also, opening that page won’t automatically make the player join the group.

That’s ok. I never intended to force the player to join it, only make it more accessible to do so (e.g. open the page for them!)

EDIT: could you give me a script example where ply and pl are in use, please?

  • a link to the gmod wiki page where this type of difference is explained? I see a lot of ply: and player: and pl: but never a guide as to when I should use them!

You use “pl”, “ply”, “player” based on the argument name on the function you’re using. So if you had a function like this:
[lua]
function example1(ply)
end
[/lua]
You would use ply instead of pl or player

AFTER FIDDDLING-- still doesn’t work though EDIT: IT WORKED!!!


function JoinCommand( pl, text, teamonly )
		    if (text == "!join") and pl:IsUserGroup("patriot") then 
			print ("WOOOOOOOOO") 
			pl:PS_GivePoints(5000)
			--pl:Setusergroup "operator"
			pl:SetUserGroup( "operator" )
			pl:PS_GiveItem('conehat')
			    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has joined our Steam group via !join." )

		end
		
	end
end
hook.Add( "PlayerSay", "Chat", JoinCommand )

What I want/believe should be happening:
Player types “!join” and is only an “admin” --> console prints “WOOOOOOOO” --> Pointshop gives the ply who wrote “!join” 5000 points --> set the user to operator–> opens webpage --> end

I can’t find a command on google which changes the user group. Ulx is the only one I could think of as that’s what I use in my dedicated’s RECON line

[editline]27th June 2014[/editline]

I’m going to have a fun weekend doing LUA tutorials :stuck_out_tongue:

By the way, thanks guys!