Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Lua Scripts/Questions/Help

6.770 Antworten
Seite
Zum Anfang Vorherige 1 2178 179 180338 339 Nächste Zum Anfang

alt Re: Lua Scripts/Questions/Help

Cure Pikachu
User Off Offline

Zitieren
Decks hat geschrieben
Decks hat geschrieben
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.

alt Re: Lua Scripts/Questions/Help

Fasttt
User Off Offline

Zitieren
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}

alt Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

Zitieren
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)

alt Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Zitieren
DRoNe hat geschrieben
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

alt Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

webnull
User Off Offline

Zitieren
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
2× editiert, zuletzt 22.03.10 22:19:33

alt Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

YellowBanana
BANNED Off Offline

Zitieren
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..

alt Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Zitieren
YellowBanana hat geschrieben

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

alt Re: Lua Scripts/Questions/Help

Decks
User Off Offline

Zitieren
Pikachu_Lv85 hat geschrieben
Decks hat geschrieben
Decks hat geschrieben
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

alt Re: Lua Scripts/Questions/Help

Cure Pikachu
User Off Offline

Zitieren
Decks hat geschrieben
Pikachu_Lv85 hat geschrieben
Decks hat geschrieben
Decks hat geschrieben
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? )
1× editiert, zuletzt 25.03.10 10:54:30

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
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?
Zum Anfang Vorherige 1 2178 179 180338 339 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht