Forum

> > CS2D > Scripts > Script support
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Script support

8 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Script support

Gajos
BANNED Off Offline

Zitieren
IMG:https://img855.imageshack.us/img855/9417/bwxhb.png

flame No Posts which offend/provoke/insult other people or groups
illegal Show good behavior and simply don't be a stupid asshole
spam The forum is NOT a chat room! Behave accordingly! No unsubstantial/very short posts!

> thread cs2d How to ask for help.
If someone needs a script or your a script can't work, We can write it for you.


¦========== user oxytamine ==========¦
Problem: I need a dynamic variable to be written to the file. Everytime value changes file should be rewritten. So I need to find something like "onchange" hook.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
onchange = function(txt)
	local filename = 'save.txt'
	local file = io.open('sys/lua/'..filename,'w')
	file:write(txt..'\n')
	file:close()
end
var = false

variable = 'lol :D'
addhook('second','_second')
function _second()
	if variable ~= var then
		onchange(variable)
	end
	var = variable
end


¦========== user HedShot ==========¦
Problem: I want to create this script, but it doesn't work!
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
cd = {
	admins = {116544,108942}
}

cd.ToTable = function(t,match)
	local cmd = {};
	if not match then match = '[^%s]+' end
	for word in string.gmatch(t,match) do
		table.insert(cmd,word)
	end
	return cmd
end

cd.bug = function(id,txt)
	msg2(id,c..'200000000Unknown command: '..c..'000255255'..txt)
end

cd.noadm = function(id)
	msg2(id,c..'200000000You don't have enough level to do this!')
end

cd.isAdmin = function(id)
	for _, i in pairs(cd.admins) do
		if player(id,'usgn') == i then
			return true
		end
	end
	return false
end

addhook('say','cd.say')
cd.say = function(id,txt)
	local p = cd.ToTable(txt)
	local cmd = string.lower(p[1])
	if txt:sub(1,1) == '!' and txt ~= 'rank' then
		if cmd == '!explosion' then
			if cd.isAdmin(id) then
				local range = tonumber(p[2])
				if range ~= nil then
					parse('explosion '..player(id,'x')..' '..player(id,'y')..' '..range)
				else
					msg2(id,c..'200000000Correct syntax: !explosion <range>')
				end
			else
				cd.noadm(id)
			end
		else
			cd.bug(id,txt)
		end
		return 1
	end
end
8× editiert, zuletzt 29.03.13 09:53:34

alt Re: Script support

oxytamine
User Off Offline

Zitieren
I need a large script no one will write for me. So I'll just leave a simple question here so I can advance a bit.

I need a dynamic variable to be written to the file. Everytime value changes file should be rewritten. So I need something like "onchange" hook.
1× editiert, zuletzt 26.03.13 15:47:22

alt Re: Script support

Gajos
BANNED Off Offline

Zitieren
user oxytamine hat geschrieben
I need a dynamic variable to be written to the file. Everytime value changes file should be rewritten. So I need to find something like "onchange" hook.


I don't understand your request.
1× editiert, zuletzt 26.03.13 13:42:43

alt Re: Script support

Avo
User Off Offline

Zitieren
Gajos PL hat geschrieben
1
2
3
4
5
6
7
8
9
10
11
onchange = function(txt)
     local filename = 'save.txt'
     local file = io.open('sys/lua/'..filename,'w')
     file:write(txt..'\n')
     file:close()
end

addhook('second','_second')
function _second()
     onchange('lol :D')
end


is useless and wastes memory. You should better use table with metatable, that re-writes table's file when you change it (set new value to existing index or make new index):
__index
__newindex
I mean.
1× editiert, zuletzt 26.03.13 18:57:07

alt Re: Script support

oxytamine
User Off Offline

Zitieren
You see, hook is being called every second, and I want it to be called only when variable was changed to avoid memory leaks. But thanks, I appreciate your help.

alt Re: Script support

Kirby7
User Off Offline

Zitieren
You might want to have a look at this. It shows how you track changes in tables. ( pretty much what bolt suggested )

alt Re: Script support

Avo
User Off Offline

Zitieren
You're welcome.

By the way I don't think that lots of people would see this thread, same with "How to ask for help".

Edit:
user Gajos, I want to know your idea for spawning items randomly on the map, of course at position that player is able to go to. You can treat that as small challenge I'm giving to you. Try to solve it without any complicated algorithms. √
1× editiert, zuletzt 06.04.13 12:56:48
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht