• String Help
    5 replies, posted
Is there a way to change a string to a plain variable. Example Change "NOTIFY_CLEANUP" to NOTIFY_CLEANUP I need this because i am making a ULX command that has a table of different notification Enums and i would like for it to allow you to select a type and use it. local notifytypes = {"NOTIFY_GENERIC", "NOTIFY_ERROR", "NOTIFY_UNDO", "NOTIFY_HINT", "NOTIFY_CLEANUP"} function ulx.notifyp( calling_ply, target_plys, minutes, typeof, message ) local seconds = minutes*60 for k,v in pairs( target_plys ) do v:SendLua("GAMEMODE:AddNotify(\"" .. tostring(message) .. "\", NOTIFY_ERROR, " .. tostring(seconds) .. ")") v:EmitSound( "buttons/button15.wav" ) end end local notifyp = ulx.command( CATEGORY_NAME, "ulx notifyp", ulx.notifyp, "!notifyp", true ) notifyp:addParam{ type=ULib.cmds.PlayersArg } notifyp:addParam{ type=ULib.cmds.NumArg, min=1, max=10, default=5, hint="minutes", ULib.cmds.optional, ULib.cmds.round } notifyp:addParam{ type=ULib.cmds.StringArg, completes=notifytypes, hint="Type of Alert", error="invalid type \"%s\" specified", ULib.cmds.restrictToCompletes, default="user", ULib.cmds.optional } notifyp:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine } notifyp:defaultAccess( ULib.ACCESS_SUPERADMIN ) notifyp:help( "Send a notification message to target." ) this is my ulx command if anyone wants to fix it to the actual command itself :P
You could just map the types in the table. Ex. local notifytypes = {NOTIFY_GENERIC = NOTIFY_GENERIC, NOTIFY_ERROR = NOTIFY_ERROR, etc}
I changed my code up a bit because i would like it to look clean with my hud. This is what i have set up. Do you know why i am getting that "notify is set to nil" errors in console? local notifytypes = {"Blue", "Red", "Green", "Light Blue", "Orange"} function ulx.notifyp( calling_ply, target_plys, minutes, notifytypestho, message ). local seconds = minutes*60 for k,v in pairs(notifytypes) do if v == "Blue" then  local notify = NOTIFY_GENERIC; elseif v == "Red" then  local notify = NOTIFY_ERROR; elseif v == "Green" then  local notify = NOTIFY_UNDO; elseif v == "Light Blue" then  local notify = NOTIFY_HINT; elseif v == "Orange" then  local notify = NOTIFY_CLEANUP; end end for k,v in pairs( target_plys ) do v:SendLua("GAMEMODE:AddNotify(\"" .. tostring(message) .. "\"," .. notify .. ", " .. tostring(seconds).. ")") v:EmitSound( "buttons/button15.wav" ) end end
You are defining notify as a local variable inside the if-statement - it will not be available outside of that scope. Really, there's no need to do the loop or if-statements, just do this: local notifytypes = { ["blue"] = NOTIFY_GENERIC, ["red"] = NOTIFY_ERROR, ["green"] = NOTIFY_UNDO, ["light blue"] = NOTIFY_HINT, ["orange"] = NOTIFY_CLEANUP } function ulx.notifyp( calling_ply, target_plys, minutes, notifytype, message ) local notify = notifytypes[notifytype] or NOTIFY_GENERIC -- Code end You will have to change notifytype to be a string, however.
Okay, seems to work but how do i set the ulx to understand that as a specific type. example notifyp:addParam{ type=ULib.cmds.StringArg, completes=notifytypes, hint="Type of Alert", error="invalid type \"%s\" specified", ULib.cmds.restrictToCompletes, default="Red", ULib.cmds.optional } This is the Param for the notifytype but it says, every notifytype is invalid and in the ulx menu it does not even list them.
Who ever would like to use this command, go to this pastebin, this command should do a notification on the player(s) that u select as well as you can pick the type. change the colors to what your hud looks like with the notification(s)
Sorry, you need to Log In to post a reply to this thread.