Why this classes script don't work as intended?
2 replies



08.12.18 12:20:25 am
Hello. I have this problem with this script. I wanted to create a script that will random every player's class every round, but i encountered a problem. Every a player spawns, all player HP changes to the currently maxhp class the randomizer chosen. Here's the code :
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
38
39
40
41
42
43
44
45
46
47
48
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
38
39
40
41
42
43
44
45
46
47
48
function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
leader=0
nemesis=0
randomizer=initArray(32)
addhook("spawn","randomclass")
function randomclass(id)
leader=0
nemesis=0
for id=1,32,1 do
randomizer[id]=math.random(5) -- 0=leader | 1=fighter | 2=builder | 3=scavenger | 4=recon | 5=medic
if (randomizer[id]==1) then
parse ("setmaxhealth "..id.." 200")
--parse ("setarmor "..id.." 81")
parse ("speedmod "..id.." -1")
return "5,85,81";
end
if (randomizer[id]==2) then
parse ("setmaxhealth "..id.." 150")
--parse ("setarmor "..id.." 80")
parse ("speedmod "..id.." 1")
return "2,74,80";
end
if (randomizer[id]==3) then -- scavenger
parse ("setmaxhealth "..id.." 150")
--parse ("setarmor "..id.." 80")
parse ("speedmod "..id.." 1")
return "1,78,56,80";
end
if (randomizer[id]==4) then
parse ("setmaxhealth "..id.." 100")
--parse ("setarmor "..id.." 79")
parse ("speedmod "..id.." 5")
return "3,79";
end
if (randomizer[id]==5) then
parse ("setmaxhealth "..id.." 750")
--parse ("setarmor "..id.." 82")
parse ("speedmod "..id.." 1")
return "3,82";
end
end
end
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
leader=0
nemesis=0
randomizer=initArray(32)
addhook("spawn","randomclass")
function randomclass(id)
leader=0
nemesis=0
for id=1,32,1 do
randomizer[id]=math.random(5) -- 0=leader | 1=fighter | 2=builder | 3=scavenger | 4=recon | 5=medic
if (randomizer[id]==1) then
parse ("setmaxhealth "..id.." 200")
--parse ("setarmor "..id.." 81")
parse ("speedmod "..id.." -1")
return "5,85,81";
end
if (randomizer[id]==2) then
parse ("setmaxhealth "..id.." 150")
--parse ("setarmor "..id.." 80")
parse ("speedmod "..id.." 1")
return "2,74,80";
end
if (randomizer[id]==3) then -- scavenger
parse ("setmaxhealth "..id.." 150")
--parse ("setarmor "..id.." 80")
parse ("speedmod "..id.." 1")
return "1,78,56,80";
end
if (randomizer[id]==4) then
parse ("setmaxhealth "..id.." 100")
--parse ("setarmor "..id.." 79")
parse ("speedmod "..id.." 5")
return "3,79";
end
if (randomizer[id]==5) then
parse ("setmaxhealth "..id.." 750")
--parse ("setarmor "..id.." 82")
parse ("speedmod "..id.." 1")
return "3,82";
end
end
end
Nothing here.
Because if you want to set a class for a player ONCE per round, you don't need to randomize it on every respawn of this player
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
leader=0
nemesis=0
randomizer=initArray(32)
maxClassNumber = 5 -- 0=leader | 1=fighter | 2=builder | 3=scavenger | 4=recon | 5=medic
addhook("startround", "newrandomclasses")
function newrandomclasses()
for i = 1, 32 do
randomizer[i] = math.random(maxClassNumber)
end
end
addhook("spawn","randomclass")
function randomclass(id)
leader=0
nemesis=0
for id=1,32,1 do
if (randomizer[id]==1) then
parse ("setmaxhealth "..id.." 200")
--parse ("setarmor "..id.." 81")
parse ("speedmod "..id.." -1")
return "5,85,81";
end
if (randomizer[id]==2) then
parse ("setmaxhealth "..id.." 150")
--parse ("setarmor "..id.." 80")
parse ("speedmod "..id.." 1")
return "2,74,80";
end
if (randomizer[id]==3) then -- scavenger
parse ("setmaxhealth "..id.." 150")
--parse ("setarmor "..id.." 80")
parse ("speedmod "..id.." 1")
return "1,78,56,80";
end
if (randomizer[id]==4) then
parse ("setmaxhealth "..id.." 100")
--parse ("setarmor "..id.." 79")
parse ("speedmod "..id.." 5")
return "3,79";
end
if (randomizer[id]==5) then
parse ("setmaxhealth "..id.." 750")
--parse ("setarmor "..id.." 82")
parse ("speedmod "..id.." 1")
return "3,82";
end
end
end
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
leader=0
nemesis=0
randomizer=initArray(32)
maxClassNumber = 5 -- 0=leader | 1=fighter | 2=builder | 3=scavenger | 4=recon | 5=medic
addhook("startround", "newrandomclasses")
function newrandomclasses()
for i = 1, 32 do
randomizer[i] = math.random(maxClassNumber)
end
end
addhook("spawn","randomclass")
function randomclass(id)
leader=0
nemesis=0
for id=1,32,1 do
if (randomizer[id]==1) then
parse ("setmaxhealth "..id.." 200")
--parse ("setarmor "..id.." 81")
parse ("speedmod "..id.." -1")
return "5,85,81";
end
if (randomizer[id]==2) then
parse ("setmaxhealth "..id.." 150")
--parse ("setarmor "..id.." 80")
parse ("speedmod "..id.." 1")
return "2,74,80";
end
if (randomizer[id]==3) then -- scavenger
parse ("setmaxhealth "..id.." 150")
--parse ("setarmor "..id.." 80")
parse ("speedmod "..id.." 1")
return "1,78,56,80";
end
if (randomizer[id]==4) then
parse ("setmaxhealth "..id.." 100")
--parse ("setarmor "..id.." 79")
parse ("speedmod "..id.." 5")
return "3,79";
end
if (randomizer[id]==5) then
parse ("setmaxhealth "..id.." 750")
--parse ("setarmor "..id.." 82")
parse ("speedmod "..id.." 1")
return "3,82";
end
end
end
https://youtu.be/OlX8havmldo |
【東方】Bad Apple!! 【影絵】 in CS2D | Propaganda, Werbung für Waren (Reklame), Lehren und Ideen, besonders auf dem Gebiete der Politik, um Anhänger zu werben; z.B. Wahlpropaganda durch Versammlungen, Rundfunkreden, Plakate und Flugblätter


when you use the command setmaxhealth() - the player’s current health is set to the value you specify
if you want to make the maximum amount of health, but make the current amount of health to others use this command: sethealth()
also, you have an inaccuracy in the code
the spawn hook is triggered for each player, I mean: if your server have 5 players, this hook will call 5 times: for player 1, for player 2, for player 3, for player 4 and for player 5
my english is bad but i think you understand
so, your code Your code will be more correct if you write this:
also, you can't do maxhealth more 250, 0 < max health <= 250 in an explicit form, but you can do a trick and reduce all the damage to the class by N, that is, implicitly increase its health, I mean: dmg = dmg/5 => health = health * 5
if you want to make the maximum amount of health, but make the current amount of health to others use this command: sethealth()
Code:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
--[[
set max health of player in 200, but set current health in 100
]]
...
if randomizer[id]==1 then
parse("setmaxhealth "..tostring(id).." 200")
parse("sethealth "..tostring(id).." 100")
...
set max health of player in 200, but set current health in 100
]]
...
if randomizer[id]==1 then
parse("setmaxhealth "..tostring(id).." 200")
parse("sethealth "..tostring(id).." 100")
...
also, you have an inaccuracy in the code
the spawn hook is triggered for each player, I mean: if your server have 5 players, this hook will call 5 times: for player 1, for player 2, for player 3, for player 4 and for player 5
my english is bad but i think you understand
so, your code Your code will be more correct if you write this:
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
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
function randomclass(id)
leader=0
nemesis=0
randomizer[id]=math.random(5) -- 0=leader | 1=fighter | 2=builder | 3=scavenger | 4=recon | 5=medic
if (randomizer[id]==1) then
parse ("setmaxhealth "..tostring(id).." 200")
parse ("speedmod "..id.." -1")
return "5,85,81";
elseif (randomizer[id]==2) then
parse ("setmaxhealth "..tostring(id).." 150")
parse ("speedmod "..tostring(id).." 1")
return "2,74,80";
elseif (randomizer[id]==3) then -- scavenger
parse ("setmaxhealth "..tostring(id).." 150")
parse ("speedmod "..tostring(id).." 1")
return "1,78,56,80";
elseif (randomizer[id]==4) then
parse ("setmaxhealth "..tostring(id).." 100")
parse ("speedmod "..tostring(id).." 5")
return "3,79";
elseif (randomizer[id]==5) then
parse ("setmaxhealth "..tostring(id).." 750")
parse ("speedmod "..tostring(id).." 1")
return "3,82";
end
parse("sethealth "..tostring(id).." 100")
end
leader=0
nemesis=0
randomizer[id]=math.random(5) -- 0=leader | 1=fighter | 2=builder | 3=scavenger | 4=recon | 5=medic
if (randomizer[id]==1) then
parse ("setmaxhealth "..tostring(id).." 200")
parse ("speedmod "..id.." -1")
return "5,85,81";
elseif (randomizer[id]==2) then
parse ("setmaxhealth "..tostring(id).." 150")
parse ("speedmod "..tostring(id).." 1")
return "2,74,80";
elseif (randomizer[id]==3) then -- scavenger
parse ("setmaxhealth "..tostring(id).." 150")
parse ("speedmod "..tostring(id).." 1")
return "1,78,56,80";
elseif (randomizer[id]==4) then
parse ("setmaxhealth "..tostring(id).." 100")
parse ("speedmod "..tostring(id).." 5")
return "3,79";
elseif (randomizer[id]==5) then
parse ("setmaxhealth "..tostring(id).." 750")
parse ("speedmod "..tostring(id).." 1")
return "3,82";
end
parse("sethealth "..tostring(id).." 100")
end
also, you can't do maxhealth more 250, 0 < max health <= 250 in an explicit form, but you can do a trick and reduce all the damage to the class by N, that is, implicitly increase its health, I mean: dmg = dmg/5 => health = health * 5
edited 3×, last 08.12.18 10:26:00 am



