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 265 66 67338 339 Next To the start

old Re: Lua Scripts/Questions/Help

BetaM
User Off Offline

Quote
I saw an interesting function in a downloaded script, but I unfortunately, deleted it 6 hours before the files were gone. Now I want to know,

map=game('sv_map')

how to make that the prefix, the _ , and the suffix of the map were separated from each other (I saw it in the GeoIP Module, it was something that started with a string.something).
edited 1×, last 10.10.09 04:12:55 pm

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
mat5b has written
I saw an interesting function in a downloaded script, but I unfortunately, deleted it 6 hours before the files were gone. Now I want to know,

map=game('sv_map')

how to make that the prefix, the _ , and the suffix of the map were separated from each other (I saw it in the GeoIP Module, it was something that started with a string.something).


The uses a string.split function that I wrote a few months ago.

Basically the gist of it would be

cmd = "sv_map"
cmd:split("_") -- {"sv","map"}


1
2
3
4
5
6
7
8
9
10
11
12
13
function string.split(t, b)
	local cmd = {}
	local match = "[^%s]+"
	if b then
		match = "%w+"
	end
	if type(b) == "string" then match = "[^"..b.."]+" end
	if not t then return invalid() end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end
	return cmd
end

old Re: Lua Scripts/Questions/Help

playa slaya
COMMUNITY BANNED Off Offline

Quote
What is wrong with my script it supposed to show 5 messages at once, but it only shows one message(the first one)

Spoiler >


or will I just need to use this
Spoiler >

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
playa slaya has written
What is wrong with my script it supposed to show 5 messages at once, but it only shows one message(the first one)

Spoiler >


or will I just need to use this
Spoiler >

Minute hook doesnt have any parameter.

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
-----------------
-- Minute --
-----------------
addhook('minute','gg_minute')
function gg_minute()
     local i
     for i=1,32 do
     msg2(i,'This Script By: playa slaya') 
     msg2(i,'Your Level is: '..level[i])
     msg2(i,'Your Experience is: '..exp[i]..'/'..exptolevel[i])
     msg2(i,'Your Warnings are: '..warnings[i]..'/'..maxwarnings)
     msg2(i,'Say !show cmds to view all commands')
end

old Re: Lua Scripts/Questions/Help

Night Till Death
User Off Offline

Quote
Blazzingxx has written
NTD has written
is there a possibility to create 2 supplys from 1 player?

i mean for example: i want to create 2 supplys 1 for CT with m4a1 and second next to the CT 1 with Ak47 is that possible?

Yes, you can use building mode for that.


i mean i need a script that can create 2 supplys next to each other next to me...

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
NTD has written
i mean i need a script that can create 2 supplys next to each other next to me...

LOL...
Please, learn lua!

It will spawn row of suplies with all modes.
1
2
3
4
5
6
addhook("serveraction","serverations")
function serverations(p,btn)
	for i = 1,6 do
		parse('spawnobject 9 '..player(p,'tilex') + i..' '..player(p,'tiley') + i..' 0 '..i..' '..player(p,'team')..' '..p)
	end
end
Press any serveration to test it.
Spoiler >

old Re: Lua Scripts/Questions/Help

playa slaya
COMMUNITY BANNED Off Offline

Quote
TheKilledDeath has written
1
2
3
4
5
6
7
8
9
10
11
12
13
-----------------
-- Minute --
-----------------
addhook('minute','gg_minute')
function gg_minute()
     local i
     for i=1,32 do
     msg2(i,'This Script By: playa slaya') 
     msg2(i,'Your Level is: '..level[i ])
     msg2(i,'Your Experience is: '..exp[i ]..'/'..exptolevel[i ])
     msg2(i,'Your Warnings are: '..warnings[i ]..'/'..maxwarnings)
     msg2(i,'Say !show cmds to view all commands')
end

it works except for this line

[i]
1
2
[/i]
msg2(i,'Your Experience is: '..exp[i ]..'/'..exptolevel[i ])

ERROR: Attemp to call a global value

old Re: Lua Scripts/Questions/Help

NozliW
User Off Offline

Quote
Oh i'm sorry i didn't noticed you quoted me
thanks for it =D
EDIT: oh i tried it and it doesn't work well thanks anyway

old Re: Lua Scripts/Questions/Help

playa slaya
COMMUNITY BANNED Off Offline

Quote
i need help with math and random
all i know about random is you need math.random
and my math wont work for like this
example = 2*32+3-10
i cant do math higher then 1 of these *,/,+,- at a time

old Re: Lua Scripts/Questions/Help

ZianSing
User Off Offline

Quote
I need help with LUA.. I need to know how to make random events happen each round. Like... in one round everyone spawns in a random position with a certain weapon or equipment... Does anyone know how to do this with LUA?
Thanks

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
1
2
math.randomseed(os.clock()) --randomizes
math.random(lower, upper) -- Generates a number between lower and upper

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("join","autoteamchose")
function autoteamchose(id)
     if(playersonteam(1)>playersonteam(2)) then --If there are more Ts
          parse("maket "..id)
     elseif(playersonteam(2)>playersonteam(1)) then --If there are more CTs
          parse("makect "..id)
     else
          local newteam = math.random(1,2) --Generate a number that may be 1 or 2
          if(newteam==1) then
               parse("maket "..id) --If results 1, makes the player a T
          else
               parse("makect "..id) --Otherwise, it makes it a CT
          end
     end
end

Aw, what happened with tabs?
edited 2×, last 11.10.09 08:32:51 am

old Re: Lua Scripts/Questions/Help

BetaM
User Off Offline

Quote
leegao has written
The uses a string.split function that I wrote a few months ago.

Basically the gist of it would be

cmd = "sv_map"
cmd:split("_") -- {"sv","map"}


1
2
3
4
5
6
7
8
9
10
11
12
13
function string.split(t, b)
	local cmd = {}
	local match = "[^%s]+"
	if b then
		match = "%w+"
	end
	if type(b) == "string" then match = "[^"..b.."]+" end
	if not t then return invalid() end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end
	return cmd
end

Good, but how can I check if a part is equal to something?

I tried:
if cmd=="arena" then
if sv=="arena" then

That didn't work...
edited 1×, last 11.10.09 12:54:48 pm

old Re: Lua Scripts/Questions/Help

BetaM
User Off Offline

Quote
The name: arena_river .
But it says that cmd is a string value -.-
BTW. I've found a function that looks more complicated then yours:
1
2
3
4
5
6
7
8
9
10
11
12
function string:split(delimiter)
  local result = { }
  local from  = 1
  local delim_from, delim_to = string.find( self, delimiter, from  )
  while delim_from do
    table.insert( result, string.sub( self, from , delim_from-1 ) )
    from  = delim_to + 1
    delim_from, delim_to = string.find( self, delimiter, from  )
  end
  table.insert( result, string.sub( self, from  ) )
  return result
end

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
that is TMK's string.split function, it's a bit more inefficient in that it doesn't take advantage of the regex native support on Lua which is why I chose to write my own function while working on AMX2D.

Basically you've given me the incorrect assumption of what you wanted to do.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
--[-- Utility Functions
function string.is_in(_str_, _table_)
	for k,v in pairs(_table_) do
		if v == _str_ then return true end
	end
end
function string.split(t, b) 
	local cmd = {} 
	local match = "[^%s]+" 
	if type(b) == "string" then match = "[^"..b.."]+" end 
	for word in string.gmatch(t, match) do table.insert(cmd, word) end 
	return cmd 
end 
--]--

current_map = "arena_river"
query = "arena"

if query:is_in(current_map:split("_")) then
	--TODO: Add logic code here.
end

old Re: Lua Scripts/Questions/Help

playa slaya
COMMUNITY BANNED Off Offline

Quote
my free hook wont work after i free it if you say a certin word your warnings go up by 0ne whatis wrong and i cant use sethook because i have two say hooks and cant select function with sethook
1
freehook('say','gg_badwords')
To the start Previous 1 265 66 67338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview