+ Reply to Thread
Results 1 to 9 of 9

Thread: E2 custom extension help

  1. #1
    Wire Noob phreak314's Avatar
    Join Date
    Feb 2009
    Location
    US
    Posts
    25

    Default E2 custom extension help

    Hey lua experts!

    I'm trying to develop a custom extension for E2 which detects key presses on clients. The overall objective is to be able to tell when a client presses any key on their keyboard. Below i've included some code which I cannot get to work. When executing printingTest() in an expression with an interval of 1, "0" is printed to the console over and over again, no matter if i press "w" or not.

    Code:
    local I = 0
    
    if (CLIENT) then
    	hook.Add("Think", "e2thinker", function()
    		if(input.IsKeyDown(33)) then
    			I = I + 1
    		end
    	end)
    
    elseif (SERVER) then
    	registerFunction("printingTest", "", "", function(self)
    		print(I)
    	end)
    
    end
    The client side code appears to be the problem. I know the code should work because i've tested it through the ingame console using the following command:

    Code:
    lua_run_cl hook.Add("Think", "e2thinker", function() if(input.IsKeyDown(33)) then print("pressing w") end  end)
    It works great, but practically the same code in a lua file in the e2 custom directory doesn't work. Any ideas?

  2. #2
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: E2 custom extension help

    Variables on the client are not the same as variables on the server. (Edit: by this I mean if you set a variable on the client to something, the one on the server with the same name won't change)

    You need to use usermessage or something
    Last edited by Divran; 01-29-2010 at 01:53 AM.
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  3. #3
    Wirererer hzzzln's Avatar
    Join Date
    Dec 2008
    Location
    :noitacoL
    Posts
    151

    Default Re: E2 custom extension help

    iirc, there already is such an addon. if you just code it again for fun, i can't help since my lua skills are very... basic.
    DO YOU HEAR THE VOICES TOO?

  4. #4
    Wire Noob phreak314's Avatar
    Join Date
    Feb 2009
    Location
    US
    Posts
    25

    Default Re: E2 custom extension help

    Thanks for the response.

    I am aware of the already existing Input Support extension. Unfortunately the client side of Input Support does not work and no one is helping on the Input Support forum. I decided to try identifying the cause of the problem myself but have come to find there must be something that changed to break the client-side functionality.

  5. #5
    Wire Noob phreak314's Avatar
    Join Date
    Feb 2009
    Location
    US
    Posts
    25

    Default Re: E2 custom extension help

    Quote Originally Posted by Divran View Post
    Variables on the client are not the same as variables on the server. (Edit: by this I mean if you set a variable on the client to something, the one on the server with the same name won't change)

    You need to use usermessage or something
    I didn't know that, thanks for the info.

    I did try to use usermessage, but that didn't work either. I will have to wait till I get home to provide examples, but the client usermessage hook does not catch the messages i send. I get an error in the console saying something about an unhanded message. I'll post later with more details. I think this is why Input Support no longer works, it uses usermessage.

  6. #6
    Wire Noob phreak314's Avatar
    Join Date
    Feb 2009
    Location
    US
    Posts
    25

    Default Re: E2 custom extension help

    So here is an example using usermessage, and sendusermessage. They both do the same thing according to the wiki so i figured i would try both. Neither reach the client.

    Code:
    if (CLIENT) then
    	usermessage.Hook("runMe", function()
    		Msg("Client received message")
    		RunConsoleCommand("e2keystate")
    	end)
    
    elseif (SERVER) then
    	concommand.Add( "e2keystate", function( player, command )
    		print("I got here")
    	end)
    
    	local RP = RecipientFilter()
    	RP:AddAllPlayers()
    
    	registerFunction("queryClient", "", "", function()
    		umsg.Start("runMe", RP)
    		umsg.End()
    //		SendUserMessage("runMe")
    	end)
    
    end
    If you run "queryClient()" with an interval in e2, you will see the following over and over in the console:
    Code:
    Warning: Unhandled usermessage 'runMe'

  7. #7
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: E2 custom extension help

    I think the client side functions need to be in a file prefixed by "cl_" in the custom folder in E2. Not sure though.
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  8. #8
    Wire Noob phreak314's Avatar
    Join Date
    Feb 2009
    Location
    US
    Posts
    25

    Default Re: E2 custom extension help

    Quote Originally Posted by Divran View Post
    I think the client side functions need to be in a file prefixed by "cl_" in the custom folder in E2. Not sure though.
    I've not done much with splitting the files like this but heres what I did...

    I created fullKeyboard.lua containing the following:

    Code:
    concommand.Add( "e2keystate", function( player, command )
    	print("I got here")
    
    end)
    
    local RP = RecipientFilter()
    RP:AddAllPlayers()
    
    registerFunction("queryClient", "", "", function()
    	umsg.Start("runMe", RP)
    	umsg.End()
    //	SendUserMessage("runMe")
    end)
    And another file call cl_fullKeyboard.lua:

    Code:
    usermessage.Hook("runMe", function()
    	Msg("Client received message")
    
    	RunConsoleCommand("e2keystate")
    
    end)
    The result, nothing happens at all when firing an expression with "queryClient()" in it. I see no messages on the client or server now. I must have done something wrong...

  9. #9
    Wire Noob phreak314's Avatar
    Join Date
    Feb 2009
    Location
    US
    Posts
    25

    Default Re: E2 custom extension help

    So no one has any idea why this doesn't work? The example I included where the clientside and serverside were both in the same file used to work. I used input support version 1.1 about a year ago. I took a break and when i came back input support was broken. Version 1.2 works mostly the same. If it's a usermessage specific issue, it must be with e2 extensions only.


    Edit: Think i just figured out whats wrong. Splitting the files into client/server is necessary along with sending the client file to the client with AddCSLuaFile. After doing this, client side stuff started working. Something must have changed to cause this cuz it wasn't always necessary to split the files like this.
    Last edited by phreak314; 01-30-2010 at 08:35 PM.

+ Reply to Thread

Similar Threads

  1. E2 extension
    By GmodSector in forum Ideas & Suggestions
    Replies: 5
    Last Post: 08-09-2009, 04:57 PM
  2. E2 signal-extension help
    By Drunkie in forum Expression 2 Discussion & Help
    Replies: 0
    Last Post: 04-09-2009, 11:14 AM
  3. New E2 signal-extension
    By Drunkie in forum Installation and Malfunctions Support
    Replies: 0
    Last Post: 04-08-2009, 10:48 PM
  4. E2 HUD drawing extension
    By Beer in forum Ideas & Suggestions
    Replies: 3
    Last Post: 03-30-2009, 07:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots