Forum

> > CS2D > Scripts > Grenade Script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Grenade Script

4 replies
To the start Previous 1 Next To the start

old Grenade Script

Marcell
Super User Off Offline

Quote
Hi!

I am working on a "little" grenade script, don't mind that is it, you will see it once it is ready.

first, I found a couple of bugs, that I can't seems to resolve or at least having difficulties find out a way do do.

• The projectile seems not removed if it out of the screen?
• Sometimes it just does not work? (98% of the time works tho)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
addhook("projectile_impact", "custom_he")
function custom_he(id, w, x, y, mode, projectileid) 
    for _,id in pairs(player(0, "table")) do
        if w == 51 then -- The projectile is HE grenade
            he = image(grenades[1]['path_img'], x, y, 0)
           timer(grenades[1]['delay'], "removeGrenade")
            function removeGrenade () -- remove grenade img
                freeimage(he)
            end
            parse("freeprojectile " ..projectileid.. " " ..id) -- remove explosion
        end
    end
end


addhook("projectile_impact", "shrapnel")
function shrapnel(id, w, x, y, mode, projectileid)
    if w == 51 then -- The projectile is HE grenade
    timer(grenades[1]['delay'], "explodeGrenade")
    function explodeGrenade()
        for i = 2,10,2 do
            timer(20*i,"parse","effect \"smoke\" " .. x .. " " .. y .. " 100 80")
        end
        local he_sound = grenades[1]['sound']
        parse ("effect \"fire\" "..x.." "..y.." 25 5 0 0 0")
        parse ("shake "..id.. " 10")
        parse('sv_soundpos "'..grenades[1]['sound']..'"  '..x..' '..y)
        
        -- further damage scripts goes there...      
    end
else return false end
end

Another thing, I am wondering which would be a good way to cause the players nearby to get damage (including the src if close)

I was thinking maybe 2-3 tiles /2-3m/ from the core of the "explosion" would cause instant death, then the rest would get just some amount of damage.

yes, I know explosion can do that, but I would like to create some sort of custom damage with ranges and many more later.

before some smart guys comes, High Explosive grenades mostly causing deaths to 2-3 meters, depending on the type.

I apricate any help, even suggesting some better way to code.

old Re: Grenade Script

Cebra
User Off Offline

Quote
maybe something with certain probabilities.
the closer the player is the more probable is a higher damage. for example something like 1/r^2-relation

but i can understand, if u don't want probabilities in a shooter, but for non-ranked-context i think it is acceptable

old Re: Grenade Script

Bowlinghead
User Off Offline

Quote
Hey,
I dont see any bit of code that removes the grenade when out of screen.

Also I think you can solve things much more eloquent.
In line 3, you check for w == 51 - which is a parameter and will be the same for every player looped from line 3.
Therefore everytime someone does not throw a HE nade, this code will check w==51 like 32x times.
But still then, you dont even use the id.

Also you also can print yourself every piece of information and let the server run for a hour. Sounds like a big mess when someones leaves while timers are up, etc. There has to be a nil somewhere in your grenade[1][""] :3
More >
edited 1×, last 22.09.20 04:30:32 pm

old Re: Grenade Script

Marcell
Super User Off Offline

Quote
user Bowlinghead has written
Hey,
I dont see any bit of code that removes the grenade when out of screen.


Also you also can print yourself every piece of information and let the server run for a hour. Sounds like a big mess when someones leaves while timers are up, etc. There has to be a nil somewhere in your grenade[1][""] :3


What I am saying, I have no clue how to do that, because of the multiple resolutions and everything. This is why I prefer tile instead of pixels in cordinates.

Regarding rest, thanks, I will work on it!

old Re: Grenade Script

SQ
Moderator Off Offline

Quote
@user Marcell: Just to clarify.
Game resolution never changes. It's always fixed in 850x480.
Hud/UI system however is dynamic.

All you have to check if projectile and player (any player?) distance is above (x > 320, y > 240)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview