• What did I do wrong?
    14 replies, posted
Hello! I just started out in LUA, so don't laugh at me! I morelikely just tried to make my character jump once, when this is executed.. When I ran it - this happened [code]includes/modules/concommand.lua:59: bad argument #1 to 'lower' (string expected, got nil)[/code] Here's the tiny piece of code :D [code]function SuperJump() timer.Create("MyTimer", 1, 1, concommand.Run "+jump") timer.Create("MyTimer", 1, 1, concommand.Run, "-jump") end concommand.Add("super_jump", SuperJump) [/code] What did I do wrong? :(
Two things: Wrote over the same timer, so it doesn't do what you want. Also, concommand.Run isn't a valid function. Use LocalPlayer():ConCommand or RunConsoleCommand. Try this: [code]function SuperJump() timer.Simple(1,RunConsoleCommand,"+jump") timer.Simple(1.01, RunConsoleCommand, "-jump") end concommand.Add("super_jump", SuperJump)[/code]
Aha :D - Thanks.. And which command do I have to use to make everything a loop?
Bad idea. [editline]05:06PM[/editline] Infinite loops do not end well.
[QUOTE=Entoros;17087831]Also, concommand.Run isn't a valid function.[/QUOTE] concommand.Run is a valid function, but you should never use it.
[QUOTE=|FlapJack|;17088913]concommand.Run is a valid function, but you should never use it.[/QUOTE] Unless you want to listen in on commands, which is necessary for things like displaying scoreboard ratings.
[QUOTE=Overv;17089098]Unless you want to listen in on commands, which is necessary for things like displaying scoreboard ratings.[/QUOTE] You can use engineConsoleCommand for the exact same purpose.
Okay.. Good to know :D Thanks for the help :D Though... I would really like to try to loop it :P Which command? :D ------------------------------------------------------------- Now's something wrong again -_- [code] function SuperJump() timer.Simple(1,RunConsoleCommand,"+jump") timer.Simple(2, RunConsoleCommand, "-jump") end for i=1,100 do function SuperJump end concommand.Add("super_jump", SuperJump) [/code]
[lua] function SuperJump() for i=1, 100 do timer.Simple(1,RunConsoleCommand,"+jump") timer.Simple(2, RunConsoleCommand, "-jump") end end concommand.Add("super_jump", SuperJump) [/lua] Should be the same as what you tried.
[QUOTE=Rdenzaci;17094176][lua] function SuperJump() for i=1, 100 do timer.Simple(1,RunConsoleCommand,"+jump") timer.Simple(2, RunConsoleCommand, "-jump") end end concommand.Add("super_jump", SuperJump) [/lua] [/QUOTE] *gouges out eyes* Can we teach him about [url=http://lua-users.org/wiki/GarbageCollectionTutorial]garbage collection[/url]? Also, all those commands would be issued at the same times...
[QUOTE=Sherkas;17089505]Okay.. Good to know :D Thanks for the help :D Though... I would really like to try to loop it :P Which command? :D ------------------------------------------------------------- Now's something wrong again -_- [code] function SuperJump() timer.Simple(1,RunConsoleCommand,"+jump") timer.Simple(2, RunConsoleCommand, "-jump") end for i=1,100 do function SuperJump end concommand.Add("super_jump", SuperJump) [/code][/QUOTE] I would try something like this instead: [code]local function Jump() timer.Simple(1,RunConsoleCommand,"+jump") timer.Simple(1.01, RunConsoleCommand, "-jump") end local function SuperJump() timer.Create("SuperJump",1,100,Jump) end concommand.Add("super_jump",SuperJump)[/code]
Thanks, again^^ Now you just gotta... tell me what that "local" means infront the "function"...
[QUOTE=Sherkas;17104383]Thanks, again^^ Now you just gotta... tell me what that "local" means infront the "function"...[/QUOTE] Means that that function is specific to that lua file.
Okay uff.... Now that this is finished, I tried myself in a "small" fretta gamemode. I wanted to make it about, breaking boxes... :D Now..... I took the start from there. [url]http://wiki.garrysmod.com/?title=Lua:Fretta[/url] Now uhm I got several problems: o I need to tell him that he shall spawn boxes randomly all over the world o I need to tell him, that he shall add +1 frag to a player which destroys a crate... I somehow... found the right command but failed in implenting it... :( The command: [code] /*--------------------------------------------------------- Name: gamemode:EntityTakeDamage( entity, inflictor, attacker, amount ) Desc: The entity has received damage ---------------------------------------------------------*/ function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) if ( ent:IsPlayer() ) then ent:OnTakeDamage( inflictor, attacker, amount ) end end [/code] What I did..... [code] function GM:EntityTakeDamage( models/props_junk/wood_crate001a.mdl, ply, ply, 100 ) if ( ent:IsProp() ) then ent:OnTakeDamage( ply, ply, 100 ) end end [/code]
Let me comment your code a bit. (I'm not trying to be mean)[QUOTE=Sherkas;17104636] [code] function GM:EntityTakeDamage( models/props_junk/wood_crate001a.mdl, ply, ply, 100 ) -- Each time this function is called (everytime an entity takes damage) it will assume the entity is named models and that it took 100 damage. It'll also give you an error because your model path wasn't a string ( ""). if ( ent:IsProp() ) then -- IsProp Isn't a valid function ent:OnTakeDamage( ply, ply, 100 ) -- :S This is an event called inside an event, it wouldn't work and it's weird xD end end [/code][/QUOTE] Now let me explain what it actually is. [lua] function GM:EntityTakeDamage( ent, inflictor, attacker, amount ) --This code will run each time an entity takes damage. --Several parameters are passed to it. -- 1 the attacked entity 2 the entity that made the damage 3 the attacker 4 the ammount of damage if ( ent:GetModel() == "models/props_junk/wood_crate001a.mdl" ) and attacker:IsPlayer() then -- if the entity's model is the crate and the attacker is a player if (ent:Health( ) - amount) <= 0 then -- and if the entity's health less the amount of damage is <= 0 then attacker:AddFrags (1) -- Give the player a frag! :D end end end[/lua] This code isn't tested, but should work in theory. I hope this helps, next time try looking in the wiki. A good way to search it is [url=http://luasearch.overvprojects.nl/]Overv's LuaSearch[/url]
Sorry, you need to Log In to post a reply to this thread.