Jump to content

Will this LUA work? (Novice needs help :P)


Chuckun

Recommended Posts

I know that typing [g] shows your silEnT GUID and typing it into fireteam chat whilst not in a fireteam will work to do it privately, but for absolute security, I wanted to make a custom command of !myguid so I made this LUA script.. Problem is I have never ever touched anything LUA or ET related, so I have no idea if this will even work and I have no means of testing it.. So I wonder if someone can tell me if I've done anything wrong, and/or if it will actually work?

----------------------------------------------------------------------
-- Filename: myguid.lua
----------------------------------------------------------------------
-- MyGUID - Prints your silEnT GUID just like /cl_guid would for etkey based GUIDs.
----------------------------------------------------------------------
-- Created by =F|A=Chuckun
-- If you use it, please donate to our clan to help fund the servers
-- Any amount will help!!
-- Fearless-Assassins.com
----------------------------------------------------------------------
-- For use with shrubbot, exec 'getmyguid'
----------------------------------------------------------------------

description = "silEnT GUID Command"
version = "1.0"   


function et_InitGame(levelTime,randomSeed,restart)
    local modname = string.format("%s", description)
    et.G_Print(string.format("%s loaded\n", modname))
    et.RegisterModname(modname)
end



function et_ConsoleCommand(command)
    if et.trap_Argv(0) == "getmyguid" then
        local userinfo = et.trap_GetUserinfo( playerID )
        local guid     = et.Info_ValueForKey( userinfo, "sil_guid" )
        et.trap_SendServerCommand(clientNum, "print \"^osilEnT GUID: ^7"..guid.."\n")
    end
    return 1
end

Or perhaps there's an easier way to simply print the GUID within the command's exec line, with no need for any LUA mod?

Edited by Chuckun
Link to comment
Share on other sites

----------------------------------------------------------------------
-- Filename: myguid.lua
----------------------------------------------------------------------
-- MyGUID - Prints your silEnT GUID just like /cl_guid would for etkey based GUIDs.
----------------------------------------------------------------------
-- Created by =F|A=Chuckun
-- If you use it, please donate to our clan to help fund the servers
-- Any amount will help!!
-- Fearless-Assassins.com
----------------------------------------------------------------------
-- For use with shrubbot, exec 'getmyguid'
----------------------------------------------------------------------

description = "silEnT GUID Command"
version = "1.0"   -- is not used in any function


function et_InitGame(levelTime,randomSeed,restart)
    local modname = string.format("%s", description)
    et.G_Print(string.format("%s loaded\n", modname))
    et.RegisterModname(modname)
end



function et_ConsoleCommand(clientNum, command)
    if et.trap_Argv(0) == "getmyguid" then

           local guid = et.Info_ValueForKey(et.trap_GetUserinfo(playerID),"sil_guid")

           et.trap_SendServerCommand(clientNum, "print \"^osilEnT GUID: ^7"..guid.."\n")

    return 1  ---return 1 here...if  not have getmyguid comand will be 0..unreconize comand 

   end

end

 

 

im begginer too...usualy i hunt logs for errors ....but i thik like this will work :) 

gaoesa solution is better :) no lua

Edited by loudness
Link to comment
Share on other sites

Thank you gaoesa and loudness! :)

 

Although I like the simplicity of the PM idea, it's a bit sloppy for my taste (i'm just quite particular I guess), but I appreciate it's functionality..

 

If anyone has a test server they could test the LUA on that would be handy :) (Moving the positive return into the scope of the IF clause as pointed out by loudness).. If not it will have to wait until I have time to do my first server setup :P

Edited by Chuckun
Link to comment
Share on other sites

No it wont work because of:

function et_ConsoleCommand(clientNum, command)

--Called when a command is entered on the server console should be et_ClientCommand( clientNum, command ) -> Called when a command is received from a client

 
    if et.trap_Argv(0) == "getmyguid" then

           local guid = et.Info_ValueForKey(et.trap_GetUserinfo(playerID),"sil_guid")

--playerID is nil -> not defined

 

           et.trap_SendServerCommand(clientNum, "print \"^osilEnT GUID: ^7"..guid.."\n")
--clientNum is nil (see above)

    return 1  ---return 1 here...if  not have getmyguid comand will be 0..unreconize comand 

   end

end

 

 

 

fixed lua and I added !help myguid. You could also add a check level to just give it to some admins.

 

----------------------------------------------------------------------
-- Filename: myguid.lua
----------------------------------------------------------------------
-- MyGUID - Prints your silEnT GUID just like /cl_guid would for etkey based GUIDs.
----------------------------------------------------------------------
-- Created by =F|A=Chuckun
-- If you use it, please donate to our clan to help fund the servers
-- Any amount will help!!
-- Fearless-Assassins.com
----------------------------------------------------------------------
-- !myguid or /!myguid
----------------------------------------------------------------------

------------------------------------------ name ----------------------------------------------

Modname = "silEnT GUID Command"
Version = "1.0"

------------------------------------------ settings ----------------------------------------------

commandprefix              = "!"                --command prefix (! shrubbot like)
myguid_cmd               = "myguid"            --shrubbot command (can be shortened to example "myg"
                                            --just like !listplayers -> !list !listp !listplay
printposition              = "chat"            --message position

----------------------------------------- functions ---------------------------------------------

function et_InitGame(levelTime,randomSeed,restart)
   et.G_Print("["..Modname.."] Version: "..Version.." Loaded\n")
   et.RegisterModname(Modname.." "..Version.. " "..et.FindSelf())
end

---------------------------------- client command functions ------------------------------

function et_ClientCommand(client, command)
    local argv0 = string.lower(et.trap_Argv(0))    --first argv if you use / will be myguid_cmd
    local argv1 = string.lower(et.trap_Argv(1))    --et.trap_Argv(0) is say/say_buddy/say_team and et.trap_Argv(1) is myguid_cmd
    local argv2 = string.lower(et.trap_Argv(2))
                --string.lower so you ca write it in upper and/or lower letters
    -------//--------------------Command----------------------------
    if string.find(argv0, "^"..commandprefix.."" .. myguid_cmd .. "") or string.find(argv1, "^"..commandprefix.."" .. myguid_cmd .. "") then --use string.find so it's not needed to write full command.
        local userinfo = et.trap_GetUserinfo( client )
        local guid     = string.upper(et.Info_ValueForKey( userinfo, "sil_guid" ))
        if guid == nil or guid == "" then guid = "UNKNOWN" end    --in case client doesn't have no guid set it to UNKNOWN
        et.trap_SendServerCommand(client, ""..printposition.." \"^osilEnT GUID: ^7"..guid.."\"")
        if string.find(argv0, "^"..commandprefix.."" .. myguid_cmd .. "") then
            return 1    --return 1 so no error message will be printed^if /command is used
        end
    end
    if argv1 == ""..commandprefix.."help" and string.find(argv2, "^" .. myguid_cmd .. "") then -- !help myguid
        et.trap_SendServerCommand(client, ""..printposition.." \"^oFunction: ^7print your ^osilEnT GUID\"" )
    end
    
    return 0
end
Link to comment
Share on other sites

@Micha! - thanks for your help :) The LUA was actually to catch the server executed command via shrubbot (so user types !myguid, shrubbot catches it and execs the function defined in the LUA script - the script itsself was not supposed to catch "!myguid" as shrubbot will do that for you and exec the 'getmyguid' function :)

 

However, I've taken on board the other points you mentioned, and should be able to successfully finish the mod :)

Thank you!

Edited by Chuckun
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...