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!

Other Help me fix my broken code.

Discussion in 'Development' started by NoahtheBoah36™, Jan 10, 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 = "Trap Test";
    ITEM.model = "models/maxib123/chessboard.mdl";
    ITEM.weight = 0.1;
    ITEM.business = false;
    ITEM.description = "DO NOT USE THIS ITEM.";
    ITEM.category = "Junk";
    --ITEM.spawnValue = 10;
    --ITEM.spawnType = "junk";
    ITEM.useText = "Scrap";
    ITEM.batch = 1;
    
    
    -- When the item is dropped.
    function ITEM:OnDrop(player, position) end;
    
    -- When the item is used.
    function ITEM:OnUse(player, itemEntity)
        local explode = ents.Create( "env_explosion" ) -- creates the explosion
        explode:SetPos( eyetrace.HitPos ) -- this creates the explosion through your self.Owner:GetEyeTrace, which is why I put eyetrace in front
        explode:SetOwner( self.Owner ) -- this sets you as the person who made the explosion
        explode:Spawn() --this actually spawns the explosion
        explode:SetKeyValue( "iMagnitude", "220" ) -- the magnitude
        explode:Fire( "Explode", 0, 0 )
        explode:EmitSound( "weapon_AWP.Single", 400, 400 ) -- the sound for the explosion, and how far away it can be heard
    end;
    
    ITEM:Register();
    
    That's the above code of the item that isn't working. As you can see it's a test item but still, I need to get it to work before I can start applying it to other items. The purpose of the item is to explode the player when they use the item. The eventual application of this is to have certain items that are trap items, which look a lot like actual items, sometimes only being distinguishable when you use the examine command.

    When I use the item, an error appears. I'm not sure if it's the item but its' appearance in the console appears to coincide with the usage (or, rather, attempted usage) of the item.
    Code:
    [HTML] http://forums.cloudsixteen.com/js/xenforo/xenforo.js?_v=073095e7:170: Uncaught TypeError: Property 'group' of object #<error> is not a function
    
    Beyond the above, the only things to note really is that when I attempt to use the item, the item remains in my inventory and doesn't appear to do anything.

    Edit: And yes I asked on Discord for some help but the people online at the time didn't know what to do so I figured I'd widen the net and ask on the forums.
     
  2. WestCoastKillers

    WestCoastKillers all links to the manifesto Clockwork Customer

    Two things. Eyetrace isn't defined at all so "eyetrace.Hitpos" doesn't mean anything in this context, and neither does "self.Owner"
    Code:
    -- When the item is used.
    function ITEM:OnUse(player, itemEntity)
        local eyetrace = player:GetEyeTrace() -- define "eyetrace" as where the player is looking.
        local explode = ents.Create( "env_explosion" )
        explode:SetPos( eyetrace.HitPos )
        explode:SetOwner( player ) -- "self.Owner" refers to the owner of an entity that explodes, not the person using the item. to get the user of the item use "player"
        explode:Spawn()
        explode:SetKeyValue( "iMagnitude", "220" )
        explode:Fire( "Explode", 0, 0 )
        explode:EmitSound( "weapon_AWP.Single", 400, 400 )
    end;
    
    This should work.
     
  3. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    Alright. Now, really quickly, let's say that I was just copy pasting this from a Gmod tutorial, what do I do if I want the explosion to occur where the player is, not where the player is looking?
     
  4. WestCoastKillers

    WestCoastKillers all links to the manifesto Clockwork Customer

    You would use player:GetPos() instead of player:GetEyeTrace().HitPos
     
  5. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    Alrighty, thanks!

    Edit: Applied the fix, didn't work.

    2nd Edit: Instead of exploding it just says in console that I gained and then lost the item if I use it while it's on the ground. When I use it in my inventory it simply gives the below error in console.

    Code:
    [HTML] http://forums.cloudsixteen.com/js/xenforo/xenforo.js?_v=073095e7:170: Uncaught TypeError: Property 'group' of object #<error> is not a function
    
    THIRD FREAKING EDIT: OKAY SO Y'ALL DIDN'T NOTICE THIS BUT I WAS MISSING THE FUCKING SEMICOLONS AT THE END OF MY LINES FML WE ARE SHIT CODERS! I PUT IN THE SEMICOLONS RESTARTED THE SERVER AND IT WORKED!

    Now for some actual footage of my reaction:

    View: https://www.youtube.com/watch?v=CS9EKKc0uVc
     
    • Good Coder Good Coder x 1
    Last edited: Jan 10, 2018

Previous Readers (Total: 0)