• A couple of questions
    4 replies, posted
Question 1: Hey, so I want to make a command that requires arguments, like !goto <player>, how does one make a command that finds the player and sends them? Question 2: I want to make a command like !gotov <player> that will teleport the player to a players vehicle (that they spawned with the Q menu) Note: I do not want these commands made for ULX, not for any admin mod, just the Player say stuff.
You could do it using Lua Patterns [code]hook.Add("PlayerSay","goto_command", function(sender,text,_) -- Makes sure if the player is an Admin, if not it will not work if not sender:IsAdmin() then return end -- Get the arguments local _,_,playername = text:find("!goto (%w+)") -- Find the player for k,v in pairs(player.GetAll()) do if v:Name() == playername then -- Goto them end end end)[/code] However this code has some flaws such as you cant goto players with a space in their name. as for GOING to the players, im not quite sure.
1. Make a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSay]GM:PlayerSay[/url] hook, check if the message starts with "!goto" with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/string/sub]string.sub[/url], then loop through [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/player/GetAll]player.GetAll[/url] and compare [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/Nick]Player:Nick[/url] with the rest of the message. 2. Make a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnVehicle]SANDBOX:PlayerSpawnVehicle[/url] and cache the vehicle in a table with the client that spawned it's SteamID as the key, then just do what I said above while also checking if the player does have a vehicle by checking the table. You could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetVehicle]Player:GetVehicle[/url] instead but that only works if the target is in the vehicle. You can set a player's position by using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetPos]Entity:SetPos[/url] and getting the target's position with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetPos]Entity:GetPos[/url].
-snip I'm wrong-
[QUOTE=gmoddertr;52661743]ur code would block players from texting who are not admin.[/QUOTE] How? It's returning, not returning an empty string.
Sorry, you need to Log In to post a reply to this thread.