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 Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

Quote
Patasuss has written
@DRoNe
1
2
3
4
5
addhook("startround","blablafunc")
function blablafunc(trigger)
blabla = math.random(0,1)
     parse ("trigger "..blabla)
end

But pls help me with my prob too


lol still dont works ... what is the problem?!

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@Patasuss
Did you tried something?
I mean, if you want it... at least try once.

The main idea is to split say hook texts string.
1st split string should be player id parameter and all other splits should be text.

old Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

Quote
So tried a little bit.
1
2
3
4
5
6
7
8
9
10
addhook("say","pm")

function pm(id,txt)
	if(string.sub(txt,1,2)=="pm") then
		local spos=string.find(txt,"%s",4)
		local ^mid=tonumber(string.sub(txt,4,(spos-1)))
		local message=string.sub(txt,(spos+1),string.len(txt))
		msg2(id,"ARGS: "..mid..","..message)
	end
end
(I know that it's not a good code)
So it works.
But when i write: "pm 1 lol" (without quotation marks) in the chat the script shows me: "ARGS: 1,lol", but
in console: LUA ERROR:attempt to call a nil value
How to get rid of this error?
pls help

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Try this one.

1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("say","pm")
function pm(p, t)
	local cmd, i = {}
	for w in string.gmatch(t, "[^ ]+") do table.insert(cmd, w) end
	if (cmd[1] == "pm") then
		local p_ = tonumber(cmd[2])
		if p_ then
			for i = 1, 2 do table.remove(cmd,1) end
			msg2(p,"You sent message for "..player(p_,"name"))
			msg2(p_,table.concat(cmd, " ")..", by "..player(p,"name"))
		end
	end
end

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~
To the start Previous 1 2177 178 179338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview