Files

> > CS2D > Lua Scripts > Better Knockback
Files overviewCS2D overviewLua Scripts overview

English Better Knockback >

6 comments603 b, 112 Downloads

old Better Knockback

BcY
Reviewer Off Offline

• Better and optimized Knockback script for your server.

You can easily add more weapons and related knockback values:
1
2
3
4
5
6
local items = {
--Check for weapon ids = https://www.cs2d.com/weapons.php
	[10] = { knockback = 20 },
	[30] = { knockback = 15 },
	[32] = { knockback = 15 }
}
√ You can edit it freely.
√ You can claim it yours.
√ You can share it wherever you want.
edited 1×, last 03.03.24 12:13:07 pm
Approved by Starkkz

Download Download

603 b, 112 Downloads

Comments

6 comments
To the start Previous 1 Next To the start

Log in!

You need to log in to be able to write comments!Log in

old

WatPz
User Off Offline

Good script OwO

@user DC: simply, the local initialization can ease the time when Lua needs the find the global var in the _G. If there are frequent calls, it may be helpful, otherside it's sh*t
I like it!

old

Ranu
User Off Offline

What @user BcY: and @user Gaios: have said are not entirely true.

@Gaios has written
The boost can achieve a 30% improvement and is invoked through a hit hook, potentially calling the functions quite frequently within a single frame.
Total BS, made up and wrong data, and hit hook would NEVER be called every frame unless probably all the 32 players in the game shoot at once and that would only be for a few frames then the cycle would break due to difference in latency!

@user DC: No, it is a total waste of time especially in a script like this, it has no effect but making things look more complicated. However, Calling CS2D API through Lua in cs2d is quite not as fast it should be, so localizing the "parse", and "player" would be useful only if you have a function being called every frame with them inside of it, and that's super uncommon in CS2D, as far as I remember the lowest you can get with always hook is every 50 ms, so there is no case where you'll need it for the game.

Some Extra Info (IMPORTANT) >

Tl;dr Localizing doesn't really improve anything ×
edited 5×, last 23.01.24 09:54:09 pm

old

acm
User Off Offline

Wow, this is really very readable.
I like it!

old

Gaios
Reviewer On Online

@user DC: Well, this optimization isn't a big deal, so why not go for it? The boost can achieve a 30% improvement and is invoked through a hit hook, potentially calling the functions quite frequently within a single frame.
I like it!

old

BcY
Reviewer Off Offline

@user DC: Yes, here is the reference: lua.org/gems/sample.pdf

In this scenario it doesn't affect much but if considering to make complicated lua scripts, localising should be a must.

old

DC
Admin Off Offline

1
2
3
4
5
6
local parse = parse
local math.atan2 = math.atan2
local math.cos = math.cos
local math.sin = math.sin
local math.floor = math.floor
local player = player
Out of curiosity: Is this an optimization to make things faster by making them local? Did you benchmark this? Does it really have a noticable effect?
edited 1×, last 04.01.24 08:55:48 pm
To the start Previous 1 Next To the start