Jump to content

havenphillip

Members
  • Posts

    550
  • Joined

  • Last visited

Posts posted by havenphillip

  1. Yeah. It was freezing up on me, too. I have a fix. Just for fun I was working on it last night. It has to do with a line in the FPS_Grenade.lua script.

    Open the FPS_Grenade.lua script right next to the other script.

    Go down to about line 480 and look for "self.entity:Release()"

    Uncomment it or change it to "self.entity:Hide()"

    Then, just under that write:

               if self.entity:Hide() then
                    self.entity:Release()
                end

     

    Like this:

    release.thumb.png.1caf7cde8981163a0c75201e9e183621.png

  2. It's because the grenade weapon doesn't have a "clip" variable. One thing you could try is adding these in the Start() function of the Fps_GrenadeView.lua script. That will get you past that error:

        self.clipammo = 1
        self.clipsize = 1
        self.ammo = 1

    Basically the ammo script is trying to figure out what numbers to display. It's asking the pipebomb script "How much ammo do I display?" and the pipebomb script is like "I don't know what you're talking about. I've never heard of clip, or clipsize, or clipammo, etc." So you have to add the variables in the pipebomb script so it can tell the ammo.lua PostRender() what to display. I used "1" which is completely arbitrary. The next thing will be to figure out how to get the pipebomb to count down as you chuck grenades.

  3. Include a crawler.pfb in your game? Can't you just drag and drop the prefab into the screen? Not sure what you mean.

    But here's a basic ammo pickup script. Just add one of your ammo models to your scene and attach this script to it. Also you might need to add a collision shape to your ammo model.

     

    ammo_pickup.lua

  4. It's great, man. It works. The rules are correct for the quadrants. The rotation sets the correct directions when walking towards or away, etc. But the dot is a bit jumpy. I have four equal quadrants and when I stand on or near the Z line (for instance) relative to the crawler and spin in a circle, the dot doesn't rotate. It just goes up and down. Same when I stand on or near the X line. I think it's because the number for the X coordinate is basically zero when I'm on the Z line so it's completely flattened. And if I walk to one of the four corners of my map I get a nice circle on rotation because the X and Z are equidistant. So as I'm walking around and rotating and stuff the dot kind of jumps around. So what I need to figure out is how to keep that circular shape from collapsing into a line when I cross between quadrants.

    No video. Sorry. I don't know how to do that. I don't really have a game or anything. Just a crawler standing in the middle of a big square lol. By all means copy/paste the code if you want. You can see for yourself.

  5. Ok. I think I see that. You created the Vec2 drawCoords variable but left it empty, basically. That allowed you to make x and y flexible depending on whatever you might want to do. And then with the "or" statements (which I was unaware of) you can reduce it down to this since some of the lines are similar:

    Script.target = nil -- entity "Target"
    Script.dotSize = 5 -- int "Dot Size"

    function Script:Start()
        self.player = self.entity:GetParent()
        self.mapPos = Vec2(200, 200)
    end

    function Script:PostRender(context)
        local x = self.mapPos.x / 2
        local y = self.mapPos.y / 2
        local playerPos = self.player:GetPosition(true)
        local enemyPos = self.target:GetPosition(true)
        local playerYRotation = self.player:GetRotation(true).y
        local drawCoords = Vec2(0,0) --We will use this variable to store the calculated draw position

        context:SetBlendMode(1)
        context:SetColor(1, 1, 1, 1)
        context:DrawRect(x, y, self.dotSize, self.dotSize)
        context:SetColor(1, 0, 0, 1)

        if (playerYRotation <= 30 and playerYRotation >= -30) or
           (playerYRotation >= 150 and playerYRotation <= 180) or
           (playerYRotation <= -150 and playerYRotation >= -180 ) then -- facing forward or backward
                if (playerPos.x < enemyPos.x and playerPos.z < enemyPos.z) or
                   (playerPos.x > enemyPos.x and playerPos.z > enemyPos.z) then
                    drawCoords.x = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x))
                    drawCoords.y = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z))
                elseif (playerPos.x > enemyPos.x and playerPos.z < enemyPos.z) or
                       (playerPos.x < enemyPos.x and playerPos.z > enemyPos.z) then
                        drawCoords.x = x + (-Math:Cos(-playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(-playerYRotation) * (enemyPos.x - playerPos.x))
                        drawCoords.y = y + (Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) + Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z))
                end
        elseif (playerYRotation >= 30 and playerYRotation <= 149) or
               (playerYRotation <= -30 and playerYRotation >= -149) then -- facing right/left
                if (playerPos.x < enemyPos.x and playerPos.z < enemyPos.z) or
                   (playerPos.x > enemyPos.x and playerPos.z > enemyPos.z) then
                    drawCoords.y = x + (Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x))
                    drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (playerPos.z - enemyPos.z))
                elseif (playerPos.x > enemyPos.x and playerPos.z < enemyPos.z) or
                       (playerPos.x < enemyPos.x and playerPos.z > enemyPos.z) then
                        drawCoords.y = x + (-Math:Cos(playerYRotation) * (playerPos.x - enemyPos.x) - Math:Sin(playerYRotation) * (enemyPos.x - playerPos.x))
                        drawCoords.x = y + (-Math:Sin(playerYRotation) * (enemyPos.z - playerPos.z) - Math:Cos(playerYRotation) * (enemyPos.z - playerPos.z))
                end
        end

        context:DrawRect(drawCoords.x, drawCoords.y, self.dotSize, self.dotSize)

        context:SetBlendMode(0)
        context:SetColor(1, 1, 1, 1)
        context:DrawText(
            Math:Round(playerPos.x) .. "," .. Math:Round(playerPos.z) .. "/" .. Math:Round(enemyPos.x) .. "," .. Math:Round(enemyPos.z),
            20,
            20
        )
        context:DrawText(playerYRotation, 20, 50)
        context:SetBlendMode(1)
    end


     

  6. Cool. Thanks. I kind of get it. It boggles my mind a bit how you can just say something like "isNegative" and go about using it without defining it anywhere. My brain will slowly absorb this.

    This code works so far. I'm getting a slope on rotation rather than a  circular motion, and for some reason if I add an "if" statement I get that error again. It's a lua error or something so it doesn't highlight a line or anything. I'm totally in the dark about it.

    What I think I need is to adjust these for right 90 and left -90 degree turns, which requires an "if." Not sure if I should try to get the rotation working or fiddle with the turn problem first, or if solving one of those will also solve the other. Ideally, without having to add a ton of coordinate statements the enemy dot would move down from top to center as I walk facing towards it and continue down as I walk away from it, regardless of my player position and rotation relative to the enemy position. As it is, when I turn right and walk away from the target, the dot moves left, rather than down. Where should I focus my efforts from here?

    Script.target = nil -- entity "Target"
    Script.dotSize = 5 -- int "Dot Size"

    function Script:Start()
        self.player = self.entity:GetParent()
        self.mapPos = Vec2(300,300)
    end

    function GetDrawCoordinate(mapPos, playerpos, enemypos, isNegative, yRotation)
        local dir = 1;
        if isNegative then
            dir  = -1
        end

        local X = mapx+(dir * Math:Cos(dir * rot)*(player.x-enemy.x) - Math:Sin(dir * rot)*(enemy.x-player.x))
        local Y = mapy+(-Math:Sin(rot)*(enemy.z-player.z) + Math:Cos(rot)*(player.z-enemy.z))
        
        return Vec2(X,Y)
    end

    function Script:PostRender(context)
        mapx = self.mapPos.x/2
        mapy = self.mapPos.y/2     
        player = self.player:GetPosition(true)
        enemy = self.target:GetPosition(true)
        rot = self.player:GetRotation(true).y
        s = self.dotSize

        context:SetBlendMode(1)
        context:SetColor(1,1,1,1)
        context:DrawRect(mapx,mapy,s,s)

        context:SetColor(1,0,0,1)
        local drawCoord = GetDrawCoordinate(Vec2(mapx,mapy), player, enemy, true, rot)
        context:DrawRect(drawCoord.x, drawCoord.y, s, s)

        context:SetColor(1,1,1,1)
        context:DrawText(Math:Round(rot),20,50)
    end

  7. Ok I'm getting an error "...error in function 'new' [argument #2 is nil...no object expected" adding variables inside a created function is still kind of a new concept to me. You don't have a video on specifically this, do you?

    Here's how I have it set up. Where is 'new' argument 2?

    --Helper function that retrieves the right DrawCoords
    function GetDrawCoordinate(mapPos, playerPos, enemyPos, isNegative, yRotation)
        local dir = 1;
        if isNegative then
            dir  = -1
        end

        local x = mapPos.x+(dir * Math:Cos(dir * yRotation)*(playerPos.x-enemyPos.x) - Math:Sin(dir * yRotation)*(enemyPos.x-playerPos.x))
        local y = mapPos.y+(-Math:Sin(yRotation)*(enemyPos.z-playerPos.z) + Math:Cos(yRotation)*(playerPos.z-enemyPos.z))
        return Vec2(x,y)
    end

    function Script:PostRender(context)
        x = self.mapPos.x/2
        y = self.mapPos.y/2     
        playerPos = self.player:GetPosition(true)
        enemyPos = self.target:GetPosition(true)
        a = self.player:GetRotation(false).y
        s = self.dotSize

        context:SetBlendMode(1)
        context:SetColor(1,1,1,1)

        context:DrawRect(x,y,s,s)

        context:SetColor(1,0,0,1)

        --Format to:
        if a <= 30 and a >= - 30 then -- facing forward
          local drawCoord = GetDrawCoordinate(Vec2(X, Y), playerPos, enemyPos, true, yRotation)
          context:DrawRect(drawCoord.x, drawCoord.y, s, s)
        end

     

  8. I'm trying to make this rotating radar thing. I have this script but I get the feeling I'm doing way more than necessary and it's really jumpy. I'm not that good with shaders and still pretty limited in my understanding of coding in general. You can kind of see what I'm trying to do but what's the best way to go about this?

    Current script:
     

    Script.target = nil -- entity "Target"
    Script.dotSize = 5 -- int "Dot Size"

    function Script:Start()
        self.player = self.entity:GetParent()
        self.mapPos = Vec2(200,200)
    end

    function Script:PostRender(context)
        x = self.mapPos.x/2
        y = self.mapPos.y/2     
        pos = self.player:GetPosition(true)
        enemy = self.target:GetPosition(true)
        a = self.player:GetRotation(true).y
        s = self.dotSize

        context:SetBlendMode(1)
        context:SetColor(1,1,1,1)

        context:DrawRect(x,y,s,s)

        context:SetColor(1,0,0,1)
        
        if a <= 30 and a >= - 30 then -- facing forward
            if pos.x < enemy.x and pos.z < enemy.z then -- lower left
                local X = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local Y = y+(-Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z < enemy.z then -- lower right
                local X = x+(-Math:Cos(-a)*(pos.x-enemy.x) - Math:Sin(-a)*(enemy.x-pos.x))
                local Y = y+(Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x < enemy.x and pos.z > enemy.z then -- upper left
                local X = x+(-Math:Cos(-a)*(pos.x-enemy.x) - Math:Sin(-a)*(enemy.x-pos.x))
                local Y = y+(Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z > enemy.z then -- upper right
                local X = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local Y = y+(-Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            end

        elseif a >= 150 and a <= 180 then -- facing backward
            if pos.x < enemy.x and pos.z < enemy.z then -- lower left
                local X = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local Y = y+(-Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z < enemy.z then -- lower right
                local X = x+(-Math:Cos(-a)*(pos.x-enemy.x) - Math:Sin(-a)*(enemy.x-pos.x))
                local Y = y+(Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x < enemy.x and pos.z > enemy.z then -- upper left
                local X = x+(-Math:Cos(-a)*(pos.x-enemy.x) - Math:Sin(-a)*(enemy.x-pos.x))
                local Y = y+(Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z > enemy.z then -- upper right
                local X = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local Y = y+(-Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            end

        elseif a >= -180 and a <= -150 then -- facing backward
            if pos.x < enemy.x and pos.z < enemy.z then -- lower left
                local X = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local Y = y+(-Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z < enemy.z then -- lower right
                local X = x+(-Math:Cos(-a)*(pos.x-enemy.x) - Math:Sin(-a)*(enemy.x-pos.x))
                local Y = y+(Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x < enemy.x and pos.z > enemy.z then -- upper left
                local X = x+(-Math:Cos(-a)*(pos.x-enemy.x) - Math:Sin(-a)*(enemy.x-pos.x))
                local Y = y+(Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z > enemy.z then -- upper right
                local X = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local Y = y+(-Math:Sin(a)*(enemy.z-pos.z) + Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            end

        elseif a >= 30 and a <= 149 then -- facing right
            if pos.x < enemy.x and pos.z < enemy.z then -- lower left
                local Y = x+(Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local X = y+(-Math:Sin(a)*(enemy.z-pos.z) - Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z < enemy.z then -- lower right
                local Y = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local X = y+(-Math:Sin(a)*(enemy.z-pos.z) - Math:Cos(a)*(enemy.z-pos.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x < enemy.x and pos.z > enemy.z then -- upper left
                local Y = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local X = y+(-Math:Sin(a)*(enemy.z-pos.z) - Math:Cos(a)*(enemy.z-pos.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z > enemy.z then -- upper right
                local Y = x+(Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local X = y+(-Math:Sin(a)*(enemy.z-pos.z) - Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            end

        elseif a <= -30 and a >= -149 then -- facing left
            if pos.x < enemy.x and pos.z < enemy.z then -- lower left
                local Y = x+(Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local X = y+(-Math:Sin(a)*(enemy.z-pos.z) - Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z < enemy.z then -- lower right
                local Y = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local X = y+(-Math:Sin(a)*(enemy.z-pos.z) - Math:Cos(a)*(enemy.z-pos.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x < enemy.x and pos.z > enemy.z then -- upper left
                local Y = x+(-Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local X = y+(-Math:Sin(a)*(enemy.z-pos.z) - Math:Cos(a)*(enemy.z-pos.z))
                context:DrawRect(X,Y,s,s)
            elseif pos.x > enemy.x and pos.z > enemy.z then -- upper right
                local Y = x+(Math:Cos(a)*(pos.x-enemy.x) - Math:Sin(a)*(enemy.x-pos.x))
                local X = y+(-Math:Sin(a)*(enemy.z-pos.z) - Math:Cos(a)*(pos.z-enemy.z))
                context:DrawRect(X,Y,s,s)
            end
        end

        context:SetBlendMode(0)

        context:SetBlendMode(1)
        context:SetColor(1,1,1,1)
        context:DrawText(Math:Round(pos.x)..","..Math:Round(pos.z).."/"..Math:Round(enemy.x)..","..Math:Round(enemy.z), 20, 20)
        context:DrawText(a,20,50)
    end

  9. Ok. It's confusing. I have this at the bottom of my AI script. Do I need/can I make use of any returns anywhere? 

    function Script:UpdateWorld()
        if self.enabled == true then
            self.despawnTimer = self.despawnTimer + Time:GetSpeed()/100
            if self.despawnTimer > self.despawnTime then
                self.mode = "dead"
                self:DespawnItem()
            end
        end

        if self.mode == "dead" then
            self.removeBodyTimer = self.removeBodyTimer + (Time:GetSpeed()/100)
            if (self.removeBodyTimer > self.removeBodyTime) then
                self:DespawnItem()
            end
        end
    end

    function Script:DespawnItem()
        self.entity:Hide()
        self.entity:Release()
    end

  10. I have this enter/exit trigger from Aggror set up to hide my weapons when I walk on the trigger and show weapons when I walk off the trigger. My problem is when I stand perfectly still on the trigger the weapons show. I don't want that so how do I stop that from happening? I tried the player script's speed, moveSpeed, and playerMovement. You can see what I'm trying to do here:

    Script.enabled = true
    Script.entered = false
    Script.exited = false
    Script.collided = false

    function Script:Collision(entity, position, normal, speed)
        self.player = entity
        if self.enabled then
            self.collided = true
            if self.entered == false then
                self.entered = true
                self.exited = false
                entity.script.weapons[entity.script.currentweaponindex].entity:Hide()
                if entity:Stop() then -- right here what?
                      entity.script.weapons[entity.script.currentweaponindex].entity:Hide()
                end
            end
        end
    end

    function Script:UpdatePhysics()
        if self.enabled then
            if self.entered then
                if self.collided == false then
                    self.exited = true
                    self.entered = false
                    self.player.script.weapons[self.player.script.currentweaponindex].entity:Show()
                end
            end
            self.collided = false
        end
    end

     

×
×
  • Create New...