• TTT ProveAddon-Help
    6 replies, posted
Hey! I'm having several problems with my TTT Prove-Addon. At first some information. [B]1. What it does?[/B] Everybody knows the following situation: You're detective, you prove someone, and nobody cares about it. My addon needs to fix this. [B] 2. How to prove someone?[/B] Only detectives can execute the command (it's an chat-command). Example: Detective types "!prove banana" in the chat, the player banana receives a message ("Hey m8, you're proven!"), and is proven. In the scoreboard is now "Yes" in banana's row [Proven]. [B] 3. My problems/questions[/B] This might be tricky, but i hope someone can help. I already have some weird code, just for starting. The following might be a good start, but some things are missing. -Only detectives can execute the command -The current state [Proven-or-not] in the scoreboard Can someone help? sb_main.lua (gamemode/vgui) [CODE]--Proven self.cols[6] = vgui.Create( "DLabel", self ) self.cols[6]:SetText("Proven") self.cols[6]:SetTextColor(Color(33,110,209))[/CODE] sb_row.lua (gamemode/vgui) [CODE]local isProven = false -- Here i need help, i want that this variable changes to "true" when the detective types !prove [name] self.cols[6] = vgui.Create("DLabel", self) self.cols[6]:SetText("No")[/CODE] Bla [CODE]if ply:IsDetective() or isProven then self.cols[6]:SetText("Yes") self.cols[6]:SetTextColor(Color(33,110,209)) end[/CODE] [IMG]http://i.imgur.com/T45i1WB.jpg[/IMG]
[URL="http://wiki.garrysmod.com/page/Hook_Library_Usage"]hook[/URL] into [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSay]GM/PlayerSay[/url], check if the speaker is a detective (PLAYER:GetRole()) and entered the command (using [url=http://wiki.garrysmod.com/page/string/sub]string.sub[/url] or something), get the name the detective entered [img]http://wiki.garrysmod.com/favicon.ico[/img] (using [url=http://wiki.garrysmod.com/page/string/sub]string.sub[/url] or something), loop through players and compare the [URL="[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/Nick]Player:Nick[/url]"]names[/URL], then [URL="http://wiki.garrysmod.com/page/Entity/SetNWBool"]set a NWBool[/URL] on the player which can be [URL="[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetNWBool]Entity:GetNWBool[/url]"]got[/URL] clientside. Remember to reset everyone's on round end.
Thanks for your reply! I've done this now. The problem: The scoreboard doesn't update the NWBool. Detectives are automatically proven. Code: [CODE] if ply:IsDetective() or ply.Proven bla [/CODE] I'll upload the other files to dropbox.
[QUOTE=_TheJok3r_;47477667] I'll upload the other files to dropbox.[/QUOTE] Use GitHub instead.
[url]https://github.com/expl0itr/addon[/url] Maybe someone can help, like i said, the scoreboard doesn't update the "NO" in the "Proven"-Row.
You're over complicating this entire thing... Simple dynamic chat command system: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html[/url] - remove .html to view .lua - several examples.. One uses console commands, the other adds salt and pepper to the commands and provides a helper function chatcommand.Add instead of concommand.Add.... Make the console command... Server side [code]util.AddNetworkString( "TTTProving" ); concommand.Add( "prove", function( _p, _cmd, _args ) // RCON, Dead players, or non-detectives can't use this if ( !IsValid( _p ) || !_p:Alive( ) || !_p:IsActiveDetective( ) ) then return; end // Search for player typed in as args - use helper function so un-proving people is easier for accidental proves... -- ... // If player was found, and that player is alive, and not a detective ( no need ) then prove... ( same for unprove ) - NOTE - you will only need to network 2 things... The player entity, and the Boolean for proven ( so unproving can use the same net message ) - true for proven, false for not.. -- ... end ); [/code] CLIENT SIDE [code]net.Receive( "TTTProving", function( _len ) local _p = net.ReadEntity( ); local _proven = net.ReadBool( ); local _text = "Player, %s, has been considered %s in the eyes of a detective!"; // Update var _p.ProvenStatus = _proven; // Notify all.. chat.AddText( ( ( _proven ) && color_white || Color( 255, 0, 0, 255 ) ), string.format( _text, _p:Nick( ), ( ( _proven ) && "proven" || "untrustworthy" ); end );[/code] For the scoreboard, instead of modifying it... use the built in hook... Example using rank-names for someone: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/ttt/adding_scoreboard_columns_using_new_hook.lua.html[/url] Now, if the scoreboard doesn't update when ProvenStatus changes, you'll need to add a hook so that when the vgui is created, it monitors the data for when it changes, but if I recall correctly if you target the entity table variable, you should have no issue with it updating so nothing special should need to be done ( the added columns should be monitored and they're redrawn anyway each frame they're up )... That's really it.. Nothing else should need to be done for this type of addon.
Thanks Acecool! I didn't knew how to hook functions from the scoreboard. It's quite simple, probably I messed everything up. Have a nice day.
Sorry, you need to Log In to post a reply to this thread.