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!

HL2RP If/Else not working?

Discussion in 'Development' started by NoahtheBoah36™, Jan 21, 2018.

  1. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    Code:
    -- Created by NoahtheBoah36 AKA Noah Engelmann
    -- Redistribution/use/modification is allowed provided credit is given.
    
    local ITEM = Clockwork.item:New();
    ITEM.name = "Broken Pistol";
    ITEM.model = "models/weapons/w_pistol.mdl";
    ITEM.weight = 0.5;
    ITEM.business = true;
    ITEM.batch = 1;
    ITEM.access = "@";
    ITEM.description = "[RED CONTRABAND] A broken handgun. Now who left this lying around?";
    ITEM.category = "Crafting";
    ITEM.useText = "Repair";
    
    -- When the item is dropped.
    function ITEM:OnDrop(player, position) end;
    
    -- When the item is used.
    function ITEM:OnUse(player, itemEntity)
        local ability = Clockwork.attributes:Fraction(player, ATB_SCAVENGING, 1);
        local difficulty = math.random(1, 25);
        if (ability >= difficulty) then
            Clockwork.player:Notify(player, "You successfully repaired the pistol!");
            player:GiveItem(Clockwork.item:CreateInstance("weapon_pistol"), true);
            Clockwork.attributes:Progress(player, ATB_SCAVENGING, difficulty);
            return;
        else
            Clockwork.player:Notify(player, "You failed to repair the pistol!");
            Clockwork.attributes:Progress(player, ATB_SCAVENGING, difficulty + ability);
            return;
        end;
    end;
    
    ITEM:Register();
    
    Always results in the else condition of saying I failed to repair the pistol even when I know my stats are high enough.
     
  2. RJ

    RJ no pay Legend Clockwork Customer

    Let's do some debugging. Add these lines after your local variables (that being 'ability' and 'difficulty') then tell me what gets printed to your console after you use the item:
    print("Ability:");
    print(ability);
    print("Difficulty:");
    print(difficulty);
     
    • Agree Agree x 1
  3. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    Code:
    Paul Johnson has gained a Broken Pistol 1516519080.
    Paul Johnson has gained a Broken Pistol 1516519081.
    Paul Johnson has gained a Broken Pistol 1516519082.
    Paul Johnson has gained a Broken Pistol 1516519083.
    Paul Johnson has gained a Broken Pistol 1516519084.
    Paul Johnson has gained a Broken Pistol 1516519085.
    Paul Johnson has gained a Broken Pistol 1516519086.
    Paul Johnson has gained a Broken Pistol 1516519087.
    Paul Johnson has gained a Broken Pistol 1516519088.
    Paul Johnson has gained a Broken Pistol 1516519089.
    You have given Paul Johnson ten Broken Pistols.
    Paul Johnson has used '/CharGiveItem s broken 10'.
    [HTML] http://forums.cloudsixteen.com/js/xenforo/xenforo.js?_v=073095e7:170: Uncaught TypeError: Property 'group' of object #<error> is not a function
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519080.
    Paul Johnson has used '/InvAction use broken_pistol 1516519080.00'.
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519081.
    Paul Johnson has used '/InvAction use broken_pistol 1516519081.00'.
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519082.
    Paul Johnson has used '/InvAction use broken_pistol 1516519082.00'.
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519083.
    Paul Johnson has used '/InvAction use broken_pistol 1516519083.00'.
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519084.
    Paul Johnson has used '/InvAction use broken_pistol 1516519084.00'.
    [HTML] http://forums.cloudsixteen.com/js/xenforo/xenforo.js?_v=073095e7:170: Uncaught TypeError: Property 'group' of object #<error> is not a function
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519085.
    Paul Johnson has used '/InvAction use broken_pistol 1516519085.00'.
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519086.
    Paul Johnson has used '/InvAction use broken_pistol 1516519086.00'.
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519087.
    Paul Johnson has used '/InvAction use broken_pistol 1516519087.00'.
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519088.
    Paul Johnson has used '/InvAction use broken_pistol 1516519088.00'.
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516519089.
    Paul Johnson has used '/InvAction use broken_pistol 1516519089.00'.
    
    Did ten pistols just in case.
     
  4. Nalo

    Nalo Clockwork Customer

    local ability = Clockwork.attributes:Fraction(player, ATB_SCAVENGING, 1, 1);

    Maybe ?
     
  5. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    Error Console:
    Code:
    Paul Johnson has gained a Broken Pistol 1516548281.
    You have given Paul Johnson a Broken Pistol.
    Paul Johnson has used '/CharGiveItem johnson broken'.
    [HTML] http://forums.cloudsixteen.com/js/xenforo/xenforo.js?_v=073095e7:170: Uncaught TypeError: Property 'group' of object #<error> is not a function
    You failed to repair the pistol!
    Paul Johnson has lost a Broken Pistol 1516548281.
    Paul Johnson has used '/InvAction use broken_pistol 1516548281.00'.
    
    Current state of the code:
    Code:
    -- Created by NoahtheBoah36 AKA Noah Engelmann
    -- Redistribution/use/modification is allowed provided credit is given.
    
    local ITEM = Clockwork.item:New();
    ITEM.name = "Broken Pistol";
    ITEM.model = "models/weapons/w_pistol.mdl";
    ITEM.weight = 0.5;
    ITEM.business = true;
    ITEM.batch = 1;
    ITEM.access = "@";
    ITEM.description = "[RED CONTRABAND] A broken handgun. Now who left this lying around?";
    ITEM.category = "Crafting";
    ITEM.useText = "Repair";
    
    -- When the item is dropped.
    function ITEM:OnDrop(player, position) end;
    
    -- When the item is used.
    function ITEM:OnUse(player, itemEntity)
        --local ability = Clockwork.attributes:Fraction(player, ATB_SCAVENGING, 1);
        local ability = Clockwork.attributes:Fraction(player, ATB_SCAVENGING, 1, 1);
        print("Ability:");
        print(ability);
        local difficulty = math.random(1, 25);
        print("Difficulty:");
        print(difficulty);
        if (ability >= difficulty) then
            Clockwork.player:Notify(player, "You successfully repaired the pistol!");
            player:GiveItem(Clockwork.item:CreateInstance("weapon_pistol"), true);
            Clockwork.attributes:Progress(player, ATB_SCAVENGING, difficulty);
            return;
        else
            Clockwork.player:Notify(player, "You failed to repair the pistol!");
            Clockwork.attributes:Progress(player, ATB_SCAVENGING, difficulty + ability);
            return;
        end;
    end;
    
    ITEM:Register();
    
    Still not working.
     
  6. duck

    duck Phant0m Legend

    You need to be looking at the server console, not client. When you do that, you will clearly see the issue.
     
    • Agree Agree x 1
  7. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    Well, the problem is that while looking at the server console nothing different popped up than what was in the client console, actually.

    However, I managed to fix the issue. I'm not sure exactly how it fixed it or what I did, but I suspect it had to do with the attributes maybe being measured in decimals rather than whole numbers.

    Code:
    -- Created by NoahtheBoah36 AKA Noah Engelmann
    -- Redistribution/use/modification is allowed provided credit is given.
    
    local ITEM = Clockwork.item:New();
    ITEM.name = "Broken Pistol";
    ITEM.model = "models/weapons/w_pistol.mdl";
    ITEM.weight = 0.5;
    ITEM.business = true;
    ITEM.batch = 1;
    ITEM.access = "@";
    ITEM.description = "[RED CONTRABAND] A broken handgun. Now who left this lying around?";
    ITEM.category = "Crafting";
    ITEM.useText = "Repair";
    
    -- When the item is dropped.
    function ITEM:OnDrop(player, position) end;
    
    -- When the item is used.
    function ITEM:OnUse(player, itemEntity)
        local ABILITY = Clockwork.attributes:Fraction(player, ATB_SCAVENGING, 1)*10;
        local CHALLENGE = math.random(1, 10);
        if (ABILITY > CHALLENGE) then
            Clockwork.player:Notify(player, "You successfully repaired the pistol!");
            player:GiveItem(Clockwork.item:CreateInstance("weapon_pistol"), true);
            Clockwork.attributes:Progress(player, ATB_SCAVENGING, CHALLENGE);
            return;
        else
            Clockwork.player:Notify(player, "You failed to repair the pistol!");
            Clockwork.attributes:Progress(player, ATB_SCAVENGING, CHALLENGE + ABILITY);
            return;
        end;
    end;
    
    ITEM:Register();
    
    All that being said, I've actually decided in the interim to give up development for my own servers, at least for the time being, and maybe development for others as well. Figured I'd post this to just keep the quality-control of the threads up. Anyway, I'll see you guys later, maybe.
     
  8. RJ

    RJ no pay Legend Clockwork Customer

    I do want to quickly note that the server console gives entirely different logging than the client console (there may be some similarities though), so I'm not sure if you were looking at the correct console or not. Think of it like this (loose) example: The server is an operating system such as Windows, so it'll log things like which drivers are loaded, which programs are running, how much CPU/RAM is being used, etc. The client is the person using the computer that's running Windows, so it'll log things like what the user clicks on, what the user types, which programs the user started, etc. (this example isn't to be taken literally btw, I don't think the computer logs quite so specifically as I laid out). Server and client are two very different aspects.
     
    • Informative Informative x 1

Previous Readers (Total: 0)