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 215 16 17338 339 Next To the start

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
TheKilledDeath has written
No. This does not work. You need to divide the string
How exactly do I do that?
What example should I use? flackos or wups? I'm really confused.

Just to let you know, I've never learnt lua in my whole life. So this scripting language just makes my face look like these smileys.

I so need to learn the basics.

Could I write player id's manually or does that fail too?
1
2
3
4
5
6
7
8
addhook("say","player_say")
function player_say(id,txt)
	if (txt=="!slay|1") then
		parse("killplayer 1"..id)
		msg("©255255255The lightning has struck against "..player(id, "name").."!")
		parse("sv_sound \"wc3tft_2d/lightningbolt.ogg\"")
	end
end
edited 1×, last 14.06.09 08:05:43 pm

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
an easy way is like I did it:
1
string.sub(string, beginning, ending)
example:
you have the following text:
1
text = !kick 1
!kick is 5 symbols, space is one, number is one:
1
first = string.sub(text, 1,5)
if you would now return first you would get:
!kick
now you need the id:
1
id = string.sub(text,7,string.len(text))
the seven is because of the space, string.len(string) lets the script go until the string ended.
the error in my script is caused of the following thing:
id is now saved as a string. we need to put it to a number:
1
idnumber = tonumber(id)

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote

1
2
3
4
5
6
7
addhook("say","player_say")
function player_say(id,txt)
	if (string.sub(txt, 1, 5) == "!slay") then
		slay = tonumber(string.sub(txt, 7, string.len(txt)))
		parse("deathslap " ..slay)
	end
end

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
LinuxGuy has written

1
2
3
4
5
6
7
addhook("say","player_say")
function player_say(id,txt)
	if (string.sub(txt, 1, 5) == "!slay") then
		slay = tonumber(string.sub(txt, 7, string.len(txt)))
		parse("deathslap " ..slay)
	end
end
That totally works dude. But I've changed code a bit. Because 'deathslap' prints a slap msg and 'killplayer' doesn't, so that's why I use 'killplayer' on the parse for the use of my own msg. This is a fun lua script however the cons. is that everyone in the server can use it and abuse it lol.

1
2
3
4
5
6
7
8
9
addhook("say","player_say")
function player_say(id,txt)
     if (string.sub(txt, 1, 5) == "!slay") then
          slay = tonumber(string.sub(txt, 7, string.len(txt)))
          parse("killplayer " ..slay)
	  parse("sv_sound \"wc3tft_2d/lightningbolt.ogg\"")
	  msg("©082237246"..player(id, "name").." used !slay: the lightning bolt has struck target!")
     end
end
Is it possible to add the victim's name into this?

old Re: Lua Scripts/Questions/Help

bezmolvie
User Off Offline

Quote
I do not lua script but i have an idea about increasing the max money. If you reach 16000, mabey 2000 will be subtracted and added to a seperate variable, allowing you to pick up more money. When it is less than a number, say 6000, the variable would get 2000 subtracted and added to your money. Just a suggestion.

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
MiroslavR coded a custom currency with lua a while ago. But I think you can't use that in buy menu I guess it has to be standard currency.

old Re: Lua Scripts/Questions/Help

Somaz
User Off Offline

Quote
GRRRRRRRRRRRRRRRRRRRRRR!

RAAAAAAAAAAAAAAAAAAAAAAAAGEEEEEEEEEEEEEEEE!

DC I think something is wrong with the cs2d Lua.

1
2
3
4
5
6
addhook("trigger","doorclose1")
function doorclose1(trigname)
	asd = doorclose(1,trigname)
	msg(asd)
	return asd
end

I try to help a guy on the forums.

What this script does:

Shows me a message 1
Still triggers

Fail...

old Re: Lua Scripts/Questions/Help

Somaz
User Off Offline

Quote
Awww man... Okay I'll say your english sux. You'll say why? Where did I make a mistake?

And I'll answer Why? Where did I make a mistake?

Oh and seriosly about grammar, you can't code right, not coding. And yes, yes I can.

Edit: Just for you I'll make it simple: Why my code is bad?

Edit2: Nvm... I restarted cs2d and everything worked.

Edit3: http://www.unrealsoftware.de/forum_posts.php?post=132793&start=0#post133129

You still think I can't code ^^?

In the link there's a code for doors that close automatically after 3 seconds. Feel free to use it/learn from it.
edited 2×, last 16.06.09 12:58:22 pm

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
pretty useless script..
1
2
3
4
5
6
7
addhook("say", "give_money")
function give_money(id,txt)
	if (string.sub(txt, 1, 6) == "!money") then
		money = tonumber(string.sub(txt, 8, string.len(txt)))
		parse("setmoney "..id.." "..player(id,"money")+money.." ") 
	end
end
All it does is that it gives you money you said. Like !money 5. If you had 1$ now you will have 6 :D. we're rich

EDIT:
For few days I'm trying to make a Private Message system. one word = fail...
This is my code, can you please help me find out whats wrong? Thanks
1
2
3
4
5
6
7
addhook("say","private_message")
function private_message(id,txt)
	i = tonumber(txt:sub(6)) 
	if (txt=="@msg"..i.." "..txt) then
		parse("sv_msg2 "..i.." "..player(id,"name").."(PM: )"..txt)
	end
end

LUA ERROR: sys/lua/test.lua:4: attempt to concatenate local 'i' (a nil value)
edited 2×, last 16.06.09 10:33:16 pm

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
I have one problem.
Why thing like that not working?

1
2
3
4
5
6
addhook("leave", "server.test.leave")
function server.test.leave()
	file = io.open("data.txt","w")
	file:write("words")
	file:close()	
end
Thats simple data writing command , but ...?
Why this code is not working ?
DC? Or someone else please answer.

old closed Re: Lua Scripts/Questions/Help

wups
User Off Offline

Quote
wups has written
blablabla tired..


Thanks for the cute warning.
Next time, fix a button so i can remove the posts instead to get this lame warnings.

Admin/mod comment

Just edit it and write DELETE PLEASE instead if writing "blablabla tired...". Then we'll delete it and you won't get warned. /TheKilledDeath

old Re: Lua Scripts/Questions/Help

Somaz
User Off Offline

Quote
Blazzingxx have you tried restartin cs2d? Sometimes it helps.

Edit: And try to see the console for some output. Maybe there's some error.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Blazingxx, try this:

1
2
3
4
5
6
addhook("leave", "server.test.leave")
function server.test.leave()
     file = assert(io.open("data.txt","w"))
     file:write("words")
     file:close()     
end

However, you have to write the path of your file in the first parameter of io.open (Unless the file is in the CS2D folder)

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
I noticed my mistake, thanks.

Here is one more question.
Then you save line:
If that player (id) line exist , how to overwrite only that line?
And btw how to get back same information from readed file?

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
if lua==nil then lua={} end
lua.server={}

addhook("join","lua.server.join")
function lua.server.join(p)
	lua.hero.lvl[p]=1
	file = io.open("sys/lua/data.cfg", "r")
	file:close()
end

addhook("leave", "lua.server.leave")
function lua.server.leave(p)
	sdat = p.." "..lua.hero.lvl[p].."\n"
	file = assert(io.open("sys/lua/data.cfg","a"))
	file:write(sdat)
	file:close()

end

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

lua.server.lvl=initArray(32)
edited 3×, last 17.06.09 02:24:42 pm

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
I don't think it's possible to replace a single line, you have to rewrite the whole file.
First, you copy all the info (Line by line) to memory, then you clear the file. After clearing it, you rewrite the file line by line, but when you get to the line of the player you have to update his settings (or wathever), you write from his current stats (or wathever).

Here's the function I used for my script.
See if you can get something from it...

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
function flacko.admins.savedata(filedir,id)
	if(flacko.admins.loggedin[id] and player(id,"usgn")>0) then
		local usgn = player(id,"usgn")
	
		local file = assert(io.open(filedir,"r"))
		database = file:read("*all")
		file:close()
		
		local linestable = {}
		for line in io.lines(filedir) do
			table.insert(linestable,line)
		end
	
		if(linestable[flacko.admins.usernumber[id]]~=nil) then
			clearfile(filedir)
	
			local appendrewrite = assert(io.open(filedir,"a"))
			for i=1,#linestable do
				if(i+1~=flacko.admins.usernumber[id]) then
					appendrewrite:write(linestable[i],"\n")
				elseif (i+1 == flacko.admins.usernumber[id]) then
					appendrewrite:write(usgn," ",flacko.admins.playerpower[id]," ",flacko.admins.colors[id]," ",flacko.admins.autosay[id]," ",flacko.admins.loggedin[id],"\n")
				end
			end
			appendrewrite:close()
			return 1
		else
		print("ERROR WHILE SAVING DATA!")
		return nil
		end
	end
end

Also, in my script I save player's user number (His corresponding line in the file) in flacko.admins.usernumber[id].
The save system only works with people with USGN to identify them easier and not having to write a password system
To the start Previous 1 215 16 17338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview