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 216 17 18338 339 Next To the start

old Lua help

KimKat
GAME BANNED Off Offline

Quote
Flacko and Blazzingxx.

I've read a tutorial about line replacement and I found this...

Source: http://www.scintilla.org/SciTELua.html
SciTELua has written
append(text) - appends text to the end of the document
insert(pos, text) - inserts text at the specified position
remove(startPos, endPos) - removes the text in the range


Most of the functions defined in Scintilla.iface are also be exposed as pane methods. Those functions having simple parameters (string, boolean, and numeric types) are fully supported. For example, editor:InsertText(pos, text) does practically the same thing as editor:insert(pos, text). Functions having a stringresult parameter will include a string in the return value. For both strings and stringresults, if the function is documented as expecting a length as its first parameter, you do not pass the length from Lua. Instead, it is inferred from the context.
These might help a bit.

I think "pos" is what line you're on. For example third row might be number 3, or 2. (not sure if 0 has anything to do with it.)

So I guess it's like this...
editor:insert(3, "put your code here")

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
y = 10

file = io.open("Read.txt","r")

for line in file:lines() do
y = y + 10
screen:print(100,y,line,white)
end

file:close()
Use parameters like that?
edited 2×, last 18.06.09 03:23:13 pm

old Re: Lua Scripts/Questions/Help

kikinep
User Off Offline

Quote
DC can you make to all this users but more to me a tut of how to do scripts but plz super easy to understand plz thx

PD:DC or anybody who want to do that ill love you xd

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
kikinep has written
DC can you make to all this users but more to me a tut of how to do scripts.

PD:DC or anybody who want to do that ill love you xd

He wont.
You can find some tuts in www.lua.org

old Re: Lua Scripts/Questions/Help

Kaka024
User Off Offline

Quote
i have a small request.
If somebody's nick is "Player" then use command "setname <this player's id> [ByKaka] Guest".

And repeat this check-up every 2 minutes.
It should be useful

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
guys, noob need help here

my script almost done, all works fine.. but i got this

LUA ERROR: attempt to call a nil value

I dunno where is it @@

old Re: Lua Scripts/Questions/Help

wups
User Off Offline

Quote
Yes of course they can change the nick back, but add the nick hook and it should work fine?

But really annoying :p

NIL = nothing, check at the code if you block nil.

old Re: Lua Scripts/Questions/Help

Kaka024
User Off Offline

Quote
I only want to rename players without nicks (I mean "Player" nick) to guests, because its better than "Player 1, player 2" etc.
So can smbd do it for me? That person can add message "Player has been renamed by ...'s system"

@edit
so... can anybody make that for me?

@edit2
tried this one (remaked script of one user+advertisements - thx for him)
but something wont work :S

addhook("minute","sample.nickchange")
addhook("join","nickjoin")
function nickjoin(p)
n = player(p,"name")
function sample.nickchange()
if (string.find(n,"player") ~= nil) then
parse("setname "..p.." [ByKaka] Guest")
end
end
end

@edit
No way! I've made it! Alone!

A simple script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("join","nickjoin")
addhook("spawn","pspawn")
a=0

function nickjoin(p)
n = player(p,"name")
 
function pspawn(p)
if n=="Player" then
a=a+1
parse("setname "..p.." [ByKaka] Guest #" ..a)
end
end
end
edited 6×, last 21.06.09 08:24:05 pm

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
KimKat has written
I think "pos" is what line you're on. For example third row might be number 3, or 2. (not sure if 0 has anything to do with it.)

So I guess it's like this...
editor:insert(3, "put your code here")


think about it, why would the SciTE API Documentation supply this function when the actual API for Lua have nothing on this? The 3 functions you've just had on were all "inhouse" functions. Forget about lua for a moment and brush up on streaming objects, view all input objects as streams and you'll figure out how to do it.

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("join","nickjoin")
addhook("spawn","pspawn")
a=0

function nickjoin(p)
n = player(p,"name")

function pspawn(p)
if n=="Player" then
a=a+1
parse("setname "..p.." [ByKaka] Guest #" ..a)
end
end
end


If you actually run this on a real server it would always rename the players if the last person who joined is named "Player" and everyone spawned. Also, try putting the different variables in their respective scopes, Lua scoping is very loose, therefore bad programming convention will lead to confusing logic errors (as the one described above), here's some of the fixes:

1) Put global variable outside of the functions. Place them at the top of the script, and always place the keyword "local" inside the function when you are using a variable that you don't want to have recycled outside of that function. Saves memory (basic optimization) and makes your script capable of running parallel with other scripts.

2) Use more meaningful names for your variables.

3) Use the right types of objects. In this case, you should be declaring your ids with a list.

That's all for now.

old Re: Lua Scripts/Questions/Help

Kaka024
User Off Offline

Quote
leggao. It isn't actual. I noticed that so i changed the script for this:
1
2
3
4
5
6
7
8
9
10
11
addhook("join","nickjoin")
addhook("spawn","pspawn")

function nickjoin(p)
function pspawn(p)
n = player(p,"name")
if n=="Player" then
parse("setname "..p.." [ByKaka] Guest")
end
end
end

It works for now

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
Kaka024 has written
leggao. It isn't actual. I noticed that so i changed the script for this:
1
2
3
4
5
6
7
8
9
10
11
addhook("join","nickjoin")
addhook("spawn","pspawn")

function nickjoin(p)
function pspawn(p)
n = player(p,"name")
if n=="Player" then
parse("setname "..p.." [ByKaka] Guest")
end
end
end

It works for now


what about name change? you could disable it
To the start Previous 1 216 17 18338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview