Forum

> > CS2D > Scripts > Script support
Forums overviewCS2D overview Scripts overviewLog in to reply

English Script support

8 replies
To the start Previous 1 Next To the start

old Script support

Gajos
BANNED Off Offline

Quote
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
edited 8×, last 29.03.13 09:53:34 am

old Re: Script support

oxytamine
User Off Offline

Quote
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.
edited 1×, last 26.03.13 03:47:22 pm

old Re: Script support

Gajos
BANNED Off Offline

Quote
user oxytamine has written
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.
edited 1×, last 26.03.13 01:42:43 pm

old Re: Script support

Avo
User Off Offline

Quote
Gajos PL has written
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.
edited 1×, last 26.03.13 06:57:07 pm

old Re: Script support

oxytamine
User Off Offline

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

old Re: Script support

Kirby7
User Off Offline

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

old Re: Script support

Avo
User Off Offline

Quote
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. √
edited 1×, last 06.04.13 12:56:48 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview