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 2102 103 104338 339 Next To the start

old Re: Lua Scripts/Questions/Help

jackisokay2
User Off Offline

Quote
wait, ok so i deleted at and now it stopped working, did i do something wrong?

Spoiler >
edited 1×, last 26.11.09 05:26:45 am

old Re: Lua Scripts/Questions/Help

Vectarrio
User Off Offline

Quote
And my question: How to make lua to load files, and how to do some automatic loading of files in folder?
And @jackisokay2: For resetting zombie class, just put oll of that things:
1
2
3
4
5
if (sample.zombie.class[id]<=1) then
parse ("setmaxhealth "..id.." 100")
parse ("setarmor "..id.." 0")
return "78,86,0";
end
To another if
Just change your sample.zombie.spawn hook and function to this:
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
42
addhook("spawn","sample.zombie.spawn")
function sample.zombie.spawn(id)
if (player(id,"team")==1) then
if (sample.zombie.class[id]<=1) then
parse ("setmaxhealth "..id.." 100")
parse ("setarmor "..id.." 0")
return "78,86,0";
end

if (sample.zombie.class[id]==2) then
parse ("setmaxhealth "..id.." 80")
parse ("speedmod "..id.." 5")
return "78,86,84";
end

if (sample.zombie.class[id]==3) then
parse ("setmaxhealth "..id.." 80")
parse ("speedmod "..id.." -1")
return "78,86,80";
end

if (sample.zombie.class[id]==4) then
parse ("setmaxhealth "..id.." 40")
parse ("setarmor "..id.." 10")
parse ("speedmod "..id.." 20")
return "78,86,0";
end

if (sample.zombie.class[id]==5) then
parse ("setmaxhealth "..id.." 75")
parse ("setarmor "..id.." 0")
parse ("equipitem "..id.." 69")
return "78,86,69";
end

if (sample.zombie.class[id]==6) then
parse ("setmaxhealth "..id.." 75")
parse ("speedmod "..id.." -10")
return "78,86,83";
end
end
end
edited 1×, last 26.11.09 05:32:53 am

old Re: Lua Scripts/Questions/Help

jackisokay2
User Off Offline

Quote
Vectar666 has written
And my question: How to make lua to load files, and how to do some automatic loading of files in folder?


wait, like dofiles?

just do

dofile("sys/lua/(foldrnamehere)name.lua")


also, ok so i deleted at and now it stopped working, did i do something wrong?

Spoiler >

old Re: Lua Scripts/Questions/Help

jackisokay2
User Off Offline

Quote
Vectar666 has written
You forgot "else" in sample.zombie.walkover function.
And i know about dofile, i mean mass dofile, all the files in same folder

hrm, i have no idea for that, sorry. but where would i put the "else" after the addhook("walkover","sample.zombie.walkover") or... what?

also, another question, how could i make it like Zombie plague where it only infects one zombie after (x) amount of seconds?
edited 1×, last 26.11.09 06:55:46 am

old Re: Lua Scripts/Questions/Help

h4uja2
User Off Offline

Quote
Some errors in ur scripit
Spoiler >


Spoiler >


But there is onether error when i hit an enemy
Spoiler >

old Re: Lua Scripts/Questions/Help

NozliW
User Off Offline

Quote
Hey jackisokay2 tab your scripts :S
it makes it easier to read.
Spoiler >

i didn't test it but it should work.
EDIT:
h4uja2 try this
Spoiler >

i hope it works

old Re: Lua Scripts/Questions/Help

h4uja2
User Off Offline

Quote
I didt test it because i make this
Spoiler >
and its workin perfect, and why do u add this "oldhealth" ?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@WIlson:
Dammit, I tried my script as a CT and it worked, but not as a T. I've found moar stupid errors >.>
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
function array(size,value)
local asd = {}
for i=1, size do
asd[i] = value
end
return asd
end

function getslotweps(id,slot)
	local myweapons = playerweapons(id)
	local rt = {}
	for i,v in pairs(myweapons) do
		if itemtype(v,"slot") == slot then
			table.insert(rt,v)
		end
	end
	return rt
end

--Global table to save what weapons did each player have
a_table = array(32,{prim={},sec={},melee={},nades={}})

addhook("startround","omg")
function omg()
	for i=1,32 do
		a_table[i] = {prim={},sec={},melee={},nades={}} --HERE WE RESET THE ARRAY
		if player(i,"exists") then
			if player(i,"team")>0 then
				a_table[i].prim=getslotweps(i,1)
				for n,v in pairs(a_table[i].prim) do
					parse("strip "..i.." "..v)
				end
				a_table[i].sec=getslotweps(i,2)
				for n,v in pairs(a_table[i].sec) do
					parse("strip "..i.." "..v)
				end
			end
		end
	end
end

@Vectar666:
Here I've made two functions (and stole one from leegao :D) that may help you:
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
function toTable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end
	return cmd
end

function writetofile(path, ...) --You can pass a lot of arguments here, returns true on succes, false on error
	local file = io.open(path, "w")
	if file then
		for i,v in ipairs(arg) do
			file:write(v,"\n")
		end
		file:close()
		return true
	else
		return false
	end
end

function readfromfile(path) --This will return an array (or false if file isn't found)
	local file = io.open(path,"r")
	if file then
		local tbl = toTable(file:read("*a"),"\n")
		file:close()
		return tbl
	else
		return false
	end
end
And if you need to know what is the current path for the current script:
1
2
3
4
5
6
function GetFileFolder()
	local path = debug.getinfo(debug.getinfo(1).func).short_src
	path = path:reverse()
	path = path:sub(path:find("/",1),-1):reverse()
	return path
end

Happy scripting guys

old Halp making images work

Trotskygrad
User Off Offline

Quote
So I'm trying to implement a ranking system, that draws colored bars (on the shoulders) of a player depending on how many kills the player has. I can't get the image functions working though, Can anyone help?

old Re: Lua Scripts/Questions/Help

NozliW
User Off Offline

Quote
omg THANKS YOU SO MUCH FLACKO
it worked !!
now i've thought another use lol.
strip and equip (so on round start you got full ammo)

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Trotskygrad has written
So I'm trying to implement a ranking system, that draws colored bars (on the shoulders) of a player depending on how many kills the player has. I can't get the image functions working though, Can anyone help?


I hope we can help you.
Show us your script so we can fix it

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Jack (I'll just call you jack):
Find this:
1
2
3
4
5
6
7
8
addhook("walkover","sample.zombie.walkover")
function sample.zombie.walkover(id,iid,type)
     if (type>=61 and type<=68) then
          return 0
     else
          return 1
     end
end

And replace it with this:
1
2
3
4
5
6
7
8
9
10
addhook("walkover","sample.zombie.walkover")
function sample.zombie.walkover(id,iid,type)
	if player(id,"team")==2 then
		if (type>=61 and type<=68) then
			return 0
		else
			return 1
		end
	end
end
Now all the survivors can pick up items.
Or you could just delete the whole function and it would have the same effect :B

old Re: Lua Scripts/Questions/Help

jackisokay2
User Off Offline

Quote
haha thanks flacko!

now, ive noticed that whatever zombie class you are, it transfers the maxHP to survivors, so lets say we become a fast zombie, with only 40hp, when you become a survivor, if you get hurt to 40hp, it stays there, and wont go back to 100.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Vectar666 has written
How can I put string parameter into function?

It's not sort of Blitzmax when you need to convert it.
Just
1
2
3
function message(txt)
	msg(txt)
end

message('Hello')

Or you need something else?

old Re: Lua Scripts/Questions/Help

NozliW
User Off Offline

Quote
add the bold text:
Spoiler >

you would have to do an experience and level gaining function.
i'm too busy to think of somehting like that but it's not really hard.
EDIT:
is it possible to free images liek radars and that kind of things ??
To the start Previous 1 2102 103 104338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview