First ever attempt at creating something myself.. and it fails without errors.

No errors in server console or player console, it just doesn’t do anything.
I’ve placed it in lua/autorun/server under the name 1glaive1.lua.

You don’t seem to have anything that is calling the function. Use a hook. http://wiki.garrysmod.com/page/GM/PlayerSay

Also a logical error, you do this:



 if string.lower(text) == "!glaive" then


2 lines down you do this:



  if string.lower(text) == "!glaive" then


Basically you assume that once the code has reached your first if-statement, it will pause and wait for player input. It won’t. It will just run past the first if-statement, then it will run past the second statement. You’re not presenting the player with any options, if you do !glaive in chat you will get to this instantly



"You are now signed up for the 1 vs. 1 glaive match! Type !leave to leave."


Also you’re checking for:



if string.lower(text) == "!leave" then


Inside the previous if-statement. Which will never be run, since your first if-clause looks if text == “!glaive” then text can’t be “!leave” within the same block of code.
So what’s happening is this:
ask if passed variable named text equals “!glaive”
true
ask if passed variable named text equals “!glaive”
true
ask if passed variable named text equals “!leave”
false

Try this instead:

Not to mention, this isn’t how you ask for text being entered as a menu. Here’s an example of your code which does “proper” outputs of text to let them know where they are in the menu, and make sure you reset the vars on PlayerDeath.

Basically, you need to think recursively, except the player is manually calling the function each time. What happens each time they call it? Well, you need to track what they’ve typed so far, so there are 2 tracking vars ( you could make it 1 and use ENUMs to track the status; but I made it 2 separate boolean vars )

PlayerSay is a SERVER side hook.

[lua] hook.Add( “PlayerSay”, “SignUpThingyMaBobber”, function( _p, _text, publicprivate )
// Check to see if a string starts with text
if ( string.StartWith( string.lower( _text ), “!glaive” ) ) then
// We need some tracking var…
if ( !_p.__SignUpTypedOnce ) then
_p:ChatPrint( “Are you sure you want to sign up? This will strip all your weapons! Type !glaive again to confirm” );
_p.__SignUpTypedOnce = true;

			return ""; // This makes it so others can't see that the user typed !glaive. Otherwise remove this line if you want them to
		else
			if ( !_p.__SignUpIsInArena ) then
				//
				_p.__SignUpIsInArena = true;

				
				_p:ChatPrint ("You are now signed up for the 1 vs. 1 glaive match! Type !leave to leave.")
				_p:StripWeapons()
				_p:Give( "glv_glaive" )

				// Consider revising hardcoded positions which need to be Vector( )s
				_p:SetPos( Vector( 1944.946777, -2931.876953, 765.031250 ) );

				return "";
			else
				_p:ChatPrint ( "Type !leave to leave." );

				// Glaive does nothing other than output advice, show chat
			end

			// If you don't want it to show, just return ""; here instead of the 2 abov
		end
	end
	
	if ( string.StartWith( string.lower( _text ), "!leave" ) ) then
		if ( !_p.__SignUpIsInArena ) then
			if ( !_p.__SignUpTypedOnce ) then
				_p:ChatPrint ( "Type !glaive twice to join a 1vs 1 glaive match." );
			else
				_p:ChatPrint ( "Type !glaive again to join a 1vs 1 glaive match." );
			end
		else
			_p:KillSilent( );
			_p:ChatPrint ( "You have left the glaive match." );

			// Reset the vars so they can do it again. Make sure you do this on death too...
			_p.__SignUpIsInArena = false;
			_p.__SignUpTypedOnce = false;
		end

		return "";
	end
end );[/lua]

Thank you very much!

[editline]17th September 2013[/editline]

How do I detect when a player tries to drop the weapon? I want to restrict the glaive from being dropped if in the match.

Modifying the SWEP will prevent it from being holstered by adding this code:

[lua]function SWEP:Holster( )
return false;
end[/lua]

You may want to modify your drop code to check whether or not they can holster before allowing them to drop it and that’s it!

This is what I do in mine, comments added for you.
[lua] // Weapon is valid
if ( IsValid( _w ) ) then
// Holster function exists AND they are NOT allowed to holster their weapon then stop…
if ( _w.Holster && !_w:Holster( ) ) then return; end

	// Otherwise, allow the player to drop the weapon!
	Player:DropWeapon( _w )
end

[/lua]

why do you have semicolons, they aren’t necessary for lua

Do they matter then?

no, it bothers the shit out of me when I see them though

The gamemode ain’t mine, and if I edit the drop function/code it may break everything…

Nothing wrong with using them though. Especially if you want to clearly separate statements.

I use them because I code in C++, Java and other languages. I’ve written a game-engine, AI and other things in languages other than Lua. Logic is universal. I can copy/paste things that I write from one language to the other much easier with the semi-colons present. Get used to it or don’t reply because you added absolutely no content to this thread by doing so.

Thanks for the box Johnny…

I use them when a language requires them but I don’t understand why you use them in lua when its just unnecessary. But maybe it’s just a pet peeve of mine.

Bumpin. Need help on restricting weapons from dropping untill the player types !leave.

set a player variable somewhat like ply:PlayerInGlaive or ConVar with 1 or 0 value.

then under PreDrop and Holster:

[lua] if ply:IsInGlaive == 1 then return false
else return true [/lua]

Quite a lua noob, but this should work

Not sure what’s “PreDrop” or “Holster” is honestly.

SWEP:PreDrop()