User Input System * GUI drawText

Share your gamemodes and snippets here
Post Reply
icuruok
Posts: 3
Joined: Fri Aug 16, 2019 3:47 pm

User Input System * GUI drawText

Post by icuruok » Sat Aug 17, 2019 6:25 pm

This is a UI based user input system I created for a upcoming gamemode I plan to release.

With this UI user input system you can have your IV:MP server request user text input to collect and store.

The text request is made on screen from drawTexthttps://bitbucket.org/Suge/eflc-mp-lua/wiki/drawText/

The user can enter any A-Z : 1-9 keys they wish and server can collect it, The text is also displayed live to the user as they type.



How To :

To call and use the user input is simple, Once userInput filterscript is loaded simply call with

gkeyboard(playerid, true) -- enable keyboard hook and request user input

You can disable by calling gkeyboard(playerid, false) -- by default is removed once user hits enter

to call/store/get the data the user entered
userInputdata[playerid] -- this is the string the user entered on input request


userInput.lua

Code: Select all

userInputdata = { } -- global table for each users input data 
userInputstream = { } -- global table of live input text from hook


function gkeyboard(pid, ctype)
   if(ctype == true) then
      wipeDrawClass(pid, 6) -- remove chat display
      drawText(pid, 6, 0.4, 0.5, 0.2, 0.54, "Enter Text - Enter to send", 0, 0xFFFFFFFF)
      userInputstream[pid] = ""
   end
   setPlayerFrozen(pid, ctype) -- freezes or unfreezes player for input
   setPlayerKeyHook(pid, 0x30, ctype) -- 0 key
   setPlayerKeyHook(pid, 0x31, ctype) -- 1 key	
   setPlayerKeyHook(pid, 0x32, ctype) -- 2 key
   setPlayerKeyHook(pid, 0x33, ctype) -- 3 key	
   setPlayerKeyHook(pid, 0x34, ctype) -- 4 key
   setPlayerKeyHook(pid, 0x35, ctype) -- 5 key
   setPlayerKeyHook(pid, 0x36, ctype) -- 6 key
   setPlayerKeyHook(pid, 0x37, ctype) -- 7 key	
   setPlayerKeyHook(pid, 0x38, ctype) -- 8 key
   setPlayerKeyHook(pid, 0x39, ctype) -- 7 key	

   setPlayerKeyHook(pid, 0x0D, ctype) -- enter key
   setPlayerKeyHook(pid, 0x20, ctype) -- space key	
   setPlayerKeyHook(pid, 0x08, ctype) -- backspace key	

   setPlayerKeyHook(pid, 0x41, ctype) -- A key	
   setPlayerKeyHook(pid, 0x42, ctype) -- B key	
   setPlayerKeyHook(pid, 0x43, ctype) -- C key	
   setPlayerKeyHook(pid, 0x44, ctype) -- D key	
   setPlayerKeyHook(pid, 0x45, ctype) -- E key	
   setPlayerKeyHook(pid, 0x46, ctype) -- F key	
   setPlayerKeyHook(pid, 0x47, ctype) -- G key	
   setPlayerKeyHook(pid, 0x48, ctype) -- H key	
   setPlayerKeyHook(pid, 0x49, ctype) -- I key	
   setPlayerKeyHook(pid, 0x4A, ctype) -- J key	
   setPlayerKeyHook(pid, 0x4B, ctype) -- K key	
   setPlayerKeyHook(pid, 0x4C, ctype) -- L key	
   setPlayerKeyHook(pid, 0x4D, ctype) -- M key	
   setPlayerKeyHook(pid, 0x4E, ctype) -- N key	
   setPlayerKeyHook(pid, 0x4F, ctype) -- O key	
   setPlayerKeyHook(pid, 0x50, ctype) -- P key	
   setPlayerKeyHook(pid, 0x51, ctype) -- Q key	
   setPlayerKeyHook(pid, 0x52, ctype) -- R key	
   setPlayerKeyHook(pid, 0x53, ctype) -- S key	
   setPlayerKeyHook(pid, 0x54, ctype) -- T key	
   setPlayerKeyHook(pid, 0x55, ctype) -- U key	
   setPlayerKeyHook(pid, 0x56, ctype) -- V key	
   setPlayerKeyHook(pid, 0x57, ctype) -- W key	
   setPlayerKeyHook(pid, 0x58, ctype) -- X key	
   setPlayerKeyHook(pid, 0x59, ctype) -- Y key	
   setPlayerKeyHook(pid, 0x5A, ctype) -- Z key	
end



function ts_keyEvent(playerid, keyCode, isUp)

    if(keyCode == 0x30) then --0 key
            userInputstream[playerid] = userInputstream[playerid] .. "0"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x31) then --1 key
            userInputstream[playerid] = userInputstream[playerid] .. "1"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x32) then --2 key
            userInputstream[playerid] = userInputstream[playerid] .. "2"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x33) then --3 key
            userInputstream[playerid] = userInputstream[playerid] .. "3"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x34) then --4 key
            userInputstream[playerid] = userInputstream[playerid] .. "4"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x35) then --5 key
            userInputstream[playerid] = userInputstream[playerid] .. "5"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x36) then --6 key
            userInputstream[playerid] = userInputstream[playerid] .. "6"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x37) then --7 key
            userInputstream[playerid] = userInputstream[playerid] .. "7"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x38) then --8 key
            userInputstream[playerid] = userInputstream[playerid] .. "8"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x39) then --9 key
            userInputstream[playerid] = userInputstream[playerid] .. "9"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end



    if(keyCode == 0x20) then --spacebar key
            userInputstream[playerid] = userInputstream[playerid] .. " "
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end

    if(keyCode == 0x08) then --backspace key
            userInputstream[playerid] = userInputstream[playerid]:sub(1, -2)
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end

    if(keyCode == 0x0D) then --enter key
            wipeDrawClass(playerid, 6) -- remove chat display
            gkeyboard(playerid, false) -- disable keyboard hook and dont capture keys
            userInputdata[playerid] = userInputstream[playerid] -- set data got from keyboard hook to users data table
            sendPlayerMsg(playerid, "you entered :" .. userInputdata[playerid], 0xFF0000FF)
    end


    if(keyCode == 0x41) then --A key
            userInputstream[playerid] = userInputstream[playerid] .. "a"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x42) then --B key
            userInputstream[playerid] = userInputstream[playerid] .. "b"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x43) then --C key
            userInputstream[playerid] = userInputstream[playerid] .. "c"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x44) then --D key
            userInputstream[playerid] = userInputstream[playerid] .. "d"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x45) then --E key
            userInputstream[playerid] = userInputstream[playerid] .. "e"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x46) then --F key
            userInputstream[playerid] = userInputstream[playerid] .. "f"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x47) then --G key
            userInputstream[playerid] = userInputstream[playerid] .. "g"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x48) then --H key
            userInputstream[playerid] = userInputstream[playerid] .. "h"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x49) then --I key
            userInputstream[playerid] = userInputstream[playerid] .. "i"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x4A) then --J key
            userInputstream[playerid] = userInputstream[playerid] .. "j"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x4B) then --K key
            userInputstream[playerid] = userInputstream[playerid] .. "k"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x4C) then --L key
            userInputstream[playerid] = userInputstream[playerid] .. "l"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x4D) then --M key
            userInputstream[playerid] = userInputstream[playerid] .. "m"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x4E) then --N key
            userInputstream[playerid] = userInputstream[playerid] .. "n"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x4F) then --O key
            userInputstream[playerid] = userInputstream[playerid] .. "o"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x50) then --P key
            userInputstream[playerid] = userInputstream[playerid] .. "p"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x51) then --Q key
            userInputstream[playerid] = userInputstream[playerid] .. "q"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x52) then --R key
            userInputstream[playerid] = userInputstream[playerid] .. "r"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x53) then --S key
            userInputstream[playerid] = userInputstream[playerid] .. "s"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x54) then --T key
            userInputstream[playerid] = userInputstream[playerid] .. "t"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x55) then --U key
            userInputstream[playerid] = userInputstream[playerid] .. "u"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x56) then --V key
            userInputstream[playerid] = userInputstream[playerid] .. "v"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x57) then --W key
            userInputstream[playerid] = userInputstream[playerid] .. "w"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x58) then --X key
            userInputstream[playerid] = userInputstream[playerid] .. "x"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x59) then --Y key
            userInputstream[playerid] = userInputstream[playerid] .. "y"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
    if(keyCode == 0x5A) then --Z key
            userInputstream[playerid] = userInputstream[playerid] .. "z"
            wipeDrawClass(playerid, 6) -- remove chat display
            drawText(playerid, 6, 0.4, 0.5, 0.2, 0.54, userInputstream[playerid], 0, 0xFFFFFFFF)
    end
end
registerEvent("ts_keyEvent", "onPlayerKeyPress")


#Dav
Posts: 3
Joined: Sun Jun 02, 2019 2:42 am
Location: Greece

Re: User Input System * GUI drawText

Post by #Dav » Sun Sep 01, 2019 9:14 am

Hey, you doing well man, thanks for releasing your work.
"Many humans do not care about what is "unfair,"
for it varies so much between them."

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest