1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
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!

cl_hooks GetSharedVar GetCharacterData Issues

Discussion in 'Development' started by Xenoxia, Jul 15, 2015.

  1. So, trying to make a plugin here for cl_hooks that shows some information through DrawTargetPlayerStatus; but I'm having quite a bit of an issue. I've tried using target:GetSharedVar or even target:GetCharacterData and they keep coming up as nil despite knowing that they shouldn't be.

    I have a sh_hooks that uses ClockworkAddSharedVars to add both the playerVars: and a sv_hooks that set the vars as the character loads in, just like how it gets if the character is tied or not.

    However, it's not working at all. I even tried Clockwork.Client:GetSharedVar("") but it just keeps throwing out errors, saying that the value is nil and such.

    What do?

    Edit - It's strange because target:GetFaction() works and so does target:Name() and such like that, so why can't it get the characters data? Also, is there something similar or such that I could use like target:GetClass() ?
     
  2. Any possible way to get the servers character data as a client? How would I transfer the target:GetCharacterData through to the client?
     
  3. duck

    duck Phant0m Legend

    Post the code.
     
    • Friendly Friendly x 1
  4. sv_hooks
    Code:
    -- Called when a player's character has loaded.
    function PLUGIN:PlayerCharacterLoaded(player)
        player:SetCharacterData("showid", true);
        player:SetSharedVar("showid", true);
        player:SetSharedVar("CharFactionRankSecondary", player:GetCharacterData("CharFactionRankSecondary"));
    end;
    
    -- Called when a player's shared variables should be set.
    function PLUGIN:PlayerSetSharedVars(player, curTime)
        player:SetSharedVar("showid", true);
        player:SetSharedVar("CharFactionRankSecondary", player:GetCharacterData("CharFactionRankSecondary"));
    end;
    sh_hooks
    Code:
    function PLUGIN:ClockworkAddSharedVars(globalVars, playerVars)
        playerVars:String("CharFactionRankSecondary");
        playerVars:Bool("showid");
    end;
    cl_hooks
    Code:
    function PLUGIN:DrawTargetPlayerStatus(target, alpha, x, y)
    local getidvar = player:GetSharedVar("showid");
    local getclassvar = player:GetSharedVar("CharFactionRankSecondary");
    
    if(getidvar) then
            local newGender = "His";
            if(target:GetGender() == GENDER_FEMALE) then
                local newGender = "Her";
            end;
            mainStatus = newGender.." facility id says - ** Name: "..target:Name().." Position: "..getclassvar
        else
            mainStatus =  gender.." is not wearing a facility id."
        end;
    if (mainStatus) then
                y = Clockwork.kernel:DrawInfo(Clockwork.kernel:ParseData(mainStatus), x, y, informationColor, alpha);
    end;
         
            return y;
    end;
    
    I know it's a bit jumbly, I removed all the unrelated code.
     
  5. You to use datastreams. I don't think that is a clientsided function.
     
  6. How would I go about using those in place of what I have? I've never used datastreams.
     
  7. It might not be datastreams at all, but I also see this:
    Code:
    local getidvar = player:GetSharedVar("showid");
    
    Player is, of course, never defined by itself. It should be:
    Code:
    local getidvar = target:GetSharedVar("showid");
    
    =====

    For the record, you use datastreams like this:

    Let's say you want to send a name from the server to the client. In a clientsided file, add the hook:
    Code:
    Clockwork.datastream:Hook("NameOfShitizen", function(data)
    thename = data
    print( thename )
    end)
    
    And in your server sided file:
    Code:
    Clockwork.datastream:Start("NameOfShitizen", blabla)
    
    blabla meaning the name of the variable/table/string to send.
     
  8. I've been getting confused and swipping and swapping through code that I must have forgot that when I tried it last. I'll try it but I doubt it'll fix it because it was target: before. ;(
     
  9. It may just be one of the many issues.
     
    • Agree Agree x 1
  10. Yep, It was one of the issues. The issue before that after I set it to player: acidently instead of target: was that I didn't include

    Code:
    function PLUGIN:PlayerSetSharedVars(player, curTime)
    end;
    Seems to be fixed, thanks.
     

Previous Readers (Total: 0)