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 2176 177 178338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Drone: None of them is right.
1
2
3
4
5
6
7
8
math.randomseed(os.time())

func()
	local rand = math.random(0,25) --generate number in range [0;25]
	if rand == 0 then --so chances will be 1/25
		--do stuff
	end
end

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
DRoNe has written
1
math.random = (0, trigger("blabla"))

or :

1
math.random = (0, ("trigger blabla"))

What is better and what is wrong, if this two codes are bad write me that good code
You can only use numbers on that I guess...
1
math.random = (0, 10) -- [i]// This will perform a random calculation between 0 and 10, as far as I know.[/i]
In pros this code could be applied to almost any of the cs2d functions, although the cons would be that I don't really know nor do I have any examples of how this could be used since I'm not a good scripter. Appreciate my effort to help because I've been gone for a while...
edited 1×, last 18.03.10 05:35:07 pm

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Kimkat: Help is always appreciated

@Pikachu: Your code has some small mistakes, I commented it and I think it should be fixed.
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
if khaleed==nil then khaleed={} end
khaleed.gl={}
khaleed.gh={}

addhook("always","khaleed.gl.always")
addhook("say","khaleed.gh.say")

--This function will save me some writing
--to get the team of a player
function p_team(id) return player(id,"team") end

function khaleed.gl.always()--Always hook has no parameters
	--Loop thru all the players in server
	for indx,id in ipairs(player(0,"table")) do
		if p_team(id)==2 then
			parse("sethealth "..id.." "..250);
			parse("setmaxhealth "..id.." "..250);
		end
	end
end

function khaleed.gh.say(id,txt)
	--Turn to lowercase so the cmd is case-unsensitive
	txt = txt:lower()
	if p_team(id)==2 then
		if txt=="god 0" then
			freehook("always","sample.gl.always");
			parse("killplayer "..id);
		elseif txt=="god 1" then
			addhook("always","sample.gl.always");
			parse("equip "..id.." "..83);
		end
	end
end
edited 2×, last 18.03.10 10:01:32 pm

old Re: Lua Scripts/Questions/Help

siuL
User Off Offline

Quote
Flacko has written
@Kimkat: Help is always appreciated

@Pikachu: Your code has some small mistakes, I commented it and I think it should be fixed.
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
if khaleed==nil then khaleed={} end
khaleed.gl={}
khaleed.gh={}

addhook("always","khaleed.gl.always")
addhook("say","khaleed.gh.say")

--This function will save me some writing
--to get the team of a player
function p_team(id) return player(id,"team") end

function khaleed.gl.always()--Always hook has no parameters
	--Loop thru all the players in server
	for indx,id in player(0,"table") do
		if p_team(id)==2 then
			parse("sethealth "..id.." "..250);
			parse("setmaxhealth "..id.." "..250);
		end
	end
end

function khaleed.gh.say(p,txt)
	--Turn to lowercase so the cmd is case-unsensitive
	txt = txt:lower()
	if p_team(id)==2 then
		if txt=="god 0" then
			freehook("always","sample.gl.always");
			parse("killplayer "..id);
		elseif txt=="god 1" then
			addhook("always","sample.gl.always");
			parse("equip "..id.." "..83);
		end
	end
end

on my server it says :
LUA ERROR: sys/lua/God.lua:14: attempt to call a table value

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
use find and replace to apply the following patch

1
for indx,id in player(0,"table") do

=>

1
for indx,id in ipairs(player(0,"table")) do

old Re: Lua Scripts/Questions/Help

siuL
User Off Offline

Quote
leegao has written
use find and replace to apply the following patch

1
for indx,id in player(0,"table") do

=>

1
for indx,id in ipairs(player(0,"table")) do

lol no 1 can do it i think :S
it says on console :
LUA ERROR: sys/lua/God.lua:10: bad argument #1 to 'player' <number expected, got nil>
its on :
[code]
function p_team(id) return player(id,"team") end
[code/]

old Re: Lua Scripts/Questions/Help

Fasttt
User Off Offline

Quote
1
2
3
4
5
6
7
marks = {1,2,3,4,5,6}

mark_1 = marks[1]
mark_2 = marks[2]
mark_3 = marks[4]
mark_4 = marks[5]
mark_5 = marks[6]

how to optimize this code? I mean like this:

1
2
3
for i = 1, #marks, 1 do
mark_..i = marks[i]
end

but my function does not works

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Ah, that's pretty easy.
But It's pointless your idea of making stuff like that.

Fix:

1
2
3
4
5
6
7
8
local i
local marks = {1,2,3,4,5,6}

for i = 1, #marks, 1 do
	_G["mark_"..i] = marks[i]
end

print(mark_1.." "..mark_2) --> "1 2"

old Re: Lua Scripts/Questions/Help

leoska
User Off Offline

Quote
GOD mod???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function array(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
player_count=game('sv_maxplayers')
pl_god=array(player_count)

addhook("hit","_hit")
function _hit(p)
if pl_god[p] == 1 then return 1; end
end

addhook("say","_say")
function _say(p,t)
if (t=='god 1') then pl_god[p]=1 return 1; end
if (t=='god 0') then pl_god[p]=0 return 1; end
end

old Re: Lua Scripts/Questions/Help

Fasttt
User Off Offline

Quote
thank you, Blazzingxx. in my example my idea is really stupid, but it's just example. code of my script is too huge to show its full here

old Re: Lua Scripts/Questions/Help

siuL
User Off Offline

Quote
Flacko has written
Ugh
1
2
3
function khaleed.gh.say(p,txt)
--Change that to
function khaleed.gh.say(id,txt)

nothing ..
like it just protects from he
but like if someone shoot me i lose health

old Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

Quote
Hello,
I want to make a pm mod myself.
I want to make a command like this:
1
pm <ID> <MESSAGE>
So now i want to find out <ID> and <MESSAGE>
Pls help
(sorry for bad english)

old Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

Quote
1
2
3
4
5
addhook("startround","blablafunc")
function blablafunc(trigger)
blabla = math.random(0,1)
	parse ("trigger ..blabla")
end

Why it does not work?

old Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

Quote
@DRoNe
1
2
3
4
5
addhook("startround","blablafunc")
function blablafunc(trigger)
blabla = math.random(0,1)
     parse ("trigger "..blabla)
end

But pls help me with my prob too

old Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

Quote
Patasuss has written
@DRoNe
1
2
3
4
5
addhook("startround","blablafunc")
function blablafunc(trigger)
blabla = math.random(0,1)
     parse ("trigger "..blabla)
end

But pls help me with my prob too


lol still dont works ... what is the problem?!

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@Patasuss
Did you tried something?
I mean, if you want it... at least try once.

The main idea is to split say hook texts string.
1st split string should be player id parameter and all other splits should be text.

old Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

Quote
So tried a little bit.
1
2
3
4
5
6
7
8
9
10
addhook("say","pm")

function pm(id,txt)
	if(string.sub(txt,1,2)=="pm") then
		local spos=string.find(txt,"%s",4)
		local ^mid=tonumber(string.sub(txt,4,(spos-1)))
		local message=string.sub(txt,(spos+1),string.len(txt))
		msg2(id,"ARGS: "..mid..","..message)
	end
end
(I know that it's not a good code)
So it works.
But when i write: "pm 1 lol" (without quotation marks) in the chat the script shows me: "ARGS: 1,lol", but
in console: LUA ERROR:attempt to call a nil value
How to get rid of this error?
pls help

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Try this one.

1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("say","pm")
function pm(p, t)
	local cmd, i = {}
	for w in string.gmatch(t, "[^ ]+") do table.insert(cmd, w) end
	if (cmd[1] == "pm") then
		local p_ = tonumber(cmd[2])
		if p_ then
			for i = 1, 2 do table.remove(cmd,1) end
			msg2(p,"You sent message for "..player(p_,"name"))
			msg2(p_,table.concat(cmd, " ")..", by "..player(p,"name"))
		end
	end
end
To the start Previous 1 2176 177 178338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview