i wanted that just for my mod and if someone make that ill be have a credit for him.
Forum




Walking scripted npcs?
3 replies



i wanted that just for my mod and if someone make that ill be have a credit for him.
tell us what the walking is like.
EDIT: Sorry, will have it finished now now, just need to re-familiarise myself with the image functions.
EDIT2: It just hit 91 lines. I need a tad more time. 10 minutes max.
EDIT3: It's finaly done! YIPPIE!!
I think I'm going to upload this, it's pretty cool

But, btw, you might want to change the item_menu() function to make it so you get the names/prices from a difrerent source other than the actual CS2D game.
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
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
function WalkingNPC() 	local walking_npc = { 		"name", -- Name of NPC -- 		"items"={ -- Array of his/her items -- 			-- an item ID goes in each part -- 		}, 		"img"="" -- His/her body img path, added when NPC is init'ed -- 		"iid"=-1 -- NPC's body-img ID -- 		"cx", -- NPC's currect X -- 		"cy", -- NPC's current Y -- 		"ang", -- NPC's current angle -- 		"p1"={"x","y"}, -- Position 1 ( starts here ) -- 		"p2"={"x","y"}, -- Position 2 ( comes here ) -- 		"p3"={"x","y"}, -- Position 3 ( then here ) -- 		"p4"={"x","y"}, -- Position 4 ( and then here ) 						-- He goes back to P1 now -- 	} 	local function walking_npc:init(img_path,pp1,pp2,pp3,pp4) -- use to init the NPC ( start-up ) -- 		for i = 1,4 do 			loadstring("self:p"..i.." = pp"..i) 			self:img=img_path 		end 		addhook("say",self..":detect_hi") 		self:draw("p1") 	end 	local function walking_npc:draw(argu) -- self-calling draw function -- 		if argu=="p1" then 			if self:iid ~= -1 then 				while self:cx ~= self:p1.x and self:cy ~= self:p1.y do 					self:ang = math.atan2(self:cx - self:p1.x, self:cy - self:p1.y) 					self:cx = self:cx + math.cos(self:ang)*1.5 					self:cy = self:cy + math.sin(self:ang)*1.5 					imagepos(self:iid,self:cx,self:cy,self:ang) 				end 				self:draw("p2") 			else 				self:iid = image(self:img,self:p1.x,self:p1.y,1) 				self:draw("p2") 			end 		elseif argu=="p2" then 			if self:iid ~= -1 then 				while self:cx ~= self:p2.x and self:cy ~= self:p2.y do 					self:ang = math.atan2(self:cx - self:p2.x, self:cy - self:p2.y) 					self:cx = self:cx + math.cos(self:ang)*1.5 					self:cy = self:cy + math.sin(self:ang)*1.5 					imagepos(self:iid,self:cx,self:cy,self:ang) 				end 				self:draw("p3") 			end 		elseif argu=="p3" then 			if self:iid ~= -1 then 				while self:cx ~= self:p3.x and self:cy ~= self:p3.y do 					self:ang = math.atan2(self:cx - self:p3.x, self:cy - self:p3.y) 					self:cx = self:cx + math.cos(self:ang)*1.5 					self:cy = self:cy + math.sin(self:ang)*1.5 					imagepos(self:iid,self:cx,self:cy,self:ang) 				end 			end 			self:draw("p4") 		elseif argu=="p4" then 			if self:iid ~= -1 then 				while self:cx ~= self:p4.x and self:cy ~= self:p4.y do 					self:ang = math.atan2(self:cx - self:p4.x, self:cy - self:p4.y) 					self:cx = self:cx + math.cos(self:ang)*1.5 					self:cy = self:cy + math.sin(self:ang)*1.5 					imagepos(self:iid,self:cx,self:cy,self:ang) 				end 				self:draw("p1") 			end 		end 	end 	local function walking_npc:distance(id) 		local a = math.sqrt(self:cx - player(id,"x") + self:cy - player(id,"y")) 		return a 	end 	local function walking_npc:item_menu() 		local a = self:name.."," 		for i=0,#self:items do 			a = a..itemtype(i,"name").."|"..itemtype(i,"price").."," 		end 	end 	local function walking_npc:detect_hi(id,txt) 		if txt == "hi" or txt=="hello" or txt=="hai" and self:distance(id) < 90 then 			menu(id,self:item_menu()) 			msg2(id,"©121121121Hi! Wanna buy something? All good prices!") 		end		 	end 	return walking_npc end -- THIS IS HOW YOU MAKE AN NPC!!! -- my_walking_npc = WalkingNPC() my_walking_npc:init("gfx/my_mod_gfx/npc01.png",{"x"=103,"y"=103},{"x"=103,"y"=192},{"x"=192,"y"=192},{"x"=192,"y"=103})
edited 2×, last 30.03.11 02:42:01 pm



