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 229 30 31338 339 Next To the start

old Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Quote
Quote
1
2
3
4
5
addhook("kill","player_kill")
function player_kill(killer)
	if (os.clock()>10) then
	parse("setpos "..killer.." 500 500")
end


How about that?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Jonzku777 has written
Quote
1
2
3
4
5
addhook("kill","player_kill")
function player_kill(killer)
	if (os.clock()>10) then
	parse("setpos "..killer.." 500 500")
end


How about that?


That would fail.
You have to use 2 hooks and and 2 tables
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
function initArray(s,v)
	local tbl={}
	for i=1, s do
		tbl[i]=v
	end
	return tbl
end

jailtime = initArray(32,os.clock())
onjail = initArray(32,false)

addhook("kill","player_kill")
function player_kill(killer,victim)
	parse("setpos "..killer.." 300 300") -- Put him into jail
	jailtime[killer]=os.clock
	onjail[killer] = true
end

addhook("second","func_second")
function func_second()
	for i=1,32 do
		if(onjail[i]==true) then
			if(os.clock() - jailtime[i]>= 30) then --30 secs
				onjail[i] = false
				parse("setpos "..i.." 10 10")--Get out from jail
			end
		end
	end
end

I don't guarantee that could work because I haven't tested it and writing code here is a pain, I should have opened worpad...
edited 1×, last 14.07.09 08:07:03 pm

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
oh. Linux guy.
Anyway kill hook shoud be activated by someone else death.
Otherwise it shurely not work.
Flack shows good example , but it uses "second hook"

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
There's no other way to take the player out from jail automatically (Without using second).
You could put a button in prison and use the trigger entity if you don't want to use second.

But look what has the RPG script i'm working in in the hook:

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
addhook("second","flacko.rpg.second")
function flacko.rpg.second()
	for i=1, 32 do
		if player(i,"exists") and player(i,"health")>0 then
			if(flacko.rpg.poisoned[i]~=0) then
				local pfactor = flacko.rpg.idtosid(1,true).factor
				local poisonlevel = flacko.rpg.speciallvl[flacko.rpg.poisoned[i]]
				if(player(i,"health") <= pfactor*poisonlevel) then
					parse("customkill "..flacko.rpg.poisoned[i].." Poison "..i)
				else
					parse("sethealth "..i.." "..player(i,"health") - pfactor*poisonlevel)
				end
			elseif(flacko.rpg.paralyzed[i]~=0) then
				local mx_speed = flacko.rpg.speed[i] 
				if(flacko.rpg.item[i][1]==12 or flacko.rpg.item[i][2]==12) then
					mx_speed = mx_speed + flacko.rpg.idtosid(12,true).factor 
				end
				if (player(i,"speedmod") < mx_speed) then
					parse("speedmod "..i.." "..player(i,"speedmod")+1)
					if player(i,"speedmod")  == mx_speed then
						flacko.rpg.paralyzed[i] = 0
					end
				end
			end
			if(flacko.rpg.special[i]==3) then
				parse("sethealth "..i.." "..player(i,"health") + flacko.rpg.idtosid(3,true).factor*flacko.rpg.speciallvl[i])
			end
		end
	end
end

And I don't feel any slowdown or experience any ping problems.

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Admirdee has written
@leegao

it's not working to me, I already copy paste it to script.
no error, but also spawn with n0thing >.<


T.T, I assumed that you would add

1
2
addhook("hit", "hit_hook")
addhook("spawn", "spawn_hook")

at the start of the file

old Wondering if its even possible?

KaiserWilhelm
User Off Offline

Quote
I'm still looking for a way to prevent the building of certain buildings, and now im wondering if its even possible. when I posted my original question yesterday i received no response, but the guy after me had a huge problem solved. So im guessing that that is an indicator that this would be imposssible in Lua? or is it so hard you have to think it over for a day? I've tried my best to write or obtain this script, i still have to leave it up to you. excuse my english

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
KaiserWilhelm has written
I'm still looking for a way to prevent the building of certain buildings, and now im wondering if its even possible. when I posted my original question yesterday i received no response, but the guy after me had a huge problem solved. So im guessing that that is an indicator that this would be imposssible in Lua? or is it so hard you have to think it over for a day? I've tried my best to write or obtain this script, i still have to leave it up to you. excuse my english


The correct response would have been that the solution is so easy that you probably wouldn't believe it. However, the solution does not require Lua as an intermediate step.

http://cs2d.com/help.php?cat=settings&cmd=mp_unbuildable#cmd

Quote
mp_unbuildable
Categories
settings, server

Parameters
- buildings (text): list of buildings which are unbuildable, seperated with ","

Info
Select which buildings are not available for building.

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
Otherwise you could simply do a console command for example: mp_building_limit "Gate Field" 0

I'm not sure how you make it using lua. Although it feels somewhat pointless when you can enter simple commands... but would be nice to see a lua version of how to disable certain buildings.

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
leegao has written
T.T, I assumed that you would add

1
2
addhook("hit", "hit_hook")
addhook("spawn", "spawn_hook")

at the start of the file


T.T I still don't get it. same problem

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Admirdee has written
T.T I still don't get it. same problem


This will only work if you are killed by a weapon. Inside the first IF condition in hit_hook, print out all of the relevant variables, do the same inside the spawn_hook

old Script Not Working

MatheusMK3
User Off Offline

Quote
Yesterday, i have written this code, but it does not works!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("say", "mk3.utils.say") 
function mk3.utils.say(id, message) 
     if(player(id,"team")==1) then 
          parse("sv_msg ©025025255"..player(id,"name").." diz: ©255255255"..message) 
     elseif(player(id,"team")==1) then 
          parse("sv_msg ©255025025"..player(id,"name").." diz: ©255255255"..message) 
     elseif(player(id,"team")==0) then 
          parse("sv_msg ©255255000"..player(id,"name").." diz: ©255255255"..message) 
     end 
     print("===CHAT: Jogador ["..player(id,"name").."] (ID "..id..") do time "..player(id,"team").." disse: 

"..message) 
     return 1 
end
But i don't know what is wrong...

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
MatheusMK3 has written
Yesterday, i have written this code, but it does not works!
But i don't know what is wrong...


Can you give us more info? Why doesn't it work, what do you want it to do, and what if any error messages were displayed on the console?

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
Did you tried to make multiple colors in the same line? its not supported

EDIT: Here you go:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook("say", "lol_said")
function lol_said(id, txt)
	print("===CHAT: Jogador ["..player(id,"name").."] (ID "..id..") do time "..player(id,"team").." disse: "..txt)
	if(player(id,"team")==1) then
		parse("sv_msg ©025025255"..player(id,"name").." diz: "..txt)
		return 1
	end
	if(player(id,"team")==2) then
		parse("sv_msg ©255025025"..player(id,"name").." diz: "..txt)
		return 1
	end
	if(player(id,"team")==0) then
		parse("sv_msg ©255255000"..player(id,"name").." diz: "..txt)
		return 1
	end
end
only You now have red for couter terrorist and Blue fror terrorist o.O

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
LinuxGuy has written
only You now have red for couter terrorist and Blue fror terrorist o.O


Try switching the 1 and the 2

old Can one Help me ????

Captain Kenpachi
User Off Offline

Quote
WHat is here wrong i dont know
addhook("kill","sample.ut.kill")
function sample.ut.kill(killer,victim,weapon)
     if (os.clock()-sample.ut.timer[killer])>3 then
          sample.ut.level[killer]=0;
     end
     level=sample.ut.level[killer]
     level=level+1
     sample.ut.level[killer]=level
     sample.ut.timer[killer]=os.clock()
     -- FIRST BLOOD?
     if (sample.ut.fblood==0) then
          sample.ut.fblood=1
          parse("sv_sound \"env/firstblood.wav\"");
          msg (player(killer,"name").." sheds FIRST BLOOD by killing "..player(victim,"name").."!")
     end
     -- HUMILIATION? (KNIFEKILL)
     if (weapon==50) then
          -- HUMILIATION!
          parse("sv_sound \"env/humiliation.wav\"");
          msg (player(killer,"name").." humiliated "..player(victim,"name").."!")
     else
          -- REGULAR KILL
          if (level==1) then
               -- Single Kill! Nothing Special!

          elseif (level==2) then
               parse("sv_sound \"env/doublekill.wav\"");
               msg (player(killer,"name").." made a Doublekill!")

          elseif (level==3) then
               parse("sv_sound \"env/multikill.wav\"")
               msg (player(killer,"name").." made a Multikill!")

          elseif (level==4) then
               parse("sv_sound \"env/ultrakill.wav\"")
               msg (player(killer,"name").." made an ULTRAKILL!")

          elseif (level==5) then
               parse("sv_sound \"env/monsterkill.wav\"")
               msg (player(killer,"name").." made a MO-O-O-O-ONSTERKILL-ILL-ILL!")
          
elseif (level==6) then
               parse("sv_sound \"env/unstoppable.wav\"")
               msg (player(killer,"name").." is UNSTOPPABLE !")

          elseif (level==7) then
               parse("sv_sound \"env/rampage.wav\"")
               msg (player(killer,"name").." made a Rampage !")

          elseif
(level==8) then
               parse("sv_sound \"env/ownage.wav\"")
               msg (player(killer,"name").." made a Onwnage !")
          
elseif
(level==9) then
               parse("sv_sound \"env/killingspree.wav\"")
               msg (player(killer,"name").." made a Killingspree !")

elseif
(level==10) then
               parse("sv_sound \"env/ludicrouskill.wav\"")
               msg (player(killer,"name").." made a ludicrouskill !")
end
     end
end

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
leegao has written
Try switching the 1 and the 2


MasterKadjik has written
WHat is here wrong i dont know

What does console say? Do you have any errors?

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
MasterKadjik has written
WHat is here wrong i dont know


For future references - If you do not tell us what it is that You Want The Script To Do AND Where the Problem is Occuring And if possible, if you don't want the world to think that you're incapable of independent though Where the error possible might be located at We can not help you

@LinuxGuy good to see you're still as sharp as always

old Re: Lua Scripts/Questions/Help

Captain Kenpachi
User Off Offline

Quote
Hm.... ok made that right now
And how i can make when i make a monster kill its in many secounds over and i cant make a unstoppable
how i can make that when save that for one round how on the [LaG] clan server ?

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
Oh hi all, i forgot, i fixed it and i played LONG sorry
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
if sample==nil then sample={} end
sample.ut={}

-----------------------
-- INITIAL SETUP     --
-----------------------
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
sample.ut.timer=initArray(32)
sample.ut.level=initArray(32)
sample.ut.fblood=0



addhook("kill","sample.ut.kill")
function sample.ut.kill(killer,victim,weapon)
	if (os.clock()-sample.ut.timer[killer])>3 then
		sample.ut.level[killer]=0;
	end
	level=sample.ut.level[killer]
	level=level+1
	sample.ut.level[killer]=level
	sample.ut.timer[killer]=os.clock()
	-- FIRST BLOOD?
	if (sample.ut.fblood==0) then
		sample.ut.fblood=1
		parse("sv_sound \"env/firstblood.wav\"");
		msg (player(killer,"name").." sheds FIRST BLOOD by killing "..player(victim,"name").."!")
	end
		-- HUMILIATION? (KNIFEKILL)
	if (weapon==50) then
		-- HUMILIATION!
		parse("sv_sound \"env/humiliation.wav\"");
		msg (player(killer,"name").." humiliated "..player(victim,"name").."!")
	else
		-- REGULAR KILL
	if (level==1) then
		-- Single Kill! Nothing Special!

	elseif (level==2) then
		parse("sv_sound \"env/doublekill.wav\"");
		msg (player(killer,"name").." made a Doublekill!")

	elseif (level==3) then
		parse("sv_sound \"env/multikill.wav\"")
		msg (player(killer,"name").." made a Multikill!")

	elseif (level==4) then
		parse("sv_sound \"env/ultrakill.wav\"")
		msg (player(killer,"name").." made an ULTRAKILL!")

	elseif (level==5) then
		parse("sv_sound \"env/monsterkill.wav\"")
		msg (player(killer,"name").." made a MO-O-O-O-ONSTERKILL-ILL-ILL!")
          
	elseif (level==6) then
		parse("sv_sound \"env/unstoppable.wav\"")
		msg (player(killer,"name").." is UNSTOPPABLE !")

	elseif (level==7) then
		parse("sv_sound \"env/rampage.wav\"")
		msg (player(killer,"name").." made a Rampage !")
	elseif (level==8) then
		parse("sv_sound \"env/ownage.wav\"")
		msg (player(killer,"name").." made a Onwnage !")
          
	elseif (level==9) then
		parse("sv_sound \"env/killingspree.wav\"")
		msg (player(killer,"name").." made a Killingspree !")

	elseif (level==10) then
		parse("sv_sound \"env/ludicrouskill.wav\"")
		msg (player(killer,"name").." made a ludicrouskill !")
	end
end
end

old Re: Lua Scripts/Questions/Help

Captain Kenpachi
User Off Offline

Quote
oh thank you linuxguy i love you
and my last ask i dont know how i can make a hud text i wandet to make it over left at the radar
EDIT
And how i can make when i make a monster kill its in many secounds over and i cant make a unstoppable
how i can make that when save that for one round how on the [LaG] clan server
edited 1×, last 16.07.09 12:40:03 am
To the start Previous 1 229 30 31338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview