1. Check out the Store if you're looking to Buy HL2RP or other schemas for your server. You can click Buy Schemas on the very top navigation bar to visit the store.
  2. Use the Plugin Center to easily subscribe to and auto-install Clockwork plugins to your server, or submit and share plugins you have developed.
  3. Having trouble setting up or developing with Clockwork? Check out the Wiki or post in the Support Forum for advice from fellow users.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

HL2RP Variables from Trudeau's Betterviewdata

Discussion in 'Development' started by CKG_Gaming, Dec 24, 2018.

  1. We currently use the above plugin, Betterviewdata, as our way to manage our player's character data in-game, but it's impossibly difficult for me to just pull data as I need it from players and use it elsewhere.

    For example, I dug up an old lemonpunch terminal plugin, and are trying to print the data provided by betterviewdata in chat, nothing crazy. I'll provide the portion I'm working within, rather than the whole file/plugin, as a little bit of debugging has pointed me to the problem:
    Code:
                        local data = LocalPlayer():GetCharacterData("combinepoints");
                        for i, v in pairs (self.data) do
                            local isLoyal = v.loy;
                                  local amount = tonumber(v.num) or 0;
    
                            if isLoyal then
                                loyaltyPoints = loyaltyPoints + amount;
                            else
                                penaltyPoints = penaltyPoints + amount;
                            end;
    
                        end;
    
                        local totalPoints = loyaltyPoints - penaltyPoints;
    
    
                        chat.AddText(Color(255,255,0),[[ Terminal Data ]],Color(255,255,255), "Total Points: "..totalPoints);
    
    After restarting the server to test my changes, the error I receive points the the first line, with this error:
    Code:
    [Clockwork] The 'Think' hook failed to run.
    gamemodes/cwhl2rp/plugins/terminal/plugin/entities/entities/cw_terminal/cl_init.lua:204: attempt to index local 'data' (a nil value)
    
    As far as I understand, there has to be some way to call Trudeau's declared variables. Do I have to create a datastream? A hook? Am I declaring it wrong?

    NOTE: When debugging, the terminal was able to call and print the character's name into chat, so it is able to find and identify the player.

    Edit: My goal is to print the user's total accumulated points, as calculated in that same for loop in Trudeau's plugin. The above file within the plugin is cl_init.lua for the terminal entity.
     
    Last edited: Dec 24, 2018
  2. Aspect

    Aspect =) Veteran Active Member

  3. last online: July 7, 2018
     
    • Informative Informative x 1
  4. duck

    duck Phant0m Legend Crusader

    That error does not match any line of code in your post.
     
  5. Allow me to clarify.
    For the sake of simplicity, I have left out the entire file, as it is completely irrelevant to the issue. The error, line 204, is the very first line of code.

    This code comes out as a 'nil' value, as specified in the error:
    Code:
    local data = LocalPlayer():GetCharacterData("combinepoints");
    So, through what I know in my experience of debugging, my assumption was that the server wasn't able to locate who the "LocalPlayer" was. However, this line of code did actually have the proper value:
    Code:
    local name = LocalPlayer():Name();
    Catch my drift?
    That first line of code is used by Betterviedata, and does not carry a nil value, but when called upon, it does. I want to find a way to get the value.
     
  6. Svensis

    Svensis Guest

  7. I see what you're saying. I believe I saw something along the lines of the networking you're pointing me towards within the framework, but I'm not too sure on how to carry it out. Was it with datastreams? I need a little help, here :confused: I've tried using them in the past, didn't work out too well..
     
  8. Svensis

    Svensis Guest

    Read the wiki page I sent you, try to figure out how to send a intiger/string from server to client
     
  9. Sir.. You've blown my mind with this information. Now I've applied it. The changes I made are as follows:
    • Using Clockwork.datastream:Hook I hooked a server and clientside datastream called "ShowData"
    • I declared local player = LocalPlayer():Name(); within the cl_init file of the terminal entity
    • Using "player" I started the datastream specified below

    Serverside Hook:
    Code:
    Clockwork.datastream:Hook("ShowData", function(player, data)
        if (IsValid(data[1])) then
            data[1]:SetCharacterData("loypoints", data[2]);
        end;
    end)
    Clientside Hook:
    Code:
    Clockwork.datastream:Hook("ShowData", function(data)
    
        chat.AddText(Color(255,255,0),[[ Terminal Data ]],Color(255,255,255), "Total Points: "..data[2]);
    
    
    end);
    cl_init for the entity:
    Code:
    local player = LocalPlayer():Name();
    Clockwork.datastream:Start(player, "ShowData", {player, player:GetCharacterData("loypoints") or ""});
    
    After pulling this all together with a combination of the wiki link you sent me and the framework sh_datastream library, I thought I was finished..

    ..Until I was given another error.
    Code:
    [Clockwork] The 'Think' hook failed to run.
    gamemodes/cwhl2rp/plugins/terminal/plugin/entities/entities/cw_terminal/cl_init.lua:220: attempt to index a string value with bad key ('GetCharacterData' is not part of the string library)
    
    (cl_init snippit is inside a local function PanelThink for the entity)

    Please.. help.
     
    Last edited: Dec 25, 2018
  10. Svensis

    Svensis Guest

    Use net like I told you (since it has examples in the wiki page). or ask someone else for datastream help.
     
    • Funny Funny x 1
  11. Aspect

    Aspect =) Veteran Active Member

    last online: July 7, 2018
     
  12. I hate to spam, but I could really use some datastream assistance with this. Unfortunately, I just cannot seem to get any results out of the proposed methods so far. If anybody has any experience with using the CW Datastreams, I'd greatly appreciate it.
     
    • Disagree Disagree x 1
  13. Svensis

    Svensis Guest

    Use net you have the wiki full of examples of what you want to do.
     
  14. Vortix

    Vortix Legend Clockwork Customer Active Member

    Can you show me the Use function from init.lua?
     
    • Agree Agree x 1
    • Disagree Disagree x 1
  15. Look man, I'm sorry, but it really doesn't help with the whole, "Figure it out yourself" approach, I understand where you're coming from, but throwing a book at me doesn't finish the project. I'm asking for insight on how to apply that information you've given me, it isn't easy with Clockwork and this particular case. Thank you, regardless.
     
    • Like Like x 1
  16. This is in the cl_init.lua file for the terminal entity:
    Code:
    local function PanelThink()
       
        if receiveTime then
       
            local deltaTime = CurTime() - receiveTime
            if deltaTime > 2 and input.IsKeyDown( KEY_E ) then
           
                ExitScreen()
                RunConsoleCommand( "wp_eject" )
               
            else
               
                local keyEnum = keys[ validKeysCount ]
                if keyEnum then
                   
                    if input.IsKeyDown( keyEnum ) then
                       
                        if not keyDown then
                       
                            keyDown = true
                            validKeysCount = validKeysCount + 1
                       
                        end
                       
                    elseif keyDown then
               
                        keyDown = false
                       
                    end
                   
                else
                   
                    surface.PlaySound( "ambient/machines/thumper_hit.wav" )
                   
                    secretScreen = true
                    urlOpened = true
                   
                end
    
                if nextPress < CurTime() and (input.IsKeyDown( KEY_ENTER ) or input.IsKeyDown( KEY_SPACE )) then
                    if deltaTime > 3 and input.IsKeyDown( KEY_ENTER ) then
                        CreateHTML()
                        //gui.OpenURL( "http://www.lemonpunch.net/news" )
                        surface.PlaySound( "ambient/machines/keyboard7_clicks_enter.wav" )
                       
                        urlOpened = true
                       
                    elseif deltaTime > 3 and input.IsKeyDown( KEY_SPACE ) then
    
                        net.Receive("charloy", function()
    --[[                        local data = net.ReadTable();
    
                        for i, v in pairs (data) do
                            local isLoyal = v.loy;
                                  local amount = tonumber(v.num) or 0;
    
                            if isLoyal then
                                loyaltyPoints = loyaltyPoints + amount;
                            else
                                penaltyPoints = penaltyPoints + amount;
                            end;
    
                        end;
    
                        local totalPoints = loyaltyPoints - penaltyPoints;
    --]]
                            chat.AddText(Color(255,255,0),[[ Terminal Data ]],Color(255,255,255), "Total Points: ");
                        end)
    
                        surface.PlaySound( "ambient/machines/keyboard7_clicks_enter.wav" )
                       
                        urlOpened = true
                   
                    end
                nextPress = CurTime()+3
                end
               
            end
       
        end
       
        if not LocalPlayer():Alive() and IsValid( panel ) then
            ExitScreen()
        end
       
    end
    
    Here's the sv_plugin datastream as well:
    Code:
    Clockwork.datastream:Hook("ShowData", function(player, data)
        if (IsValid(data[1])) then
            data[1]:SetCharacterData("loypoints", data[2]);
        end;
    end)
    My end goal is to receive the total points that stored as a character variable by betterviewdata, and display it in chat on the specified keypress.

    Sorry for the messy code, but that is the whole think function it is in as the "Use" function.
     
  17. Vortix

    Vortix Legend Clockwork Customer Active Member

    There should be a init.lua (not cl_init.lua), show me the contents of that.
     
  18. Sorry about that. Here's the entire file; The plugin, when it worked, linked the user to a chosen link as a derma window.
    Code:
    include("shared.lua");
    
    AddCSLuaFile("cl_init.lua");
    AddCSLuaFile("shared.lua");
    
       
        ENT.Type        = "anim"
        ENT.Base        = "base_anim"
        ENT.Author        = "Thermadyle and Blt950"
       
        AddCSLuaFile()
       
        function ENT:Initialize()
       
            self:SetModel( "models/props_combine/breenconsole.mdl" )
           
            self:PhysicsInit( SOLID_VPHYSICS )
            self:SetMoveType( MOVETYPE_NONE )
            self:SetSolid( SOLID_VPHYSICS )
           
            self:SetUseType( USE_TOGGLE )
           
        end
       
        function ENT:Use( pl )
           
            if not pl._nextComputerUse or pl._nextComputerUse < CurTime() then
           
                pl._inWebsitePanel = not pl._inWebsitePanel
                pl:DrawViewModel( not pl._inWebsitePanel )
                pl:SetMoveType( ( pl._inWebsitePanel and MOVETYPE_NONE ) or MOVETYPE_WALK )
               
                umsg.Start( "wp_screen", pl )
                umsg.Bool( pl._inWebsitePanel )
                umsg.Entity( self )
                umsg.End()
               
                pl._computer = self
                pl._nextComputerUse = CurTime() + 2
           
            end
           
        end
       
        local function ExitComputer( pl )
           
            if IsValid( pl._computer ) then
           
                pl._inWebsitePanel = false
                pl:DrawViewModel( true )
                pl:SetMoveType( MOVETYPE_WALK )
               
                umsg.Start( "wp_screen", pl )
                umsg.Bool( false )
                umsg.Entity( self )
                umsg.End()
               
                pl._computer = nil
                pl._nextComputerUse = CurTime() + 2
           
            end
           
        end
        concommand.Add( "wp_eject", ExitComputer )
     
  19. Vortix

    Vortix Legend Clockwork Customer Active Member

    Before the usermessage start begin the datastream, sending the points data. You can hook into that clientside to store the received value. You should use that received value in the panel.

    Usermessage start is the following:
    Code:
    umsg.Start( "wp_screen", pl )
     

Previous Readers (Total: 0)