Forum

> > CS2D > Scripts > Add hat to class
Forums overviewCS2D overview Scripts overviewLog in to reply

English Add hat to class

27 replies
Page
To the start Previous 1 2 Next To the start

old Add hat to class

MixTape
User Off Offline

Quote
Hi guys. I dlike to add diffrent hat's to all . You know, mage have diffrent hat than warrior etc.
Im using a few scripts from this page. I trying add hat to class in this code. It's script to choose player class.

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
--------------------------------------------------
-- Player Classes Script by Unreal Software     --
-- 28.02.2009 - www.UnrealSoftware.de           --
-- Adds Player Classes to your server           --
--------------------------------------------------

if sample==nil then sample={} end
sample.classes={}

-----------------------
-- INITIAL SETUP     --
-----------------------
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
sample.classes.class=initArray(32)
function sample.classes.classmenu(id)
	menu(id,"Select your Class,Warrior|150HP 300A,Mage|100HP 100A,Assasin|80HP 100A|,Ogre|300HP Heavy Armor|Slow,Demon|150HP 100A,Ninja|50HP|Very fast,Orc|200HP 100A,Night elf|120HP 100A,Undead|200HP 200A)")	
end


-----------------------
-- TEAM -> CLASS     --
-----------------------
addhook("team","sample.classes.team")
function sample.classes.team(id,team)
	if (team>0) then
		sample.classes.classmenu(id)
	end
end


-----------------------
-- SERVERACTION      --
-----------------------
addhook("serveraction","sample.classes.serveraction")
function sample.classes.serveraction(id)
	sample.classes.classmenu(id)
end


-----------------------
-- CLASS SELECTION   --
-----------------------
addhook("menu","sample.classes.menu")
function sample.classes.menu(id,menu,sel)
	if (menu=="Select your Class") then
		if (sel>=0 and sel<=9) then
			sample.classes.class[id]=sel
			if (player(id,"health")>0) then
				parse("killplayer "..id)
			end
		end
	end
end


-----------------------
-- SPAWN             --
-----------------------
addhook("spawn","sample.classes.spawn")
function sample.classes.spawn(id)
	-- Warrior
	if (sample.classes.class[id]<=1) then
		parse ("setmaxhealth "..id.." 150")
		parse ("setarmor "..id.." 300")
		parse ("speedmod "..id.." 1")
		local headcrab = image("gfx/npc/headcrab.bmp<m>", 1, 0, 200+id)
		return "69,76,41";
	end
	-- Mage
	if (sample.classes.class[id]==2) then
		parse ("setmaxhealth "..id.." 100")
		parse ("setarmor "..id.." 100")
		parse ("speedmod "..id.." 3")
		return "86,76,69,53,75,77";
	end
	-- Assasin
	if (sample.classes.class[id]==3) then
		parse ("setmaxhealth "..id.." 80")
		parse ("setarmor "..id.." 100")
                parse ("speedmod "..id.." 5")
		return "69,52,53,60,77,76,72";
	end
	-- Ogre
	if (sample.classes.class[id]==4) then
		parse ("setmaxhealth "..id.." 300")
		parse ("setarmor "..id.." 100")
                parse ("speedmod "..id.." -2")
		return "81,60,59,49";
	end
	-- Demon
	if (sample.classes.class[id]==5) then
		parse ("setmaxhealth "..id.." 150")
		parse ("setarmor "..id.." 100")
		parse ("speedmod "..id.." 2")
		return "73,54,46";
	end
	-- Ninja
	if (sample.classes.class[id]==6) then
		parse ("setmaxhealth "..id.."50")
		parse ("setarmor "..id.." 0")
                parse ("speedmod "..id.." 7")
		return "69,52,52,53,51";
	end
	-- Orc
	if (sample.classes.class[id]==7) then
		parse ("setmaxhealth "..id.." 200")
		parse ("setarmor "..id.." 100")
                parse ("speedmod "..id.." 1")
		return "53,54,59,69";
	end
	-- Night Elf
	if (sample.classes.class[id]==8) then
		parse ("setmaxhealth "..id.." 120")
		parse ("setarmor "..id.." 100")
                parse ("speedmod "..id.." 3")
		return "35,89,53,";
	end
	-- Undead
	if (sample.classes.class[id]==9) then
		parse ("setmaxhealth "..id.." 75")
		parse ("setarmor "..id.." 200")
                parse ("speedmod "..id.." 10")
		return "88,85,78,77,52";
	end
end



-----------------------
-- NO BUYING         --
-----------------------
addhook("buy","sample.classes.buy")
function sample.classes.buy()
	return 1
end


-----------------------
-- NO COLLECTING     --
-----------------------
addhook("walkover","sample.classes.walkover")
function sample.classes.walkover(id,iid,type)
	if (type>=61 and type<=68) then
		return 0
	end
	return 1
end


-----------------------
-- NO DROPPING       --
-----------------------
addhook("drop","sample.classes.drop")
function sample.classes.drop()
	return 1
end


-----------------------
-- NO DEAD DROPPING --
-----------------------
addhook("die","sample.classes.die")
function sample.classes.die()
	return 1
end

Im sure, you see this code
1
local headcrab = image("gfx/npc/headcrab.bmp<m>", 1, 0, 200+id)
Yes, i try add it from other script but i cant.

PS: I'm new in LUA, i dont try programming in this language before cs2d. I dont have any support in my language so please help me and be patient

old Re: Add hat to class

Tier
BANNED Off Offline

Quote
Dude, please don't start scripting at hight level. Yes, it's good you learn from examples but you start too hard.

Here are some Lua tutorials. I found one by Starkkz.

old Re: Add hat to class

_Yank
User Off Offline

Quote
@user Tier: In my opinion that doesn't matter at all. I learned scripting by studying advanced scripts and trying to modify them. BTW, hat scripts aren't advanced at all, lol.

@user MixTape: Put this on the top of server lua (it is a patch I made that corrects some image bugs and stuff) http://unrealsoftware.de/forum_posts.php?post=392522&start=0#post392594.
Then, add this after the 20th line,
1
sample.classes.image=initArray(32)
This array will serve as placeholder to the player images (the hats).

Then change the 72nd line (now 73rd) to
1
sample.classes.image[id] = image("gfx/npc/headcrab.bmp<m>", 1, 0, 200+id)
That will deploy the image over the player. (See http://cs2d.com/help.php?luacat=all&luacmd=image#cmd)

And finally put this on the 68th line (now 69th ( ͡° ͜ʖ ͡°) ):
1
freeimage(sample.classes.image[id])
This will remove the player previous image (hat).

That's it. If it returns an error everytime a player spawns but stills working (player gets the hat), ignore it. And by the way, I recommend you to use the CS2D Lua documentation page, http://cs2d.com/help.php?luacat=all.
edited 1×, last 25.07.15 06:32:36 pm

old Re: Add hat to class

MixTape
User Off Offline

Quote
@Yank i dont know but it doesn't work. Hat is on my head before choose a class(when i dont have any class), when i choose class, this hat disappears (?). I have problem with 69 ( ͡° ͜ʖ ͡°) line, i must change this from
1
if (sample.classes.class[id]<=1) then
to
1
freeimage(sample.classes.image[id])
or add after it? I know it's only remove.
Btw. wihout this code
1
freeimage(sample.classes.image[id])

hat too disappears when i choose class.

Sorry for my problems or my a bit knowledge but i make it first time.

Its my code NOW:

Spoiler >


PS1: Are u sure i must add UPDATE code to server.lua not server.cfg? I dont know but i dont use before this file.
I dlike to show it u.
Spoiler >

old Re: Add hat to class

_Yank
User Off Offline

Quote
@user MixTape: That happens because the 69th line is checking wether the class value is 1 or lower (and by default, when you haven't a class, the class value is 0) and it assumes the player is using that class. To fix it change the 69th line to
1
if (sample.classes.class[id]==1) then
This will make it assume the player is using that class only if his class value is 1.

And yes the freeimage thingy is supposed to be placed after the 69th line. BTW, you add this to each class (line 78, etc).

About the image patch, yes your server.lua is correct you don't need to change anything.

old Re: Add hat to class

MixTape
User Off Offline

Quote
It still doesn't work, i dont have hat on Warrior when i choose this class.
Code of warrior:
1
2
3
4
5
6
7
if (sample.classes.class[id]==1) then
	    freeimage(sample.classes.image[id])
		parse ("setmaxhealth "..id.." 150")
		parse ("setarmor "..id.." 300")
		parse ("speedmod "..id.." 1")
		sample.classes.image[id] = image("gfx/npc/headcrab.bmp<m>", 1, 0, 200+id)
		return "69,76,41";

old Re: Add hat to class

_Yank
User Off Offline

Quote
You probably did something wrong because, here it works.
Here's my 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
--------------------------------------------------
-- Player Classes Script by Unreal Software     --
-- 28.02.2009 - www.UnrealSoftware.de           --
-- Adds Player Classes to your server           --
--------------------------------------------------

if sample==nil then sample={} end
sample.classes={}

-----------------------
-- INITIAL SETUP     --
-----------------------
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
sample.classes.image=initArray(32)
sample.classes.class=initArray(32)
function sample.classes.classmenu(id)
	menu(id,"Select your Class,Warrior|150HP 300A,Mage|100HP 100A,Assasin|80HP 100A|,Ogre|300HP Heavy Armor|Slow,Demon|150HP 100A,Ninja|50HP|Very fast,Orc|200HP 100A,Night elf|120HP 100A,Undead|200HP 200A)")     
end

-----------------------
-- TEAM -> CLASS     --
-----------------------
addhook("team","sample.classes.team")
function sample.classes.team(id,team)
	if (team>0) then
		sample.classes.classmenu(id)
	end
end

-----------------------
-- SERVERACTION      --
-----------------------
addhook("serveraction","sample.classes.serveraction")
function sample.classes.serveraction(id)
	sample.classes.classmenu(id)
end

-----------------------
-- CLASS SELECTION   --
-----------------------
addhook("menu","sample.classes.menu")
function sample.classes.menu(id,menu,sel)
	if (menu=="Select your Class") then
		if (sel>=0 and sel<=9) then
			sample.classes.class[id]=sel
			if (player(id,"health")>0) then
				parse("killplayer "..id)
			end
		end
	end
end

-----------------------
-- SPAWN             --
-----------------------
addhook("spawn","sample.classes.spawn")
function sample.classes.spawn(id)
	-- Warrior
	if (sample.classes.class[id]<=1) then
		freeimage(sample.classes.image[id])
		parse ("setmaxhealth "..id.." 150")
		parse ("setarmor "..id.." 300")
		parse ("speedmod "..id.." 1")
		sample.classes.image[id] = image("gfx/npc/headcrab.bmp<m>", 1, 0, 200+id)
	return "69,76,41";
	end
	-- Mage
	if (sample.classes.class[id]==2) then
		freeimage(sample.classes.image[id])
		parse ("setmaxhealth "..id.." 100")
		parse ("setarmor "..id.." 100")
		parse ("speedmod "..id.." 3")
		return "86,76,69,53,75,77";
	end
	-- Assasin
	if (sample.classes.class[id]==3) then
		freeimage(sample.classes.image[id])
		parse ("setmaxhealth "..id.." 80")
		parse ("setarmor "..id.." 100")
		parse ("speedmod "..id.." 5")
		return "69,52,53,60,77,76,72";
	end
	-- Ogre
	if (sample.classes.class[id]==4) then
		freeimage(sample.classes.image[id])
		parse ("setmaxhealth "..id.." 300")
		parse ("setarmor "..id.." 100")
		parse ("speedmod "..id.." -2")
		return "81,60,59,49";
	end
	-- Demon
	if (sample.classes.class[id]==5) then
			freeimage(sample.classes.image[id])
			parse ("setmaxhealth "..id.." 150")
			parse ("setarmor "..id.." 100")
			parse ("speedmod "..id.." 2")
			return "73,54,46";
	end
	-- Ninja
	if (sample.classes.class[id]==6) then
			freeimage(sample.classes.image[id])
			parse ("setmaxhealth "..id.."50")
			parse ("setarmor "..id.." 0")
			parse ("speedmod "..id.." 7")
			return "69,52,52,53,51";
	end
	-- Orc
	if (sample.classes.class[id]==7) then
		freeimage(sample.classes.image[id])
		parse ("setmaxhealth "..id.." 200")
		parse ("setarmor "..id.." 100")
		parse ("speedmod "..id.." 1")
		return "53,54,59,69";
	end
	-- Night Elf
	if (sample.classes.class[id]==8) then
		freeimage(sample.classes.image[id])
		parse ("setmaxhealth "..id.." 120")
		parse ("setarmor "..id.." 100")
		parse ("speedmod "..id.." 3")
		return "35,89,53,";
	end
	 -- Undead
	if (sample.classes.class[id]==9) then
		freeimage(sample.classes.image[id])
		parse ("setmaxhealth "..id.." 75")
		parse ("setarmor "..id.." 200")
		parse ("speedmod "..id.." 10")
		return "88,85,78,77,52";
	end
end

-----------------------
-- NO BUYING         --
-----------------------
addhook("buy","sample.classes.buy")
function sample.classes.buy()
	return 1
end

-----------------------
-- NO COLLECTING     --
-----------------------
addhook("walkover","sample.classes.walkover")
function sample.classes.walkover(id,iid,type)
	if (type>=61 and type<=68) then
		return 0
	end
	return 1
end


-----------------------
-- NO DROPPING       --
-----------------------
addhook("drop","sample.classes.drop")
function sample.classes.drop()
	return 1
end
     
-----------------------
-- NO DEAD DROPPING --
-----------------------
addhook("die","sample.classes.die")
function sample.classes.die()
	return 1
end

old Re: Add hat to class

MixTape
User Off Offline

Quote
Okay, so in my folder's is something wrong, cause your code isn't working too. I must reinstall CS2D, wait a second. I will edit this comment.

old Re: Add hat to class

MixTape
User Off Offline

Quote
I dont know guys, it doesn't work again, what i can do wrong? The files are in "autorun" it can be problem?

old Re: Add hat to class

_Yank
User Off Offline

Quote
You placed it on a .lua file inside the autorun ? It should be working... What error does it return ? Are you using any other scripts ? Are you using the code I provided on my last post ?

old Re: Add hat to class

_Yank
User Off Offline

Quote
Strange because here it works... Are you sure you have that image on your CS2D folder ? What class are you using to test (Because right now it is only supposed to work on Warriro class) ?

old Re: Add hat to class

MixTape
User Off Offline

Quote
I know, it's only on warrior class, i have this graphics (i check it 10x) i dont know what's wrong in my files, i make all this same like u.

This problem is in my files, i join to my LAN server from other computer and it doesn't working too.
Maybe i have wrong dedicated server exe? i dont know, please help me i stay in one place all day. I have no idea, tomorrow(today) i looking for a problem again. Good night my friends.

//EDIT: Okay, it's working but... Can be problem in server.cfg file in "sv_gamemode 0" => "sv_gamemode 1"? But i think, cause i change it and it's working, LOOL.

//EDIT2: where i can add folder with hat's (download content before connect to server), cause on other computer i dont see this other hats.
edited 4×, last 26.07.15 02:29:46 pm

old Re: Add hat to class

Rainoth
Moderator Off Offline

Quote
servertransfer.lst
is where you define each file that needs to be sent to people who join your server as long as those files are in scripts cause files in maps get sent automatically...
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview