Force a player to use a specific weapon
15 replies



23.04.18 01:28:02 am
Hello guys, I need a lua which when the admin hit somebody with a special weapon he will force him to use knife only and the victim won't be able to use other arms only that specific weapon until he dies.
thank you for reading this.
thank you for reading this.
l
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
admin = 0 -- your usgn
specialweapon = 1 -- the weapon you want
knfonly = {}
for i = 1, game("sv_maxplayers") do knfonly[i] = 0 end
addhook("hit", "_hit")
addhook("walkover", "_walkover")
addhook("buy", "_buy")
function _hit(p, s, w)
if player(s, "usgn") == admin and w == specialweapon then
parse("strip "..p.." 0")
knfonly[p] = 1
end
end
function _walkover(p)
if knfonly[p] == 1 then return 1 end
end
function _buy(p)
if knfonly[p] == 1 then return 1 end
end
specialweapon = 1 -- the weapon you want
knfonly = {}
for i = 1, game("sv_maxplayers") do knfonly[i] = 0 end
addhook("hit", "_hit")
addhook("walkover", "_walkover")
addhook("buy", "_buy")
function _hit(p, s, w)
if player(s, "usgn") == admin and w == specialweapon then
parse("strip "..p.." 0")
knfonly[p] = 1
end
end
function _walkover(p)
if knfonly[p] == 1 then return 1 end
end
function _buy(p)
if knfonly[p] == 1 then return 1 end
end
@
Talented Doge:Thanks bro but i didn't mean that but when i hit the player his weapons will stay but he can't use them he will use only the special weapon
Edit : I think i should use the select hook but i don't know how i'm not a good scripter

Edit : I think i should use the select hook but i don't know how i'm not a good scripter
edited 1×, last 23.04.18 04:16:32 pm
l
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
admin = 0 -- your usgn
specialweapon = 1 -- the weapon you want
knfonly = {}
for i = 1, game("sv_maxplayers") do knfonly[i] = 0 end
addhook("hit", "_hit")
addhook("buy", "_buy")
addhook("select", "_select")
function _hit(p, s, w)
if player(s, "usgn") == admin and w == specialweapon then
knfonly[p] = 1
end
end
function _select(p)
if knfonly[p] == 1 then parse("setweapon "..p.." 50") end
end
function _buy(p)
if knfonly[p] == 1 then return 1 end
end
specialweapon = 1 -- the weapon you want
knfonly = {}
for i = 1, game("sv_maxplayers") do knfonly[i] = 0 end
addhook("hit", "_hit")
addhook("buy", "_buy")
addhook("select", "_select")
function _hit(p, s, w)
if player(s, "usgn") == admin and w == specialweapon then
knfonly[p] = 1
end
end
function _select(p)
if knfonly[p] == 1 then parse("setweapon "..p.." 50") end
end
function _buy(p)
if knfonly[p] == 1 then return 1 end
end

Because:
1. You didn't change the admin usgn
2. You didn't use usp.
1. You didn't change the admin usgn
2. You didn't use usp.
He meant that players still can swap their weapons using mouse or 1-9 slots.. I think that you have to strip all the weapons and save to array. And then at round start just equip them again.
Why not just attach sth like ms100 to setweapon along with "select". It's not exactly how it's supposed to be but it will reach the goal, no?
@
Gaiosyes that what i meant, thank you.
@
Rainoth: i already tried with always hook but it didn't work, i'll see if ms100 will do something.

@

l
Due to the ping the function will be delayed anyway. You'd see that you swiped and fired but after some time you set back to that knife. In fact you didn't fire on server so only 0/Server ping would be pretty acceptable. There is no other right way than do it like
Gaios said.

why "ms100" along with "select"? the latter alone will do the thing,right?
edited 3×, last 24.04.18 03:05:25 pm
Code:
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
33
34
35
36
37
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
33
34
35
36
37
admin = 131785 -- your usgn
specialweapon = 1 -- the weapon you want
knfonly = {}
playeweps = {}
for i = 1, game("sv_maxplayers") do knfonly[i] = 0 playeweps[i] = {} end
addhook("hit", "_hit")
addhook("buy", "_buy")
addhook("select", "_select")
addhook("spawn", "_spawn")
function _hit(p, s, w)
if player(s, "usgn") == admin and w == specialweapon then
playeweps[p] = playerweapons(p)
parse("strip "..p.." 0")
knfonly[p] = 1
return 1
end
end
function _spawn(p)
if knfonly[p] == 1 then
knfonly[p] = 0
for i = 1, #playeweps[p] do
parse("equip "..p.." "..playeweps[p][i])
end
end
end
function _select(p)
if knfonly[p] == 1 then parse("setweapon "..p.." 50") end
end
function _buy(p)
if knfonly[p] == 1 then return 1 end
end
specialweapon = 1 -- the weapon you want
knfonly = {}
playeweps = {}
for i = 1, game("sv_maxplayers") do knfonly[i] = 0 playeweps[i] = {} end
addhook("hit", "_hit")
addhook("buy", "_buy")
addhook("select", "_select")
addhook("spawn", "_spawn")
function _hit(p, s, w)
if player(s, "usgn") == admin and w == specialweapon then
playeweps[p] = playerweapons(p)
parse("strip "..p.." 0")
knfonly[p] = 1
return 1
end
end
function _spawn(p)
if knfonly[p] == 1 then
knfonly[p] = 0
for i = 1, #playeweps[p] do
parse("equip "..p.." "..playeweps[p][i])
end
end
end
function _select(p)
if knfonly[p] == 1 then parse("setweapon "..p.." 50") end
end
function _buy(p)
if knfonly[p] == 1 then return 1 end
end
And there is an interesting bug:
When I change the weapon back to knife and the player still gets to keep his primary weapon, the primary weapon will stay and functions almost identical to itself but:
1. It cannot reload
2. It cannot attack except at close range like a knife
Use a timer of 0 interval to parse the
setweapon command.
Also, your coding abbreviations are inconsistent:
pls fix

Also, your coding abbreviations are inconsistent:
specialweapon
playeweps
knfonly
pls fix
@
Talented Doge Thank you i'm a little bit close to the goal i have edited it to not strip the players weapons only force the player to select the special weapon and remove his damage.

l



