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 2178 179 180338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Cure Pikachu
User Off Offline

Quote
Decks has written
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?

Ehm, what do you mean?
I doubt anyone can help you like that.

old Re: Lua Scripts/Questions/Help

Fasttt
User Off Offline

Quote
I have a question. Does anyone know how to sort the table from largest value to a smaller?

Example.
scoretable = {3,9,0,1,5} ---> scoretable = {9,5,3,1,0}

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Not really.
Sometimes with ElseIf you can get rid of some extra lines.

1
2
3
4
5
6
7
if var == 1 then
	var = 2
else
	if var == 2 then
		var = 1
	end
end
1
2
3
4
5
if var == 2 then
	var = 1
elseif var == 1 then
	var = 2
end

old Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

Quote
omg you know, i want something better. so if you are thinking, i'll steal your script then you don't must give me a script.
If i knew doing lua ...
(Sorry for my English, im from Slovakia)

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
DRoNe has written
omg you know, i want something better.

Beggars can't be choosers.
Just simply change the image used for the script if you do not like the image. If you want battery life (like in ZP) you should ask someone to HELP you or just find out how to yourself

old Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Quote
I think that i found bugs in timer function...

1.
1
timer(100,"stargate.freeimage",id,1)

It should execute ONE TIME stargate.freeimage(id) after 100 miliseconds, but it executes the command more than one time.

So, timer doesnt delete self when executed command.

PLEASE FIX IT I NEED THIS FEATURE!

I tried many ways, so i decided to write own timer function "bt-timer" ( "better timer" ), and i do it.

But i have another problem, there is no way to check time in miliseconds in LUA/Linux Shell - so i just build timer that works on seconds...

-- WebNuLL

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Counterstrike 2d provides a msec100 hook (called 10 times per second) and an always hook (called 50 times per second)

old Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Quote
I found a way to get miliseconds in LUA:

1
2
3
function miliseconds()
	return string.format("%.4f", os.clock())
end

So im going to build my bt-timer function to replace this build in crap "timer".

So, i finished my code, but i dont know if it really works.

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
-----------------------------
-- BETTER TIMER BY WEBNULL --
--  ITS OPEN-SOURCE CODE   --
-----------------------------


function array(m) 
     local array = {} 
     for i = 1, m do 
          array[i] = 0 
     end 
     return array 
end 

function miliseconds()
	return tonumber(string.format("%.4f", os.clock()))
end

-- maximum limit of timer
bt_timer={}
bt={0}

function bt.push(time,func,rep)

	-- only number format in miliseconds
	if (type(time) == "number")
	then
		eoft=table.getn(bt_timer) -- check last index
		nextindex=(eoft+1) -- get id of next index
		os_time=string.format("%.4f", os.clock())

		-- initialize array
		bt_timer[nextindex]={'time','func','rep', 'r_time'}
		bt_timer[nextindex]['time']=tonumber(os_time+((time/1000)/2.1))
		bt_timer[nextindex]['time']=tonumber(os_time+((time/1000)/2.1))
		bt_timer[nextindex]['r_time']=tonumber((time/1000)/2.1)
		bt_timer[nextindex]['func']=func
		bt_timer[nextindex]['rep']=rep

		local f = io.open("sys/lua/tmp/"..nextindex..".lua", 'w')
		f:write("-- BT-Timer by WebNuLL\n")
		f:write(func)
		io.close(f)


		-- return id number
		return nextindex

	else
		-- ohh, the time argument is not a number!
		return false
	end
end

function bt.remove(id)
	if (bt_timer[id])
	then
		table.remove(bt_timer,id)

		-- removed
		return true
	else
		-- already removed
		return true
	end
		
end

function bt.init(mode)
	if (mode=="ms100") then
		addhook("ms100","bt.watch")
	elseif (mode=="second") then
		addhook("secound", "bt.watch")
	elseif (mode=="minute") then
		addhook("minute", "bt.watch")
	elseif (mode=="always") then
		addhook("always", "bt.watch")
		print("Warning the bt-timer is set to \"always\" and it can cost more CPU power.")
	end
end

function bt.watch()

	os_time=miliseconds()

	for i=0, table.getn(bt_timer) do
		if(type(bt_timer[i])=="table")
		then
			
		if(bt_timer[i]['time'] and bt_timer[i]['rep'] and bt_timer[i]['r_time'])
		then
			--msg(bt_timer[i]['time'].." - "..os_time)
			if(bt_timer[i]['time']<os_time or bt_timer[i]['time']==os_time)
			then			
				print("Executing sys/lua/tmp/"..i..".lua")	
				dofile("sys/lua/tmp/"..i..".lua")


				if(bt_timer[i]['rep']>1)
				then
					bt_timer[i]['rep']=(bt_timer[i]['rep']-1)
					bt_timer[i]['time']=(os_time+bt_timer[i]['r_time'])
				else
					-- if it only repeat 1 time, just delete it
					bt.remove(i)
				end
			end
		end
		end
	end
end

-- EXAMPLE OF USAGE!
--bt.init("ms100") -- ms100, second, minute, always is a refresh rate
--bt.push(10000,"msg(\"it works!\")",1)

-- WebNuLL
edited 2×, last 22.03.10 10:19:33 pm

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
I forgot and would be like this:
1
2
3
x=nil
a = x and 25
print(a)  --> 25
where if the first value is a false value it uses the second?

but or would be the opposite of and?

i looked for the answer on lua.org but could not find it

old Re: Lua Scripts/Questions/Help

YellowBanana
BANNED Off Offline

Quote
The conjunction operator and returns its first argument if this value is false or nil; otherwise, and returns its second argument. The disjunction operator or returns its first argument if this value is different from nil and false; otherwise, or returns its second argument. Both and and or use short-cut evaluation, that is, the second operand is evaluated only if necessary.



Why would you wanna use this for fucks sake..

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
YellowBanana has written

Why would you wanna use this for fucks sake..

well sometimes it can lessen the effort and time put into a script or a chunk of code

Example:
1
2
3
4
5
6
7
function factorial(n)
	if n == 1 or n == 0 then
		return 1
	else
		return n * factorial(n - 1)
	end
end
I could also do it this way:
1
2
3
function factorial(n)             
  	return n == 0 and 1 or n * factorial(n - 1)
end
see there is a difference in characters between the two functions, but each do the exact same operation

old Re: Lua Scripts/Questions/Help

Decks
User Off Offline

Quote
Pikachu_Lv85 has written
Decks has written
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?

Ehm, what do you mean?
I doubt anyone can help you like that.

i mean, i think about scrypt lua which create other spectator mode for spectators than the rest, but i dont know how that do

old Re: Lua Scripts/Questions/Help

Cure Pikachu
User Off Offline

Quote
Decks has written
Pikachu_Lv85 has written
Decks has written
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?

Ehm, what do you mean?
I doubt anyone can help you like that.

i mean, i think about scrypt lua which create other spectator mode for spectators than the rest, but i dont know how that do

Let me guess... Impossible?
(Since no one gave a reply for months)

EDIT: I think I get it, he wants a script which allows individual spectator modes per spectator (Or am I wrong? )
edited 1×, last 25.03.10 10:54:30 am

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
I don't think it's impossible (I didn't understand what he meant neither) but maybe nobody answered because no one wants to do his job?
To the start Previous 1 2178 179 180338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview