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 try to edit data with command

Discussion in 'Development' started by K.N.G., Mar 31, 2019.

  1. Hello, Cloud sixteen's community, I'm a part of a dev team for another hl2rp server and I've been trying to add a command allowing players to edit someone's data without opening the panel.This is the result:
    Code:
    local PLUGIN = PLUGIN;
    local Clockwork = Clockwork;
    
    local COMMAND = Clockwork.command:New("addPoints");
    COMMAND.tip = "Voir la data d'une personne donné.";
    COMMAND.text = "<Nom|CID>";
    COMMAND.flags = CMD_DEFAULT;
    COMMAND.arguments = 2;
    
    -- Called when the command has been run.
    function COMMAND:OnRun(player, arguments)
        local target = Clockwork.player:FindByID(arguments[1]);
        local targetdataPoints=arguments[2];
        newTable={
            rsn="test",
            usr="system",
            loy="Crédit de stérilisation",
            num=tonumber(targetdataPoints)
        };
        target:SetCharacterData("combinepoints",newTable);
    end;
    
    COMMAND:Register();
    But it does not work, I don't know why when I check the data with /viewdata I have this error.
    Code:
    [ERROR] gamemodes/cwhl2rp/plugins/betterviewdata/plugin/derma/cl_data.lua:248: attempt to index a string value with bad key ('rsn' is not part of the string library)
    1. error - [C]:-1
    2. __index - lua/includes/extensions/string.lua:297
    3. PopulateRecords - gamemodes/cwhl2rp/plugins/betterviewdata/plugin/derma/cl_data.lua:248
    4. Populate - gamemodes/cwhl2rp/plugins/betterviewdata/plugin/derma/cl_data.lua:148
    5. unknown - gamemodes/cwhl2rp/plugins/betterviewdata/plugin/cl_plugin.lua:12
    6. func - gamemodes/clockwork/framework/libraries/sh_datastream.lua:186
    7. unknown - lua/includes/extensions/net.lua:32
     
    Last edited: Mar 31, 2019
  2. Viz

    Viz Legend Clockwork Customer Active Member

    The "combinepoints" character data is a table that contains multiple tables for each entry you see on viewdata. What you are essentially doing here is destroying that main table that stores the individual entries, and replacing it with a singular entry. Clockwork isn't designed to process this, hence the error.
    Code:
    local PLUGIN = PLUGIN;
    local Clockwork = Clockwork;
    
    local COMMAND = Clockwork.command:New("addPoints");
    COMMAND.tip = "Voir la data d'une personne donné.";
    COMMAND.text = "<Nom|CID>";
    COMMAND.flags = CMD_DEFAULT;
    COMMAND.arguments = 2;
    
    -- Called when the command has been run.
    function COMMAND:OnRun(player, arguments)
      local target = Clockwork.player:FindByID(arguments[1]);
      local targetdataPoints=arguments[2];
    
      if (IsValid(target)) then
        local combinePoints = target:GetCharacterData("combinepoints") or {};
    
        newTable={
        rsn="test",
        usr="system",
        loy="Crédit de stérilisation",
        num=tonumber(targetdataPoints)
        };
    
        table.insert(combinePoints, newTable);
    
        target:SetCharacterData("combinepoints", combinePoints);
       end;
    end;
    
    COMMAND:Register();
    
    Something more along these lines is what you're looking for - what I'm doing here is getting the player's current "combinepoints" character data and then inserting the newly created entry into that table. This should allow Clockwork to process it as you intend.
     
    • Good Coder Good Coder x 1
  3. It's work,Thanks :)