Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Scripts/Questions/Help

6,770 replies
Page
To the start Previous 1 2177 178 179338 339 Next To the start

old Sound & Access to entities on a map

webnull
User Off Offline

Quote
Hi im new to LUA scripting.

Im writing now Stargate network in LUA and it will works like on this video: http://www.youtube.com/watch?v=IKTy7qxXoX8

But i have some problems, because i dont know something.

1. How to play a sound only in short range on map with LUA?
2. How to access sprite entity on a map with LUA? - I want change its "Image File" to make animation
3. How to "sleep" script for some seconds/mili seconds?

I want to be Stargate mod avaible for maps without editing a source map ( just make configuration files for all maps that will use Stargate mod )

I finished activating, support for infinity count of Stargates, teleporting, killing when going throught other side.

My code is about 200 lines...

Thanks, WebNuLL

old Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Quote
1. Im completly new in LUA, i dont have idea how to use your function with sv_sound2
2. You have any image documentation?
3. To stop script for some miliseconds to do timed animation

-- WebNuLL

old Re: Lua Scripts/Questions/Help

siuL
User Off Offline

Quote
ok forgot ct god it dont worked but forget it but could (read pag 177) you at least make me terrorist have like infinite bullets like if you throw a he
and it explode it come agains to you and
with weapons when bullets 100/200 (example)
and you shoot 1 time it continues 100 lol
could you make it ? ? ?
please
edited 1×, last 21.03.10 03:07:24 am

old Re: Lua Scripts/Questions/Help

0ito
User Off Offline

Quote
how to put a menu shopping for zombie mod and use normal money for buy?

items to zombies:
infection bomb(gut bomb)
zombie rage (15 speed)
gas grenade
antidote

old Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Quote
Can i edit entities on a map?

I found this function, but i think it cant edit entities:
- entity(tileX,tileY,"value")     Return a value of an entity:
                    exists, typename, type, name,
                    trigger, state, int0, int1, int2,
                    int3, int4, int5, int6, int7,
                    int8, int9, str0, str1, str2,
                    str3, str4, str5, str6, str7,
                    str8, str9
                    (int0-9 and str0-9 are used
                    for entity settings and are
                    different for each entity type)

And how can i replace player skins and weapon skins/sounds?

Or how to make new weapon.

-- WebNuLL

old Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

Quote
YOu can't add a new weapon. Only edit one in lua.
In Lua you can place a image over a certain player.
And i think you can't edit entities on a map.

old Re: Lua Scripts/Questions/Help

YellowBanana
BANNED Off Offline

Quote
0ito has written
how to put a menu shopping for zombie mod and use normal money for buy?

items to zombies:
infection bomb(gut bomb)
zombie rage (15 speed)
gas grenade
antidote



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
items = {
			{title = "Infection bomb",price = 4000},
			{title ="Zombie rage",price =2500},
			{title ="Gas grenade",price =1300},
			{title ="Antidote",price = 900}
		}

function createMenu(header, matrix)
	local menuString = header;
	menuString = menuString..", "
	for key, value in ipairs(matrix) do
		menuString = menuString..value.title.." | "..tostring(value.price).. ","
	end
	return menuString
end


addhook("serveraction","my_serveraction")
function my_serveraction(id,action)
	if(action == 1) then
		menu(id,createMenu("Zombie Items",items))
	end
end

addhook("menu","my_menu")
function my_menu(id,title,button)
	if(button == 0) then
		return
	end

	if(title == "Zombie Items") then
		if(player(id,"money") > items[button].price) then
			parse("setmoney "..id.." "..(player(id,"money") - items[button].price))
			if(button==1) then
				parse("equip "..id.." "..86)
			elseif(button==2) then
				parse("speedmod "..id.." "..15)
			elseif(button==3) then
				parse("equip "..id.." "..72)
			elseif(button==4) then
				msg2(id,"antidote???")
			end
		end
	end
end

old Re: Lua Scripts/Questions/Help

0ito
User Off Offline

Quote
YellowBanana has written
0ito has written
how to put a menu shopping for zombie mod and use normal money for buy?

items to zombies:
infection bomb(gut bomb)
zombie rage (15 speed)
gas grenade
antidote



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
items = {
			{title = "Infection bomb",price = 4000},
			{title ="Zombie rage",price =2500},
			{title ="Gas grenade",price =1300},
			{title ="Antidote",price = 900}
		}

function createMenu(header, matrix)
	local menuString = header;
	menuString = menuString..", "
	for key, value in ipairs(matrix) do
		menuString = menuString..value.title.." | "..tostring(value.price).. ","
	end
	return menuString
end


addhook("serveraction","my_serveraction")
function my_serveraction(id,action)
	if(action == 1) then
		menu(id,createMenu("Zombie Items",items))
	end
end

addhook("menu","my_menu")
function my_menu(id,title,button)
	if(button == 0) then
		return
	end

	if(title == "Zombie Items") then
		if(player(id,"money") > items[button].price) then
			parse("setmoney "..id.." "..(player(id,"money") - items[button].price))
			if(button==1) then
				parse("equip "..id.." "..86)
			elseif(button==2) then
				parse("speedmod "..id.." "..15)
			elseif(button==3) then
				parse("equip "..id.." "..72)
			elseif(button==4) then
				msg2(id,"antidote???")
			end
		end
	end
end


LUA does not work this way and did not work the menu:


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
-------------------------------------
-- Zombie Plague Mod               --
-- Made by Oitø                    --
-------------------------------------
if lua==nil then lua={} end
lua.zm={}


----------------------------
-- Zombies                --
----------------------------
addhook("spawn","lua.zm.za")
function lua.zm.za(id)
if player(id,"team")==1 then

-- Zombie Health (250)
parse ("setmaxhealth "..id.." 250")

-- setmaxhealth "..id.." [Health] �©This text is health specify. 

-- Zombie Speed (6)
parse ("speedmod "..id.." 6")

-- speedmod "..id.." [Speed] �©This text is speed specify.

-- Zombie Equip (Gut Bomb)
parse("equip "..id.." 86")

-- equip "..id.." [Weapons ID] �©This text is weapon specify.
-- Weapon ID list
-- sys/lua/weaponID.txt

end
end

----------------------------
-- Survivors              --
----------------------------
addhook("spawn","lua.zm.sr")
function lua.zm.sr(id)
if player(id,"team")==2 then

-- Survivor Health (110)
parse ("setmaxhealth "..id.." 110")

-- setmaxhealth "..id.." [Health] �©This text is health specify. 

-- Survivor Speed (3)
parse ("speedmod "..id.." 3")

-- speedmod "..id.." [Speed] �©This text is speed specify.

-- Survivor Equip (Kevlar+Helm)
parse("equip "..id.." 58")

-- Survivor Equip (HE)
parse("equip "..id.." 51")

-- Survivor Equip (Flare)
parse("equip "..id.." 54")

-- equip "..id.." [Weapons ID] �©This text is weapon specify.

end
end

-----------------------------
-- Killed Zombie Voice     --
-----------------------------
addhook("kill","lua.zm.kills")
function lua.zm.kills(killer,victim,weapon)
if player(killer,"team")==1 then

-- Sound File (zp_infect4)
parse("sv_sound \"zombieplague/zp_infect4.wav\"")

-- zombieplague/zp_infect4.wav �©This text is sound specify.

end
end

items = { 
               {title = "Infection bomb",price = 1500}, 
               {title ="Zombie rage",price = 1500}, 
               {title ="Gas grenade",price = 1700}, 
               {title ="Antidote",price = 9000} 
          } 

function createMenu(header, matrix) 
     local menuString = header; 
     menuString = menuString..", " 
     for key, value in ipairs(matrix) do 
          menuString = menuString..value.title.." | "..tostring(value.price).. "," 
     end 
     return menuString 
end 


addhook("serveraction","my_serveraction") 
function my_serveraction(id,action) 
     if(action == 1) then 
          menu(id,createMenu("Zombie Items",items)) 
     end 
end 

addhook("menu","my_menu") 
function my_menu(id,title,button) 
     if(button == 0) then 
          return 
     end 

     if(title == "Zombie Items") then 
          if(player(id,"money") > items[b].price) then 
               parse("setmoney "..id.." "..(player(id,"money") - items[b].price)) 
               if(button==1) then 
                    parse("equip "..id.." "..86) 
               elseif(button==2) then 
                    parse("speedmod "..id.." "..15) 
               elseif(button==3) then 
                    parse("equip "..id.." "..72) 
               elseif(button==4) then 
                    msg2(id,"antidote???") 
               end 
          end 
     end 
end

old Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Quote
Quote
YOu can't add a new weapon. Only edit one in lua.
In Lua you can place a image over a certain player.
And i think you can't edit entities on a map.


I cant find anything in manual.

How can i edit weapon in LUA, how can i edit it damage, image and sound?

How can i edit player look in LUA?

-- WebNuLL

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Using images.
Read info.txt and the examples included in CS2D and you should kinda understand more or less what we are talking about.

old Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

Quote
webnull has written
Quote
YOu can't add a new weapon. Only edit one in lua.
In Lua you can place a image over a certain player.
And i think you can't edit entities on a map.


I cant find anything in manual.

How can i edit weapon in LUA, how can i edit it damage, image and sound?

How can i edit player look in LUA?

-- WebNuLL

With editing i ment that you can make that there is a explosion when (for example) a snowballs hits the wall or player.
The weapondamage can be changed with mp_wpndmg <NAMEOFWEAPON> <DAMAGE>

A special effect you can make with one of Blazz' Script.
Like this:
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
-- Projectiles Stuff Example --
-- Lua Scripting Tutorial Example
-- Not Finshed --

obj = {x = {}, y = {}, rot = {}, img = {}, id = {}}

addhook("always","obj_update")
addhook("attack","obj_add")

function obj_remove(id)
     local k, v
     if obj.img[id] then freeimage(obj.img[id]) end
     for k, v in pairs(obj) do table.remove(obj[k], id) end
end

function obj_add(p)
     	if(player(p,"weapontype")==32) then
	local x , y, rot , id = player(p,"x"), player(p,"y"), player(p,"rot")
     id = image("gfx/sprites/flare2.bmp",x,y,1)
     imageblend(id, 1)
     table.insert(obj.img, id)
     table.insert(obj.x, x)
     table.insert(obj.y, y)
     table.insert(obj.id, p)
     table.insert(obj.rot, rot)
	return 1
end
end

function obj_update()
     local del, id, n = {}
     for id, n in pairs(obj.img) do
          obj.x[id] = obj.x[id] + math.cos(math.rad(obj.rot[id] - 90)) * 10
          obj.y[id] = obj.y[id] + math.sin(math.rad(obj.rot[id] - 90)) * 10
          imagepos(n, obj.x[id], obj.y[id], obj.rot[id])
          if tile( math.ceil(obj.x[id] / 32) - 1, math.ceil(obj.y[id] / 32) - 1, "wall") then
               parse("explosion "..obj.x[id].." "..obj.y[id].." 50 250 "..obj.id[id])
               table.insert(del, id)
          end
     end
     for id, n in ipairs(del) do obj_remove(n) end
end
This makes a cool effect when you shoot with the M4A1.

Then take a look at one of DC's sample scripts.
glowingplayers.lua has written
--------------------------------------------------
-- Glowing Players Script by Unreal Software --
-- 08.11.2009 - www.UnrealSoftware.de --
--------------------------------------------------

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

--------------------------------------
-- GLOW --
--------------------------------------

-- Glow Function
function sample.glowing.makeallglow()
     for i=1,32,1 do
          id=image("gfx/sprites/flare1.bmp",0,0,100+i)     -- Create image @ Player
          imagecolor(id,255,0,0)                              -- Make image yellow
          imageblend(id,1)                                        -- Make image glow
          imagealpha(id,1)                                        -- Decrease Glow Strength
     end
end

-- Make Glow instantly after starting server
sample.glowing.makeallglow()

-- Make Glow after roundstart (because images are deleted on roundstart!)
addhook("startround","sample.glowing.startround")
function sample.glowing.startround()
     sample.glowing.makeallglow()
end

And in Future tell the forum what you want with more details.
(sorry for my english)
~Pata~

old Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Quote
I just want to replace weapon model, the weapon image, not any effect.

But its not important.

The important thing is for me to make sound whih player will hear only on selected distance, example 5 meters from my Stargates.

Stargates have many sounds, when opening etc. and i cant play these sounds on whole map...

-- WebNuLL

old Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Quote
Not yet, but i will place it with image() on a map.

To include Stargate on a map there will be to do:
1. Create lua file with same name as the map name
2. Add dofile("sys/lua/stargate-system.lua")
3. Create coordinates, configurate Stargates

I will try to put Stargates on a map without editing it.

This is my animation for CS2D, i spent 2 hours making it...

http://img443.imageshack.us/img443/91/stargatedialing2.gif

At now my configuration file looks:

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
-- first stargate
stargate[0]={'dhd','horizon','status'}
stargate[0]['dhd']={0,0} -- initialize dhd array for two dhds
stargate[0]['dhd'][0]={13,7,1,1}
stargate[0]['horizon']={0,0}
stargate[0]['horizon'][0]={10,6,2,'tile-1',0, '338.47510375977', '227.50535827637'}
stargate[0]['horizon'][1]={11,6,2,'tile-2',0, '623.693664', '228.96551'}
stargate[0]['status']={0,0,2,4}
stargate[0]['elements']={'kawoosh-off','close-off'} -- animations 
stargate[0]['elements']={'kawoosh','close'} -- animations 
stargate[0]['elements']['kawoosh']={'x', 'y', 'image'}
stargate[0]['elements']['kawoosh']['x']='8'
stargate[0]['elements']['kawoosh']['y']='9'
stargate[0]['elements']['kawoosh']['image']='webnull/stargate-dialing-2.gif'

-- second stargate
stargate[1]={'dhd','horizon','status'} -- initialize array
stargate[1]['dhd']={0,0} -- initialize dhd array for two dhds
stargate[1]['dhd'][0]={22,7,1,0} -- second stargate -- this is a stargate ( DHD )
stargate[1]['horizon']={0,0}
stargate[1]['horizon'][0]={19,6,2,'tile-1',1, '626.164', '233.39'}
stargate[1]['horizon'][1]={20,6,2,'tile-2',1, '660.15856933594', '229.96551513672'}
stargate[1]['status']={0,0,3,5}
stargate[1]['elements']={'kawoosh','close'} -- animations 
stargate[1]['elements']['kawoosh']={'x', 'y', 'image'}
stargate[1]['elements']['kawoosh']['x']='8'
stargate[1]['elements']['kawoosh']['y']='9'
stargate[1]['elements']['kawoosh']['image']='webnull/stargate-dialing-2.gif'

To place "kawoosh" effect i added, but i dont know if it works ( i didnt test it ):

1
stargate[id]['elements']['kawoosh']['id']=image(stargate[id]['elements']['kawoosh']['image'],stargate[id]['elements']['kawoosh']['x'],stargate[id]['elements']['kawoosh']['y'],101);

-- WebNuLL

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
You can use:
1
table.index
Instead of
1
table['index']
This makes code more readable & clean.
edited 1×, last 21.03.10 09:38:55 pm

old Re: Lua Scripts/Questions/Help

Decks
User Off Offline

Quote
Decks has written
someone clever can help me with my problem?

its very important for me how create lua scrypt for other specmode for spectators or simple player

someone help me?
To the start Previous 1 2177 178 179338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview