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 226 27 28338 339 Next To the start

old Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Quote
Straight to the point:

I need example for a script which stores and retrieves data.

I would like it to do something like this:

So. A player goes near water-tile, player presses F4 to fish.

Every time player presses F4, player catches a fish, with maximum amount of 5 fish in players "bag".

Then, players goes near a shopcounter and presses F4 again.
Player sells all the current fishes he has in hes "bag" at this point, 1.
Player sells them for 1000$/fish and gets total 1000$ at this point.

So, how to make script like this, which stores certain data, and can retrieve it and give for example certain amount of money of certain data stored (fishes)?

Thanks you!

P.S Is it against rules to make new account here, if I totally stop using this one?

old Server Messages

Proah
User Off Offline

Quote
srvmsg.lua
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
-- Variable
minutes=0

-- Hook1
addhook("minute","srvmsg")

-- Hook1 function
function srvmsg()

	if(minutes==0) then 
		minutes=1
	end

-- Server Messages
	
	if(minutes==5) then
		msg("Message 5")
		minutes = 0
	end

	if(minutes==4) then 
		msg("Message 4")
		minutes = minutes + 1
	end

	if(minutes==3) then 
		msg("Message 3")
		minutes = minutes + 1
	end

	if(minutes==2) then
		msg("Message 2")
		minutes = minutes + 1
	end

	if(minutes==1) then 
		msg("Message 1")
		minutes = minutes + 1
	end

end

For color messages
1
2
3
msg("©255000000Red message")
msg("©000255000Green message")
msg("©000000255Blue message")

For server message (middle of client)
1
2
3
Add [b]@C[/b] at the end of the message, like so:

msg("This message will be in the center of the game.@C")

Add to server.lua
1
dofile("sys/lua/srvmsg.lua")

Or you could add the contents of srvmsg.lua to server.lua, but I find it easier to modify as a separate file.

Message 1 is at the end of the file because if it was at the top it would add 1 to the variable 'minutes' thus triggering the rest of the messages (if they are all in order) and it will show them all at once, every minute.

I know this is easier than pie, but it's useful.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
You could write that.

1
2
3
4
5
6
7
8
9
10
11
12
-- Variable 
min=0 

-- Hook1 
addhook("minute","minutes") 

-- Hook1 function 
function minutes() 
	min = min + 1 
	if min>5 then min=0 ; end
	msg("Message "..min) 
end

old Re: Lua Scripts/Questions/Help

aceman
User Off Offline

Quote
Hey this is blazingxx's code, I wanted to know how to swith it by ip instead per usgn account.

1
2
3
4
5
6
7
addhook("join","lua.hero.join")
function lua.hero.join(p)
usgn = player(p, "usgn")
if (usgn > 0) then
msg2(p,"©160160255Your U.S.G.N ID: "..usgn.."@C")
local usgn = player(p, "usgn")
files = io.open("sys/lua/data/"..usgn..".txt","r")

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Hey guys, I've read in the manual that local variables are faster than global ones.
Now I wonder, how fast are them compared to global ones?
I use local variables when I have to access a global one more than once in the same function and I give it a shorter name to make my code nicier :). Is it ok?

old Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Quote
Hey!

I was wondering about the limitations of the lua, and this seemed like good example:

usgn = player(p, "usgn")
to
usgn = player(p, "ip")

There is 2 options to choose from, ip and usgn.

What if I wanted to make it about characters in name or time of a clock or color of spraytag?

I mean, (may sound stupid) could i technically make script, which bans players if he`s/she`s spraytag is blue?
Or script which bans player if he/she has three T`s in he`s/she`s name?
Or script which bans players who have logged in between 12am & 15 am?

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
You should really read through the info.txt in /sys/lua!
info.txt has written
- player(id,"value")          Return a value of a player:
                    exists, name, ip, port, usgn, ping,
                    idle, bot, team, look, x, y,
                    rot, tilex, tiley, health,
                    armor, money, score, deaths,
                    teamkills, hostagekills,
                    teambuildingkills, weaponid,
                    weapontype, nightvision,
                    defusekit, bomb, flag,
                    reloading, process,
                    sprayname, spraycolor,
                    votekick, votemap, favteam,
                    speedmod, maxhealth
                    Moreover there is:
                    player(0,"table"): table with all player IDs

old What is wrong in my code?

MatheusMK3
User Off Offline

Quote
1
2
if mk3==nil then mk3={} end 
mk3.utils={}
[...]
1
2
3
4
5
6
7
8
9
addhook("join", "mk3.utils.join")
function mk3.utils.join(id)
	parse("msg2 "..id.." Bem Vindo ao servidor Construção Brasil!@C")
	parse("msg2 "..id.." Ganhe level matando inimigos!")
	parse("msg2 "..id.." Ganhe créditos ganhando level!")
	parse("msg2 "..id.." Compre armas pressionando a tecla F2.")
	parse("msg2 "..id.." Divirta-Se!")
	parse("msg O jogador "..player(id,"name").."("..id..") acabou de entrar.")  -- USER (id) CONNECTED
end
Why, when a user enter, nothing appear on screen!

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
parse msg2 should also work I think.. but use this one:
1
2
3
4
5
6
7
8
9
addhook("join", "mk3_utils_join")
function mk3_utils_join(id)
     msg2(id,"Bem Vindo ao servidor Construção Brasil!@C")
     msg2(id,"Ganhe level matando inimigos!")
     msg2(id,"Ganhe créditos ganhando level!")
     msg2(id,"Compre armas pressionando a tecla F2.")
     msg2(id,"Divirta-Se!")
     msg("O jogador "..player(id,"name").." "..id.." acabou de entrar.") -- USER (id) CONNECTED
end

old Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Quote
What does parse actually do (the long way)?

I know it must be used like if you want to use sethealth-command, but why? and what it does? is there any other, but stupid and hard way to do the same?

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
parse lets CS2D use console commands. It's like when you enter something in the console. It's to be able to use these commands without creating a      equipollent command for Lua.

old DRoNe

DRoNe
User Off Offline

Quote
How to create a table through lua which is, for example in classes when choosing a class? please can me write a script?

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Jonzku777 has written
Might this be right?
1
2
3
if (txt=="!Deagl3") && (USGN=="Somecertainusgn") then
     	parse("equip "..id.." 3")
end

What you want to do here?
Equip player if he have usgn?

old Re: Lua Scripts/Questions/Help

RedPillow
User Off Offline

Quote
Umm, I wan`t that only a player with certain usgn may use it

So i though that if player writes !Deagl3 & the usgn is certain then give deagle
To the start Previous 1 226 27 28338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview