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 2118 119 120338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
CmDark has written
1
2
3
4
5
6
7
8
9
10
11
function rwep()
	math.random() 
	local result = math.random(1,90)
	return result
end

rwep()

--[[-- Use
parse("equip "..id.." "..rwep())
--]]--

Isn't this more "real" ?


That would be epic fail because it might return 9 as the item type, and such weapon does not exist.
1
2
3
4
5
6
7
function rwep()
	local wp = math.random(1,90)
	while itemtype(wp,"name") == "" do
		wp = math.random(1,90)
	end
	return wp
end
But I think that using tables is better

Edit:
@Deatherr: YOU have a script? Or is it the one that I posted before?
You could try fixing this thing by yourself.

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
Flacko has written
CmDark has written
1
2
3
4
5
6
7
8
9
10
11
function rwep()
	math.random() 
	local result = math.random(1,90)
	return result
end

rwep()

--[[-- Use
parse("equip "..id.." "..rwep())
--]]--

Isn't this more "real" ?


That would be epic fail because it might return 9 as the item type, and such weapon does not exist.
1
2
3
4
5
6
7
function rwep()
	local wp = math.random(1,90)
	while itemtype(wp,"name") == "" do
		wp = math.random(1,90)
	end
	return wp
end
But I think that using tables is better


I could just add this

1
if result == 7 or result == 8 or result == 9 or result == 12 or result == 13 or result == 14 or result == 15 or result == 16 or result == 17 or result == 18 or result == 19 or result == 25 or result == 26 or result == 27 or result == 28 or result == 29 or result == 42 or result == 43 or result == 44 or result == 60 or result == 89 or result == 90 then return end

Long but effective

old Re: Lua Scripts/Questions/Help

NozliW
User Off Offline

Quote
hehe thanks but i need random for primary and secondary so i used this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function rndsec()
	local sec = math.random(1,6)
	while itemtype(sec,"name") == "" do
		sec = math.random(1,6)
	end
	return sec
end 
function rndprim()
	local prim = math.random(1,39) -- (its just until the 39'th weapon i don't want any other =)
	while itemtype(prim,"name") == "" do
		prim = math.random(1,39)
	end
	return prim
end
but sometimes it gave me 2 secondary weapons and no primary, it's problem of this or problem on any other place of the script ?

old Re: Lua Scripts/Questions/Help

- Dark Void -
User Off Offline

Quote
CmDark has written
I could just add this

1
if result == 7 or result == 8 or result == 9 or result == 12 or result == 13 or result == 14 or result == 15 or result == 16 or result == 17 or result == 18 or result == 19 or result == 25 or result == 26 or result == 27 or result == 28 or result == 29 or result == 42 or result == 43 or result == 44 or result == 60 or result == 89 or result == 90 then return end

Long but effective


You could just add this

1
2
3
if result > 6 and result < 91 then
     return 
end

Short but effective
edited 4×, last 16.12.09 03:21:38 am

old Re: Lua Scripts/Questions/Help

Deatherr
User Off Offline

Quote
Quote
Edit:
@Deatherr: YOU have a script? Or is it the one that I posted before?
You could try fixing this thing by yourself.


Yes this is the one that is posted . When i said "Have" that mean that i have it no that i have made it.....Nerver mind it.........i fix it already i think

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
this would be newb question

for 1st, I have this
1
alltalk = initArray(32)

1
2
3
4
5
6
7
addhook("say","adminsay")
function adminsay(p,t)
usgn = player(p,"usgn")
	if (alltalk[p] == 1 ) and (usgn == 1234) then
	msg("©255255255"..player(p,"name").."(ALLTALK): "..t.."@C")
	end	
end

I've try to fix it, but I can't, I try to see the problem at console, but no error.

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
Flacko has written
Post your initArray function please...


1
2
3
4
5
6
7
function initArray(m)
local array = {}
	for i = 1, m do
	array[i]=0
	end
return array
end

i got that

old Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Quote
1
2
3
4
5
6
addhook("say","allsay")
function allsay(id,txt)
name = player(id,"name")
	msg("©255255255"..name.." (ALL TALK): "..txt.."@C")
	return 1
end

that is if you want to all players say.
and..

1
2
3
4
5
6
7
addhook("say","adminsay")
function adminsay(id,txt)
name = player(id,"name")
	if (id==1) then
		msg("255255255"..name.." "..txt.."@C")
	return 1
end

this is admin say.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Admirdee:
Replace your function with this one
1
2
3
4
5
function initArray(s,[u]v[/u])
	local array = {}
	for i = 1, s do array[i] [u]= v[/u] end
	return array
end

And your table declaration should be like this
1
alltalk = initArray(32,[u]1[/u])

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
@Flacko

thanks, it's perfectly working.

@Starkzz

no, I don't mean like that, I mean it can be enable and disable by player

old Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Quote
ok, i see what can i do.
see if it works.

Spoiler >


the command is
1
2
all_talk <id> <value>
value is to turn on or off ( 1 = on ; 0 = off )
edited 2×, last 17.12.09 01:26:37 am

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
Starkkz has written
ok, i see what can i do.
see if it works.

Spoiler >


You don't need a long code for that, use function posted by Flacko already enough

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@firefox

Try this one:

1
2
3
4
5
6
7
addhook('attack','snowball')

function snowball(p)
	if (player(p,'weapontype') == 75) then
		parse('equip '..p..' 75')
	end
end

When you throw snowball, you get new one.
To the start Previous 1 2118 119 120338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview