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 2176 177 178338 339 Nächste Zum Anfang

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Zitieren
DRoNe hat geschrieben
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...
1× editiert, zuletzt 18.03.10 17:35:07

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
@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
2× editiert, zuletzt 18.03.10 22:01:32

alt Re: Lua Scripts/Questions/Help

siuL
User Off Offline

Zitieren
Flacko hat geschrieben
@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

alt Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

siuL
User Off Offline

Zitieren
leegao hat geschrieben
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/]

alt Re: Lua Scripts/Questions/Help

Fasttt
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

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

alt Re: Lua Scripts/Questions/Help

leoska
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

Fasttt
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

siuL
User Off Offline

Zitieren
Flacko hat geschrieben
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

alt Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

Zitieren
Patasuss hat geschrieben
@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?!

alt Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

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

alt Re: Lua Scripts/Questions/Help

Patasuss
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Zitieren
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
Zum Anfang Vorherige 1 2176 177 178338 339 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht