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 2212 213 214338 339 Next To the start

old Re: Lua Scripts/Questions/Help

TheKingOfP90
User Off Offline

Quote
Hello! I have a problem: io.open function doesn't want to open my .txt file. How do I fix it?
The thing is - I want to save data for this USGN number in a separate file. I use io.open with parameter "w", and then with "r", but even when I choose to read numbers only, it still doesn't want to read it. What do I do? Or is there any tutorial for this?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
1
2
3
4
5
6
a = io.open("file.txt","w")
a:write("asd")
a:close()
a = io.open("file.txt","r")
text = a:read("l")
if text=="asd" then print("success")

old Re: Lua Scripts/Questions/Help

TheKingOfP90
User Off Offline

Quote
Thanks! And what about reading the variable in this file and setting the variable in script to the one in file? I may be not too understandable

EDIT:
1
2
3
4
5
6
a = io.open("sys/lua/data/file.txt","w")
a:write("asd")
a:close()
a = io.open("file.txt","r")
text = a:read("l")
variable[id]=text

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
If you expect a number value then you would have to tonumber() your result because the FILE:read() function returns strings, unless you call it with the parameter "*n"

1
2
3
4
5
6
file = io.open("5.txt","w")
file:write(player(5,"money"))
file:close()
file = io.open("5.txt","r") -- Reopen the file for reading
parse("setmoney 5 " .. (file:read("*n")) )--Read the number
file:close()

old Re: Lua Scripts/Questions/Help

Snake_Eater
User Off Offline

Quote
Hi all! I want if I shoot somebody with deagle that this player teleports AND SPAWN again and again at a special place.For example at x=2160 y=784.
CAN ANYBODY SHOW ME A SCRIPT LIKE THIS PLS PLS??
I am repeating me but there is no answer
PLS answer me and help
ty if you know and tell it me

old Re: Lua Scripts/Questions/Help

Cure Pikachu
User Off Offline

Quote
I'll fix up the first part.
1
2
3
4
5
6
addhook("hit","tele")
function tele(id,source,weapon)
	if (weapon==3) then
		parse("spawnplayer "..id.." 2160 784")
	end
end
The part about teleporting at the same spot after getting hit, I have no idea.

old Probably this will help you =)

Cliffe_Snake
User Off Offline

Quote
Snake_Eater, try this
1
2
3
4
5
6
addhook("kill","NoWhereToRun")
function NoWhereToRun(killer,victim,weapon,x,y)	
     if (weapon==3) then
          parse("spawnplayer "..victim.." "..x.." "..y)
     end
end
Why forum trims blanks and tabs in my code???

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
@SnakeEater
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
array = {}
addhook("kill","NoWhereToRun")
addhook("move", "m")
function NoWhereToRun(killer,victim,weapon,x,y)     
if (weapon==3) then
parse("spawnplayer "..victim.." 2160 784")
array[victim] = 1
end
end

function m (id)
	if ( array[id] ~= nil and array[id] == 1 ) then
		parse("spawnplayer "..victim.." 2160 784")
	elseif ( array[id] = nil ) then
		array[id] = 0
	end
end

old Re: Lua Scripts/Questions/Help

Szkieletor
User Off Offline

Quote
martis67 has written
i think thats a stupid question but how create lua script?

Create a text file, then Save as... Name.lua
Name can be anything you want. You also have to learn scripting, DRoNe already said where to look.
To the start Previous 1 2212 213 214338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview