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!

sh_fixes.lua:100

Discussion in 'Development' started by Vortix, Nov 23, 2014.

  1. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    I'm getting an error on the file.Exist function (sh_fixes.lua line 100, at the #files point)
    This is the code I'm trying to run:
    Code:
    local Clockwork = Clockwork;
    local COMMAND = Clockwork.command:New("PlyGiveFlags");
    COMMAND.tip = "Give flags to a player.";
    COMMAND.text = "<string Name> <string Flag(s)>";
    COMMAND.access = "s";
    COMMAND.arguments = 2;
    function COMMAND:OnRun(player, arguments)
    	local target = Clockwork.player:FindByID(arguments[1])
    	if (target) then
    		if (string.find(arguments[2], "a") or string.find(arguments[2], "s")
    		or string.find(arguments[2], "o")) then
    			Clockwork.player:Notify(player, "You cannot give 'o', 'a' or 's' flags!");
    		else
    			SaveFlags(target, arguments[2])
    			Clockwork.player:GiveFlags(target, arguments[2]);
    			Clockwork.player:NotifyAll(player:Name().." gave "..target:Name().." '"..arguments[2].."' global flags.")
    		end;
    	else
    		Clockwork.player:Notify(player, arguments[1].." is not a valid character!");
    	end;
    end;
    COMMAND:Register();
    These are the functions, in sv_plugin.lua
    Code:
    function LoadFlags(player)
    	plyflags = Clockwork.kernel:RestoreSchemaData("plugins/playerflags/"..player:SteamID());
    	return plyflags
    end
    
    function SaveFlags(player, flags)
    	local curflags = LoadFlags(player)
    	local plyflags = flags
    	if(curflags != nil and curflags != "") then
    		for x = 0, string.len(plyflags) do
    			if !string.find(curflags, string.sub(plyflags, x, x)) then
    				curflags = curflags..string.sub(plyflags, x, x)
    			end
    		end
    	end
    	Clockwork.player:GiveFlags(player, curflags);
    	Clockwork.kernel:SaveSchemaData("plugins/playerflags/"..player:SteamID(), curflags);
    end
     
  2. sants1

    sants1 I'm an asshole. That's all.

    I don't see where it's saying you have an error. Can you point it out? #files doesn't really help me at all.
     
  3. NightAngel

    NightAngel Fuck off Lev

    Give us the actual error that it's giving you.
     
  4. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Sorry, here it is:
    [Clockwork] The 'PostPlayerSpawn' plugin hook has failed to run.
    gamemodes/clockwork/framework/sh_fixes.lua:100: attempt to get length of local 'files' (a nil value)

    As well as:
    [Clockwork] The 'PlyGiveFlags' command has failed to run.
    gamemodes/clockwork/framework/sh_fixes.lua:100: attempt to get length of local 'files' (a nil value)

    With the PostPlayerSpawn hook being the following:
    Code:
    function PLUGIN:PostPlayerSpawn(player, lightSpawn, changeClass, firstSpawn)
    	Clockwork.player:TakeFlags(player, allflags)
    	if(player:GetCharacterData(ExemptFlags) != nil and player:GetCharacterData(ExemptFlags) != "") then
    		Clockwork.player:GiveFlags(player, LoadFlags(player)..player:GetCharacterData(ExemptFlags))
    	else
    		Clockwork.player:GiveFlags(player, LoadFlags(player))
    	end
    end
    My own personal theory is that as the file for " Clockwork.kernel:SaveSchemaData("plugins/playerflags/"..player:SteamID(), curflags);" doesn't exist yet, and it would use the file.Exist to check it (which has issues) the file is nil and so it comes up with an error. What I don't know is how to prevent it without using the file.Exists in one of my checks (as it is broken I can't use it)
     
  5. NightAngel

    NightAngel Fuck off Lev

    Shit, that's weird...

    [member=1]kurozael[/member] [member=5482]duck[/member]
     
  6. duck

    duck Phant0m Legend

    This isn't a good to way to it. You should be using character data instead of writing to files.
     
  7. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    I was in an old version, however the CharacterData doesn't go between characters, and the plugin functions to give flags to all of a player's characters.
     
  8. Crater

    Crater Hostell Roleplay

    You should be able to use Clockwork.player:GetCharacters(player) to get all of a player's characters, then feed that table into a loop that gives each character the flags.

    e.g.
    Code:
    for k, v in pairs(Clockwork.player:GetCharacters(target)) do
         Clockwork.player:GiveFlags(k, flags);
    end
    
    At least, I'm pretty sure that's how it would work. If I'm wrong in saying this, someone please correct me.
     
  9. duck

    duck Phant0m Legend

    GiveFlags takes a player as the first argument. Something like this could be done.

    Code:
    local charactersTable = Clockwork.config:Get("mysql_characters_table"):Get();
    
    local queryObj = Clockwork.database:Update(charactersTable);
    	queryObj:SetValue("_Flags", player:GetFlags()..arguments[2]);
    	queryObj:AddWhere("_SteamID = ?", player:SteamID());
    queryObj:Push();
    No new characters they make would have the flags, but you could make something for that.
     
  10. sants1

    sants1 I'm an asshole. That's all.

    Use the newest version of Clockwork. Old versions are not supported.
     
  11. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Never used those functions before so it never popped into my mind, but it makes sense, so thanks, I'll definately use that.

    I meant an old version of my plugin.

    EDIT: If I use this will it automatically update a player's flags whilst they are playing with the character whose flags got updated?
    EDIT2: How might I load the content of _Flags? Extremely stupid question
     
  12. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Doesn't seem to work:
    Code:
    function SaveFlags(player, flags)
    	local charactersTable = Clockwork.config:Get("mysql_characters_table"):Get();
    	local queryObj = Clockwork.database:Update(charactersTable);
    		queryObj:SetValue("_Flags", player:GetFlags()..flags);
    		queryObj:AddWhere("_SteamID = ?", player:SteamID());
    	queryObj:Push();
    end
    Code:
    local Clockwork = Clockwork;
    local COMMAND = Clockwork.command:New("PlyGiveFlags");
    COMMAND.tip = "Give flags to a player.";
    COMMAND.text = "<string Name> <string Flag(s)>";
    COMMAND.access = "s";
    COMMAND.arguments = 2;
    function COMMAND:OnRun(player, arguments)
    	local target = Clockwork.player:FindByID(arguments[1])
    	if (target) then
    		if (string.find(arguments[2], "a") or string.find(arguments[2], "s")
    		or string.find(arguments[2], "o")) then
    			Clockwork.player:Notify(player, "You cannot give 'o', 'a' or 's' flags!");
    		else
    			SaveFlags(target, arguments[2])
    			Clockwork.player:NotifyAll(player:Name().." gave "..target:Name().." '"..arguments[2].."' global flags.")
    		end;
    	else
    		Clockwork.player:Notify(player, arguments[1].." is not a valid character!");
    	end;
    end;
    COMMAND:Register();
    Doesn't give the player the flags.
     
  13. duck

    duck Phant0m Legend

    Add this below the call to SaveFlags.

    Code:
    target:SetSharedVar("Flags", target:GetFlags()..arguments[2]);
     
  14. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Nope :'(
     
  15. Vortix

    Vortix Moderator Staff Member Moderator Legend Clockwork Customer

    Found a better, working way of doing this.
    Code:
    player:SetData
    If anyone is interested ^
     

Previous Readers (Total: 0)