Why my scripts not working?



  • soooo... The things happen everytime I want to make a TargetHUD (show information about target on screen), when nothing was rendered on screen.
    The script:

    var scriptName = "TargetHUD";
    var scriptVersion = 1.0;
    var scriptAuthor = "Asutoboki-kun";
    
    var Potion = Java.type("net.minecraft.potion.Potion");
    var entity;
    var target;
    var Color = Java.type("java.awt.Color");
    var GL11=Java.type("org.lwjgl.opengl.GL11");
    var ScaledResolution = Java.type("net.minecraft.client.gui.ScaledResolution");
    
    function SuperHeroFX() {
        var width = value.createInteger("X", 0, 0, 500);
        var height = value.createInteger("Y", 0, 0, 500);
        var red = value.createInteger("Red", 0, 0, 255);
        var green = value.createInteger("Green", 160, 0, 255);
        var blue = value.createInteger("Blue", 255, 0, 255);
        var toNotRender = value.createInteger("DistanceNotRender", 15, 5, 20);
        this.getName = function() {
            return "ATargetHUD"
        }
        this.getDescription = function() {
            return "A Simplistic, Modern TargetHUD"
        }
        this.getCategory = function() {
            return "YandereDev"
        }
        this.onAttack = function(event) {
            var entity = event.getTargetEntity();
            target = entity
        }
        this.onRender2D = function() {
            drawRect(offsetWidth, offsetHeight, inf1Width, resizedHeight, 0xC0000000);
            drawStringWithMcFontCentered(target.getName() + " (" + targetPing + ")", centered, height.get() + 30, colorGet);
            drawStringWithMcFontCentered(information1, centered, height.get() + 40, colorGet);
            drawStringWithMcFontCentered(information2, centered, height.get() + 50, colorGet);
            drawStringWithMcFontCentered(targetChoose, centered, height.get() + 60, colorGet)
        }
        this.onEnable = function() {
            var entity = null
            var target = null
        };
        this.onDisable = function() {
    
        };
        this.onUpdate = function() {
            var colorGet = new Color(red.get(), green.get(), blue.get()).getRGB();
            var offsetWidth = (width.get() + mcWidth) / 1.5
            var offsetHeight = (height.get() + mcHeight) / 1.5
            var inf1Width = mc.fontRendererObj.getStringWidth(information1);
            var resizedHeight = (height.get() + (70 * size.get()) + mcHeight) / 1.5
            var centered = (offsetWidth + inf1Width) / 2;
            if (mc.thePlayer.ticksExisted % 2 == 0) {
                if (target.getDistanceToEntity(mc.thePlayer).toFixed(0) > toNotRender.get()) {
                    targetDistance = toNotRender.get() + "+";
                } else {
                    targetDistance = target.getDistanceToEntity(mc.thePlayer).toFixed(0);
                }
                if (mc.thePlayer.getHealth().toFixed(2) < target.getHealth().toFixed(2)) {
                    targetChoose = "Losing"
                } else {
                    targetChoose = "Winning"
                }
                var information1 = "Health: " + target.getHealth().toFixed(2) + "/" + target.getMaxHealth().toFixed(2) + " | Regeneration: " + target.isPotionActive(Potion.regeneration);
                var information2 = "Distance: " + targetDistance + " | Yaw: " + target.getRotationYawHead();
                var playerInfo = mc.getNetHandler().getPlayerInfo(target.getUniqueID());
                var targetPing = playerInfo == null ? "0 ms": playerInfo.getResponseTime() + " ms"
            }
        }
        this.addValues = function(values) {
            values.add(width);
            values.add(height);
            values.add(red);
            values.add(green);
            values.add(blue);
            values.add(toNotRender)
        }
    }
    
    var SuperHeroFX = new SuperHeroFX();
    
    function onEnable() {
        moduleManager.registerModule(SuperHeroFX)
    };
    
    function onDisable() {
        moduleManager.unregisterModule(SuperHeroFX)
    };
    
    function onLoad() {}
    
    function drawRect(paramXStart, paramYStart, paramXEnd, paramYEnd, color) {
        var alpha = (color >> 24 & 0xFF) / 255;
        var red = (color >> 16 & 0xFF) / 255;
        var green = (color >> 8 & 0xFF) / 255;
        var blue = (color & 0xFF) / 255;
    
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
    
        GL11.glPushMatrix();
        GL11.glColor4f(red, green, blue, alpha);
        GL11.glBegin(GL11.GL_TRIANGLE_FAN);
        GL11.glVertex2d(paramXEnd, paramYStart);
        GL11.glVertex2d(paramXStart, paramYStart);
        GL11.glVertex2d(paramXStart, paramYEnd);
        GL11.glVertex2d(paramXEnd, paramYEnd);
    
        GL11.glEnd();
        GL11.glPopMatrix();
    
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_LINE_SMOOTH);
    
        GL11.glColor4f(1, 1, 1, 1);
    };
    
    function getScaledWidth() {
        var scaledWidth = new ScaledResolution(mc).getScaledWidth();
    
        return scaledWidth;
    }
    
    function getScaledHeight() {
        var scaledHeight = new ScaledResolution(mc).getScaledHeight();
    
        return scaledHeight;
    }
    
    function drawStringWithMcFontCentered(content, positionX, positionY, GetColor) {
        mc.fontRendererObj.drawStringWithShadow(content, positionX - (mc.fontRendererObj.getStringWidth(content) / 2), positionY, GetColor)
    }
    


  • {var s = "hello";}
    Chat.print(s);
    


  • @Aftery hi
    btw can you help me I took almost 2 days to fix but not successful



  • Can anyone help me please?



  • pls help me im gonna die


  • Banned

    no // 8chars



  • can I die?



  • iam bad in render 😉



  • You must define a variable before you can use it



  • It's about the scope of a variable. In ur method onRender2D you referenced offsetWidth variable. However you only declared offsetWidth in method onUpdate. You will need to declared it outside of that method. (The scope thing is somewhat related to lifetime of variables)

    Btw it would be helpful if you can provide those errors/execptions. You could look into .minecraft/logs/fml-client-latest.log for script exceptions. And u might see somthing like ReferenceError: "a" is not defined. They are pretty ez to find like this. (This example irrelevant to your script tho, just to show that it is ez to find).a99ee6c6-4dae-4428-9e06-99fb9b3fd06f-image.png .



  • @commandblock2 thanks so much for telling me that!


Log in to reply