Forum

> > CS2D > Scripts > Creating npc
Forums overviewCS2D overview Scripts overviewLog in to reply

English Creating npc

6 replies
To the start Previous 1 Next To the start

old Creating npc

deividas270
User Off Offline

Quote
Hello, its my first thread and i want to ask you how to create new npc? For example, creating a dog npc that moves and attacks? And how to paint images? And what lua scripting tutorial could you rekomend for me?

old Re: Creating npc

EngiN33R
Moderator Off Offline

Quote
1. Creating custom NPCs is difficult and requires skills. I'm not sure, but I think there are some NPC scripts in the file archive.
2.
1
imagecolor(imageid,red,green,blue)
3. I'd recommend you to read TKD's tutorial as well as just study the Lua user manual - it has plenty of examples of how to use different Lua features.

old Npc Script

xSkyLordx
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
npc={}
npc[1]={name="Robert",x=27,y=27,msg="Can you help me?",rot=120,img=1}

addhook("second","spawnimg")
function spawnimg(id)
     for a=1,#npc do
          npc[a].px=npc[a].x*32+16
          npc[a].py=npc[a].y*32+16
          npc[a].sprite=image("gfx/npc"..npc[a].img..".png",npc[a].px,npc[a].py,1)
     end
end

addhook("say","wordsay")
function wordsay(id,t)
     for a=1,#npc do
          if (player(id,"tilex")>=npc[a].x-1 and player(id,"tilex")<=npc[a].x+1 and player(id,"tiley")>=npc[a].y-1 and player(id,"tiley")<=npc[a].y+1) then
               if t=="hi" or t=="hello" then
                    msg2(id,""..npc[a].name..":"..npc[a].msg.."")
               end
          end
     end
end

say hi front of NPCs after NPCs answer you

old Re: Creating npc

Infinite Rain
Reviewer Off Offline

Quote
user xSkyLordx has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
npc={}
npc[1]={name="Robert",x=27,y=27,msg="Can you help me?",rot=120,img=1}

addhook("second","spawnimg")
function spawnimg(id)
     for a=1,#npc do
          npc[a].px=npc[a].x*32+16
          npc[a].py=npc[a].y*32+16
          npc[a].sprite=image("gfx/npc"..npc[a].img..".png",npc[a].px,npc[a].py,1)
     end
end

addhook("say","wordsay")
function wordsay(id,t)
     for a=1,#npc do
          if (player(id,"tilex")>=npc[a].x-1 and player(id,"tilex")<=npc[a].x+1 and player(id,"tiley")>=npc[a].y-1 and player(id,"tiley")<=npc[a].y+1) then
               if t=="hi" or t=="hello" then
                    msg2(id,""..npc[a].name..":"..npc[a].msg.."")
               end
          end
     end
end

say hi front of NPCs after NPCs answer you

*FACEPALM*
I think he meant NPC as mobs

old Re: Creating npc

4Vendetta
User Off Offline

Quote
Today when I was playing I've saw one server [mobs test] and I've played there was a lot of monster whos follow you and attack you ...
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview