• Making preset ULX ent command
    10 replies, posted
In short, I would like help making a ULX command that just spawns in a specified prop without any params or classnames. For example if I made this command and it was for a vending machine it would be as follows: classname: prop_physics params: model:models/props/cs_office/vending_machine.mdl Here's my code so far: [CODE] local CATEGORY_NAME = "Spawnables" function ulx.prop( calling_ply, classname, params ) if not calling_ply:IsValid() then Msg( "Can't create entities from dedicated server console.\n" ) return end classname = prop_physics newEnt = ents.Create( classname ) -- Make sure it's a valid ent if not newEnt or not newEnt:IsValid() then ULib.tsayError( calling_ply, "Unknown entity type (" .. classname .. "), aborting.", true ) return end local trace = calling_ply:GetEyeTrace() local vector = trace.HitPos vector.z = vector.z + 20 newEnt:SetPos( vector ) -- Note that the position can be overridden by the user's flags params:gsub( "([^|:\"]+)\"?:\"?([^|]+)", function( key, value ) key = key:Trim() value = value:Trim() newEnt:SetKeyValue( key, value ) end ) newEnt:Spawn() newEnt:Activate() undo.Create( "ulx_ent" ) undo.AddEntity( newEnt ) undo.SetPlayer( calling_ply ) undo.Finish() if not params or params == "" then ulx.fancyLogAdmin( calling_ply, "#A created ent #s", classname ) else ulx.fancyLogAdmin( calling_ply, "#A created ent #s with params #s", classname, params ) end end local prop = ulx.command( CATEGORY_NAME, "ulx prop", ulx.ent ) prop:addParam{ type=ULib.cmds.StringArg, hint="prop_physics", } prop:addParam{ type=ULib.cmds.StringArg, hint="model:", ULib.cmds.takeRestOfLine, ULib.cmds.optional } prop:defaultAccess( ULib.ACCESS_SUPERADMIN ) prop:help( "Spawns a vending machine" )[/CODE] If anyone can help, it would be appreciated! [editline]22nd May 2016[/editline] *bumb* [editline]22nd May 2016[/editline] *BUMP*
Might have more luck on the ulysses forums
I figured. No luck so far though.
Any help?
Uh, you could try something like RunConsoleCommand("ulx","ent","prop_physics","model: ..") That way you're not trying to mess with the ULX internals, rather just making a wrapper for ulx ent.
Ok, I tried that. Now it shows the errors: [ERROR] addons/ulx/lua/ulx/modules/sh/spawnables.lua:4: syntax error near 'ulx' 1. unknown - addons/ulx/lua/ulx/modules/sh/spawnables.lua:0 and: [ERROR] addons/ulx/lua/ulx/modules/sh/rcon.lua:79: attempt to index local 'classname' (a nil value) 1. call - addons/ulx/lua/ulx/modules/sh/rcon.lua:79 2. __fn - addons/ulib/lua/ulib/shared/commands.lua:943 3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296 4. Run - lua/includes/modules/concommand.lua:54 5. unknown - addons/ulib/lua/ulib/shared/commands.lua:1311 6. unknown - lua/includes/modules/concommand.lua:54 When I use the code: [code]local CATEGORY_NAME = "Spawnables" function ulx.vendingmachine( calling_ply ) local RunConsoleCommand("ulx ent prop_physics model:models/props/cs_office/vending_machine.mdl") ulx.fancyLogAdmin( calling_ply, "#A created a vending machine!", classname ) end local vendingmachine = ulx.command( CATEGORY_NAME, "ulx vendingmachine", ulx.ent ) vendingmachine:defaultAccess( ULib.ACCESS_SUPERADMIN ) vendingmachine:help( "Spawns a vending machine" )[/code]
This shouldn't be hard. A lot of the code can be simplified since you're only wanting the prop itself and not wanting to add any parameters to altering the entity. [CODE] local CATEGORY_NAME = "Spawnables" -- The command can be found in the ULX GUI menu by doing !menu in chat or xgui in console and looking under 'Spawnables' category function ulx.prop( calling_ply ) if not calling_ply:IsValid() then Msg( "You're a God, yes, but you can't spawn vending machines at this time.\n" ) return end -- Create the entity first, making it a prop_physics so it can be moved with the Physics Gun vendM = ents.Create( "prop_physics" ) -- Used to spawn the vending machine at crosshair local trace = calling_ply:GetEyeTrace() local vector = trace.HitPos vector.z = vector.z + 20 vendM:SetPos( vector ) -- Note that the position can be overridden by the user's flags vendM:SetModel( "models/props/cs_office/vending_machine.mdl" ) -- Set the model before it spawns vendM:Spawn() vendM:Activate() -- Make this undo-able undo.Create( "vending machine" ) undo.AddEntity( vendM ) undo.SetPlayer( calling_ply ) undo.Finish() -- Log it ulx.fancyLogAdmin( calling_ply, "#A created a vending machine" ) end local prop = ulx.command( CATEGORY_NAME, "ulx prop", ulx.prop ) -- You had ulx.ent instead of ulx.prop, which is the function above prop:defaultAccess( ULib.ACCESS_SUPERADMIN ) prop:help( "Spawns a vending machine" ) [/CODE] You can do "ulx prop" in console to check and see if it works.
Sweet! Thanks! [editline]25th May 2016[/editline] It won't spawn in, after 2 restarts. All I get is: [ERROR] addons/ulx/lua/ulx/modules/sh/spawnables.lua:10: bad argument #1 to 'Create' (string expected, got nil) 1. Create - [C]:-1 2. call - addons/ulx/lua/ulx/modules/sh/spawnables.lua:10 3. __fn - addons/ulib/lua/ulib/shared/commands.lua:943 4. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296 5. Run - lua/includes/modules/concommand.lua:54 6. unknown - addons/ulib/lua/ulib/shared/commands.lua:1311 7. unknown - lua/includes/modules/concommand.lua:54
[QUOTE=ThyMason122;50390022]Sweet! Thanks! [editline]25th May 2016[/editline] It won't spawn in, after 2 restarts. All I get is: [ERROR] addons/ulx/lua/ulx/modules/sh/spawnables.lua:10: bad argument #1 to 'Create' (string expected, got nil) 1. Create - [C]:-1 2. call - addons/ulx/lua/ulx/modules/sh/spawnables.lua:10 3. __fn - addons/ulib/lua/ulib/shared/commands.lua:943 4. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296 5. Run - lua/includes/modules/concommand.lua:54 6. unknown - addons/ulib/lua/ulib/shared/commands.lua:1311 7. unknown - lua/includes/modules/concommand.lua:54[/QUOTE] if you'd look at the error instead of making us fix this for you, you could tell that SupahMarioX missed some " in the ents.Create function, but no, you want us to do it all for you. This is not how it works.
Actually I did see it, But I don't know what to put instead of ents.Create.
[QUOTE=ThyMason122;50390463]Actually I did see it, But I don't know what to put instead of ents.Create.[/QUOTE] -facepalm- [CODE]bad argument #1 to 'Create' (string expected, got nil)[/CODE] Just put quotation marks around prop_physics on the ents.Create line. geferon's right though - analyze the error. It literally said the argument needed to be a string.
Sorry, you need to Log In to post a reply to this thread.