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 2212 213 214338 339 Nächste Zum Anfang

alt Re: Lua Scripts/Questions/Help

TheKingOfP90
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

TheKingOfP90
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Snake_Eater
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

Cure Pikachu
User Off Offline

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

alt Probably this will help you =)

Cliffe_Snake
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

archmage
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Szkieletor
User Off Offline

Zitieren
martis67 hat geschrieben
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.
Zum Anfang Vorherige 1 2212 213 214338 339 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht