#recharging grenades

1 messages · Page 1 of 1 (latest)

spring charm
#
timer.Create("youraddon_grenadecheck", 20, 0, function()
    for k, v in pairs(player.GetAll()) do
        v:CheckForGrenade()
    end
end)

function PLAYER:CheckForGrenade()
    if not self:HasWeapon("weapon_frag") then
        self:Give("weapon_frag")
    end
end
#

or something

primal estuary
#

it gave an error

spring charm
#

well you'd wanna create the timer for ever player

primal estuary
#

attempt index ply nil value something

spring charm
#

well yeah

timid fulcrum
#

define player

spring charm
#

in this case

#

you want to target every player

#

well

#

actually

#

i wrote that wrong

#

try that

#

also, you need to make sure y ou define PLAYER as the player metatable

#
local PLAYER = FindMetaTable("Player")
#

somewhere before that other code

wicked hollow
#

wait what

#

sorry to butt in but

#

why would you do that

spring charm
#

its just a way of doing it

wicked hollow
#

but what part of the code is it used in

primal estuary
#

so when i save the script it gave an error about PLAYER

#

and after 20 seconds passed it gave an error about

#

CheckForGrenade

wicked hollow
#

you can copy the error messages from the console like text

primal estuary
#

[weapons] addons/weapons/lua/autorun/nadecharge.lua:7: attempt to index global 'PLAYER' (a nil value)

  1. unknown - addons/weapons/lua/autorun/nadecharge.lua:7

[weapons] addons/weapons/lua/autorun/nadecharge.lua:7: attempt to index global 'PLAYER' (a nil value)

  1. unknown - addons/weapons/lua/autorun/nadecharge.lua:7

[weapons] addons/weapons/lua/autorun/nadecharge.lua:3: attempt to call method 'CheckForGrenade' (a nil value)

  1. unknown - addons/weapons/lua/autorun/nadecharge.lua:3

Timer Failed! [youraddon_grenadecheck][@addons/weapons/lua/autorun/nadecharge.lua (line 1)]

[weapons] addons/weapons/lua/autorun/nadecharge.lua:3: attempt to call method 'CheckForGrenade' (a nil value)

  1. unknown - addons/weapons/lua/autorun/nadecharge.lua:3

Timer Failed! [youraddon_grenadecheck][@addons/weapons/lua/autorun/nadecharge.lua (line 1)]

#

how do you define a player meta thing

primal estuary
#

beacuse i put that

wicked hollow
#

oh i see now

#

did you put that before the timer code?

#

like at the top out of functions and stuff

primal estuary
#

after

wicked hollow
#

well its causing an error because code is read by the computer from top to bottom

#

and since you defined it after the timer it doesn't know what that is

spring charm
wicked hollow
#

yea my bad

primal estuary
#

ok it worked

#

or not?

wicked hollow
#

errors?

primal estuary
#

i thought it gave faster than 20 seconds

#

it turns out not the case it works like intended

#

so no problems

wicked hollow
#

oh ok

primal estuary
#

no wait definetly problems

#

i got grenade before timer could finish 20 seconds

wicked hollow
#

whats the rest of the code?

send it but make sure to put single quotes around it

primal estuary
#

i think i know the issue

#

timer starts before the player check

#

timer should start after the player gets into ammo count 0

wicked hollow
#

oh yeah, if u just create a timer outside of everything it'll start whenever the code loads

primal estuary
#

i think putting a check over ammo count shouldn't be that hard

wicked hollow
#

also I would switch to visual studio code instead of notepad++

primal estuary
#

i do not have that

wicked hollow
#

its free

timid fulcrum
#

for lua

wicked hollow
#

but it would help alot since the gmod extension

#

without it I would be using the wiki 3x as much

#

i like to know what arguments i need to use for a function, or if a function even exists really quick

primal estuary
#

ok so i will trying to mash this code with my old code

timid fulcrum
wicked hollow
#

im talking about visual studio code not visual studio if thats what your thinking about

primal estuary
#

i need to delete give weapon_frag and make it start the code at the bottom

primal estuary
#

how do i do that

wicked hollow
#

ok first u need to fix your if statements inside of getammocount

#

if ammocount 0 is wrong since there isnt any conditional, a conditional is <=, >=, ==, or !=. its a symbol that sits between two variables (in this case your ammocount and 0) that compares the two. so you would put ==

primal estuary
#

if ammocount ==0 then
function timer.create("youraddon_...

#

would this work?

wicked hollow
#

read last part of my msg

#

ye also not necessary but put a space after the == for better readability

primal estuary
#

is there too much end?

wicked hollow
#

ok your missing two more ends but its formatted kinda weird so lemme write it out for you

primal estuary
#

[weapons] addons/weapons/lua/autorun/nadecharge.lua:1: attempt to index global 'Player' (a function value)

  1. unknown - addons/weapons/lua/autorun/nadecharge.lua:1
wicked hollow
#

yeah holdon, could you send the code from if ammocount == 0 to right before function PLAYER:CheckForGrenade?

#

like as text not as screenshot

primal estuary
#

if ammocount == 0 then
timer.Create("youraddon_grenadecheck", 20, 0, function()
for k, v in pairs(player.GetAll()) do
v:CheckForGrenade()
end
end)

#

wait isn't there supposed to be function

#

before timer.create

wicked hollow
#

if ammocount == 0 then
timer.Create("youraddon_grenadecheck", 20, 0, function()
for k, v in pairs(player.GetAll()) do
v:CheckForGrenade()
end
end)
end

try adding this in, its nothing you really did wrong you just accidentally moved around some of the ends and it pasted in weird so it was hard to read

primal estuary
#

eof expected near end

#

what does that even mean

wicked hollow
#

eof means end of file, i was expecting that to happen since it was still kinda messy. functions and if statements need proper ends so whenever it kinda falls into the void for a lack of an end it causes that error.

add an end to the bottom right before function PLAYER:CheckForGrenade() and it should fix it

primal estuary
#

it did not

#

it just changed where the error is

#

from line 22 to 21

wicked hollow
#

can you send what it looks like right now?

primal estuary
timid fulcrum
#

thats alot of fuckin ends

primal estuary
#

yeah i said that too

wicked hollow
#

oh remove the two ends at the bottom

primal estuary
#

ok

#

[weapons] addons/weapons/lua/autorun/nadecharge.lua:20: 'end' expected (to close 'function' at line 5) near '<eof>'

wicked hollow
#

can you send a screenshot but with line numbers on the left?

primal estuary
wicked hollow
#

add one end below the highlighted one

primal estuary
#

[weapons] addons/weapons/lua/autorun/nadecharge.lua:1: attempt to index global 'Player' (a function value)

  1. unknown - addons/weapons/lua/autorun/nadecharge.lua:1
#

i hate coding

wicked hollow
#

make Player into PLAYER

#

at top func

#

sorry i can probably guess how you feel

primal estuary
wicked hollow
primal estuary
#

on both local and function?

wicked hollow
#

i mean just change Player into PLAYER on line 5

primal estuary
#

it gave the same exact error

wicked hollow
#

ok i understand now

#

gimme a sec

#

your gonna have to make a hook, which is basically hitchhiking onto a game event to run your own code

spring charm
wicked hollow
#

i just got timed out for some reason

#

ok so let me type that again

primal estuary
#

wontair

#

let's say

#

i have a running animation

#

and an ironsight animation

spring charm
primal estuary
#

and you can ironsight while running

#

but running animation overrides ironsight for some reason

#

how can i fix that

wicked hollow
#

uhh you would make either a running ironsight animation or modify the viewmodel pos instead of using an animation for the ironsights

#

but your grenade recharging is really easy to fix

#

i just took forever cause i had to type the code in discord lol

primal estuary
#

ironsight

#

running animation

#

and running while ironsight

wicked hollow
#

which one

primal estuary
wicked hollow
#

ok then you either need it to stop it from playing the running animation or have ironsights running anim

really tho let me help u fix that recharging grenade script it will only take like 5 mo mins

primal estuary
#

no problem

#

you need the .lua file?

wicked hollow
#

sure actually

primal estuary
wicked hollow
#

also i would get vscode now

primal estuary
wicked hollow
#

visual studio code

#

im scared to send a link cause it might time me out again

#

its the one with the blue icon

#

the reason you should get it is because it has autocompletion

primal estuary
#

is your profile picture from komegatze

wicked hollow
#

yea i think

primal estuary
wicked hollow
#

yea but its pretty weak compared to vscode with the gmod lua extension

#

trust me your gonna save alot of time

#

the extension name is GLua Enhanced btw

#

you find it in here when u get the program

#

im testing out my new code

#

ill be able to send it pretty soon

primal estuary
#

i think i did everything right

wicked hollow
#

yup!

#

i got ur code gimme a sec

#

i added alot of comments so i hope they might help

primal estuary
#

oh

#

i read it as commands

#

instead of comments

wicked hollow
#

oh and one extra thing: when you make the function PLAYER:CheckForGrenade it simply adds that function to all players you have access to, if that makes any sense. since it adds it to the table (see how PLAYER is declared above it) that all player entities use.

primal estuary
#

are you sure code works

#

i completed the gauntlent in 23 seconds and i am waiting here for the last 15 seconds and no greandes coming?

#

oh fuck nevermind

#

i'm dumb

timid fulcrum
wicked hollow
#

its almost ready i could probably release it today

primal estuary
#

wtf is an anti screamer

timid fulcrum
#

you will get 10000000000000 likes

wicked hollow
#

it overrides functions that draw textures to the screen to do nothing then adds the calls to a list that you can look over to see if any mods are trying to be mailcious

wicked hollow
#

ye that too

#

i have a table of the names of functions i can just add to

timid fulcrum
#

def obfuscate ur code

primal estuary
#

i actually never encountered a screamer addon

wicked hollow
primal estuary
#

one dumbass kept showing me his screamer addon

#

but other than that i never saw one in the workshop

wicked hollow
#

if you want 100% security you need to download the mod locally and rename the script files so that a screamer couldnt override them

primal estuary
#

is it possible to double the speed of a weapon through lua

wicked hollow
#

ill brb for 5 minutes but if you mean firerate and the weapon is lua based then yea

primal estuary
#

and how does firerate would even work on a grenade

#

Wontairr code me friends to play with

#

.d

timid fulcrum
#

its hardcoded u cant mod vanilla hl2 weapons unless lua data n stuff idk is made for it

primal estuary
#

when i press a button

#

it speeds things up for the weapon

#

and stuff

#

beacuse grenade takes exactly 1.3 seconds to draw and throw with my quick nade code that i stole

#

while punching somebody like you are in yakuza is frame 0

wicked hollow
spring charm
#

are u just using default grenade

#

you could maybe handle grenade throw urslef

primal estuary
#

anything lower than 1.3 it doesn't throw

#

i was thinking maybe speed up the draw and throw animation based on multipliers

#

so instead of 1.3

#

it should come out at 0.6

#

or something

#

but only when this code is used or something idk

primal estuary
#

@spring charm you there?

#

i need to ask something

primal estuary
#

UGH I HATE RETAR DED CODES

#

IT JUST DOESN'T MAKE SENSE

#

IT SHOULD WORK

#

NOT BUG OUT AT FUCKING FRAME 15 AND LOOP IT

spring charm
#

The computer only knows to do what you tell it to do

#

If it’s not working then you told it to do something wrong

primal estuary
#

i didn't wrote shitty lua

#

it's impossible

#

basically it didn't recognize act_vm_idle_lowered for every weapon

#

except the shotgun

#

and shotgun doesn't recognize idletolow

#

but every other weapon does

#

and i couldn't fix it with lua

#

so i fixed it with qc

#

anyways that isn't the issue

#

how do i disable a code based on an another code

#

beacuse ironsight and running animation clash

#

running animation takes priority

#

while ironsight needs to have priority

#

" if inIronsights then return end"
shouldn't something like this end the running animation or something?

#

after this didn't work i tried something like "if inIronsights then seqToPlay = vm:LookupSequence("idle01")"

#

but it did not work

spring charm
#

It’s fine to be a beginner but you’re so confident it’s funny

#

You’ll have to check with the specific gun mod

primal estuary
#

but this code uses inIronsights not me

spring charm
#

It’s hard to say whatever addons you might be running work

#

Fair enough haha

#

That’s not the right thing

#

Wait what do you wanna do again sry

primal estuary
#

ironsight should prioritize over running

#

but right now it's the other way around

#

scope animation

spring charm
#

I think maybe you can use StartCommand hook and check if player is scoping with weapon

#

But someone might tell you there’s a better way

primal estuary
#

when i do both

#

running animation

spring charm
#

Yeah stop the player from running using startcommand if they are scoping in with a weapon

#

StartCommand has a ucmd object and you can change inputs

#

GPT will honestly do something like that for you

#

I don’t recommend it if you want to actually learn though

primal estuary
spring charm
#

Theoretically as soon as you start scoping the StartCommand hook will instantly remove any sprint input

#

Maybe

#

I’ve not actually written any glua in a long time lol

primal estuary
#

it shouldn't remove the input it should override the animation

spring charm
#

The sprinting animation?

primal estuary
#

yes

#

ironsight should override running

spring charm
#

When you stop sprinting the animation stops bro

primal estuary
#

yeah but

spring charm
#

Oh you mean they should sprint and scope at the same time..?

primal estuary
#

yes

#

but sprint animation shouldn't override the damn scope

#

that just slows down the gameplay

#

y'know

#

also how do you make the scope work like it does in arccw or something

#

somebody was talking about fov and stuff in development but i didn't understand

primal estuary
#

code isn't exactly mine i stole it

#

wait could the lua name overriding it?

#

nah it's not it

primal estuary
#

i have like 7 more people to ask before publishing

#

and if they do not respond in a week i kinda don't care

wicked hollow
#

nah no need

primal estuary
#

@wicked hollow how do i put the code into this

wicked hollow
# primal estuary <@292759042999320586> how do i put the code into this

put ```lua
if not GetConVar("sv_rechargeable_grenades"):GetBool() then return end


at the top of the hook function.

you dont need local = for the createconvar its just a function that stores a convar in whatever source uses to store them. also u dont want the last FCVAR u put, and theres a hanging comma at the end (u just need help text at the end no min max)
primal estuary
#

like this

#

or one below the --

#

[functions] addons/functions/lua/autorun/server/sv_rechargeablegrenades.lua:12: attempt to index a nil value

  1. unknown - addons/functions/lua/autorun/server/sv_rechargeablegrenades.lua:12
wicked hollow
#

at the top of the hook*'s* function i mean

#

like right before if ammoid == 10

#

i meant to say the function that the hook is creating

#

also you forgot to do the stuff i said after the code block

#

also why are you still on notepad++ lol

primal estuary
wicked hollow
#

u got an extra comma next to FCVAR_ARCHIVE

#

also by help text i mean the description of the command

primal estuary
wicked hollow
#

normally u just put "Enables (whatever it enables)"

primal estuary
#

oh

#

so something more like this?

#

what do i do here after

wicked hollow
#

yeah thats good, also i have nooo idea how that works i haven't messed with that in a while

#

i would decompile a mod that has that setup already

primal estuary
#

didn't understand shit tho

#

also it doesn't work

#

when convar is set to 0 it still gives me the grenade

wicked hollow
#

restart the map if u haven't

#

sometimes the old hooks stay around

primal estuary
#

still giving me grenades

#

it's at 0 too

primal estuary
#

oh it needs a restart each time i enable this and disenable it

#

for some reason

primal estuary
#

@wicked hollow how could one turn a swep with base, let's say arccw into a swep with no base

primal estuary
#

@spring charm need help again

#

i can't get this to work it gives an error texture

#

now it's showing nothing at all

#

i hate vmt

#

or code

#

whichever is causing the porblem

wicked hollow
# primal estuary i can't get this to work it gives an error texture

you should always send all the info you have. example: how those textures are being used in code, what do the vmt files look like, etc. it saves time for the person trying to help, since even if long times pass, they don't have to ask you for the extra details in times when you may not be on.

primal estuary
#

i fixed it actually vtf was the problem

#

for some reason no mipmaps caused it to not show up

#

now i need to do

#

find how to make a pcf work

#

and overlay it on the screen

#

and turn arccw base weapon into a normal swep with no base

#

help me wink wink

primal estuary
primal estuary
wicked hollow
#

wdym like have it fade out on the edges

#

do that in the texture

#

unless there is a way idk

primal estuary
#

textures fades in and out

#

or something

wicked hollow
primal estuary
primal estuary
#

it instantly appears rn

#

it wasn't doing that when it was a png

wicked hollow
#

remove the multiplier on the frametime and see what happens

primal estuary
#

lua/includes/util.lua:304: attempt to perform arithmetic on local 'to' (a nil value)

  1. Lerp - lua/includes/util.lua:304
  2. v - addons/progressive low health overlays/lua/autorun/bloodscreenprogressive.lua:42
    3. unknown - lua/includes/modules/hook.lua:96 (x113)
wicked hollow
#

you gotta show code

#

also send it as text not screenshot

primal estuary
#

i don't know how to do the code text thingy

wicked hollow
#

note the symbol is the ~ without shift not '

primal estuary
#
local healthThresholds = {
    {threshold = 10, image = Material("vgui/damage/damage_overlay_red2bloom.vmt")},
    {threshold = 30, image = Material("vgui/damage/damage_overlay_redbloom.vmt")},
    {threshold = 40, image = Material("vgui/damage/damage_overlay_orangebloom.vmt")},
}

local currentAlpha = 0
local targetAlpha = 0
local fadeSpeed = 3
local selectedImage = nil
local previousImage = nil
local previousAlpha = 0

hook.Add("HUDPaint", "HealthBasedImageOverlay", function()
    local ply = LocalPlayer()

    if not IsValid(ply) then return end  -- Check if the player is valid

    local health = ply:Health()
    
    if not ply:Alive() then
        targetAlpha = 0
        selectedImage = nil
    else
        local newSelectedImage = nil
        for _, data in ipairs(healthThresholds) do
            if health <= data.threshold then
                newSelectedImage = data.image
                break
            end
        end

        if newSelectedImage ~= selectedImage then
            previousImage = selectedImage
            previousAlpha = currentAlpha
            selectedImage = newSelectedImage
        end

        targetAlpha = selectedImage and 255 or 0
    end

    currentAlpha = Lerp(FrameTime())
    previousAlpha = Lerp(FrameTime())

    if previousAlpha > 0 and previousImage then
        surface.SetDrawColor(255, 255, 255, previousAlpha)
        surface.SetMaterial(previousImage)
        surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
    end

    if currentAlpha > 0 and selectedImage then
        surface.SetDrawColor(255, 255, 255, currentAlpha)
        surface.SetMaterial(selectedImage)
        surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
    end
end)
wicked hollow
#

oh i said remove the multiplier for frame time not the whole function args

#

like remove the * fadespeed part

primal estuary
#

oh

wicked hollow
#

make sure to keep an eye on what arguments functions require

#

if u hover over lerp it should show it

#

otherwise check the wiki

primal estuary
#

ok code is fucking with me right now

#

it said

#

")" is expected near "fadespeed"

#

so i deleted the other args

#

except fadespeed

#

then it gave me an error again

#

saying the same exact thing

#
    currentAlpha = Lerp(FrameTime() fadeSpeed, currentAlpha, targetAlpha)
    previousAlpha = Lerp(FrameTime() fadeSpeed, previousAlpha)
#

[progressive low health overlays] addons/progressive low health overlays/lua/autorun/bloodscreenprogressive.lua:42: ')' expected near 'fadeSpeed'

[progressive low health overlays] addons/progressive low health overlays/lua/autorun/bloodscreenprogressive.lua:42: ')' expected near 'fadeSpeed'

#

then i deleted currentalpha and target alpha and previous alpha

#

then it gave the same thing

#

i wanna punch the code sometimes

wicked hollow
#

lol its not messing with you.

can you see what the issue is here?

 Lerp(FrameTime() fadeSpeed, currentAlpha, targetAlpha)
#

its for both lines using lerp

primal estuary
#

wontair i still don't understand code

wicked hollow
#

i get it but im just trying to reap some results

#

basically take a look at the first part before currentAlpha

#

its hard to explainn but

Lerp(FrameTime() fadeSpeed this doesnt work because the two variables (FrameTime and fadeSpeed) are just "floating" . as in there is nothing that connects them to eachother. thats why it gets all confused because it expected the lerp function to close with a ). you would have to put a sign like + or * to connect them back.

anyways i wanted u to get rid of the * fadeSpeed part and u only got rid of the * so thats why its causing errors. i think that maybe the fadespeed is making it lerp too fast? lerp is linear interpolation btw

primal estuary
#

with the same exact error but this time it's currentAlpha

wicked hollow
primal estuary
#

no

#

there is still targetalpha after that

wicked hollow
#

i mean after frametime

primal estuary
#

currentAlpha = Lerp(FrameTime() currentAlpha, targetAlpha)
previousAlpha = Lerp(FrameTime() previousAlpha, 0)

wicked hollow
#

yeah see my msg

#

all arguments have to be separated by commas

primal estuary
#

so i need a + or a *?

wicked hollow
#
#

see the top part

primal estuary
#

example shows lerpanimation

#

which we are using a vmt that has no animation

#

number lerp numbet t is just numbers

#

so we just give it numbers?

#

gah fuck this

#

do you know how to use a pcf

wicked hollow
#

no sorry

#

you should probably be doing simpler things right now to hone in some coding basics

#

its hard to resist doing cool stuff but you cant build a house without a foundation

#

keep the gmod wiki open btw while you work

primal estuary
#

sourcegame2sourcegame porting experience

#

everything is ready you just need to know how to do shit after that point

wicked hollow
#

pcf is a particle effect file

primal estuary
#

i just need to

#

put that particle

#

on the screen

#

when player takes damage