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 215 16 17338 339 Nächste Zum Anfang

alt Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Zitieren
TheKilledDeath hat geschrieben
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
1× editiert, zuletzt 14.06.09 20:05:43

alt Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Zitieren

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

alt Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Zitieren
LinuxGuy hat geschrieben

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?

alt Re: Lua Scripts/Questions/Help

bezmolvie
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

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

alt Re: Lua Scripts/Questions/Help

Somaz
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Somaz
User Off Offline

Zitieren
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.
2× editiert, zuletzt 16.06.09 12:58:22

alt Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Zitieren
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)
2× editiert, zuletzt 16.06.09 22:33:16

alt Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

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

alt geschlossen Re: Lua Scripts/Questions/Help

wups
User Off Offline

Zitieren
wups hat geschrieben
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 Kommentar

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

alt Re: Lua Scripts/Questions/Help

Somaz
User Off Offline

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

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

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Zitieren
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)
3× editiert, zuletzt 17.06.09 14:24:42

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

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