• Lua even triggered with func_button
    12 replies, posted
I would like to know if a lua command could be triggered with an in map func. For example, would it be possible to make a func_button in the map (let's call it button_open_doom_door) make lua fire the function "GM:Giveallweapons()". (note: this is a oversimplified example just to describe what I need to know). Is there a restriction just to init.lua or can it be used in shared .lua as well? Thanks in advance
[QUOTE=thejjokerr;26361340][url]http://wiki.garrysmod.com/?title=Gamemode.PlayerUse[/url][/QUOTE] Thanks a lot.
I just want to add something for this If you wanted it to be that it prints the message when someone presses the button would it be: [lua] function DoomDoorButton( ply, entity ) if (entity:GetClass("button_open_doom_door")) then Msg( "Player " .. ply:Nick() .. " used " .. entity:GetClass() .. " at " .. tostring( entity:GetPos() ) .. "\n" ); end end hook.Add( "PlayerUse", "PrintUseInformation", PrintUseInformation ) [/lua] I know this is wrong, but is this the sort of way you would go around doing this? (I was trying to do a remake of the CoD Nazi Zombie feature so then I would have a button that would cost money but also open the door)
[lua] function DoomDoorButton( ply, entity ) if (entity:GetName() == "button_open_doom_door") then MsgN( "Player " .. ply:Nick() .. " used " .. entity:GetClass() .. " at " .. tostring( entity:GetPos() ) ); end end hook.Add( "PlayerUse", "DoomDoorButton", DoomDoorButton ) [/lua]
Nice, thanks for that everyone, looks good :D
(Only bumping because otherwise this post won't be read!) How would I make it so that if the button was pressed and the play can afford the money then the door would open? Would this is done using Lua or in the Hammer Editor?
[QUOTE=xomaxhox;26382680](Only bumping because otherwise this post won't be read!) How would I make it so that if the button was pressed and the play can afford the money then the door would open? Would this is done using Lua or in the Hammer Editor?[/QUOTE] [url]http://wiki.garrysmod.com/?title=Entity.Remove[/url] I think this might do the job
Thanks anyway, but I found it out myself For anyone that wants to know the code should be [lua] function DoomDoorButton( ply, entity ) if (entity:GetName() == "button_open_doom_door") then Entity:Fire('open', '', 0) end end hook.Add( "PlayerUse", "PrintUseInformation", PrintUseInformation ) [/lua] Untested but should work :D
if (entity:GetClass() == "button_open_doom_door") then
[QUOTE=Freze;26388097]if (entity:GetClass() == "button_open_doom_door") then[/QUOTE] That was wrong anyway, and I changed mine because I forgot to change it when I originally posted
also, if source does not know the entity on map spawn it will be removed(If my memory is correct) the correct 'way' to do it is to make an entity in lua/entites/ and use the use function there.
Sorry, you need to Log In to post a reply to this thread.