And I don't get how the table has anything to do with it. Sorry
Forum
CS2D Scripts Lua Scripts/Questions/HelpAnd I don't get how the table has anything to do with it. Sorry
my idea is a button, when you press it, you get a HE, end loses 400$
addhook("use","weaponshop")
funtion weaponshop(id,trigger)
if trigger=="HE" then
if (player(id,"money")>399 then
parse("setmoney"..id.." "..player(id,"money")-400)
parse("equip"..id.." "..player(id,"51")")
end
end
end
end
thats how it is still now ! could someone send me the corret version for this ?
This is the toTable function by leegao:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
function toTable(text,delimiter) 	local buff = {} --Here we make our table 	delimiter = delimiter or " " --If there is no 2nd parameter, we will use whitespace 	delimiter = "[^"..delimiter.."]+" 	for w in string.gmatch(text,delimiter) do--For everytime lua finds our token in the string 		table.insert(buff,w)--We put the word in our table 	end 	return buff --And we return the table end
1
2
3
4
5
6
7
2
3
4
5
6
7
addhook("parse","command_parse") function command_parse(text) 	local splitted = toTable(text) 	if splitted[1] == !equip then 		parse("equip "..splitted[2].." "..splitted[3]) 	end end
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function totable(t,match) 	local cmd = {} 	if not match then match = "[^%s]+" end 	for word in string.gmatch(t, match) do 		table.insert(cmd, word) 	end 	return cmd end addhook("parse","debt_parse") function debt_parse(cm) 	local parses = totable(cm) 	local cmd = tostring(parses[1]) 	local id = tonumber(parses[2]) 	local v = tonumber(parses[3]) 	if (cmd=="!equip")	then -- !equip is the command 		if (id ~= nil and v ~= nil) then -- Check value nil 			if (player(id,"exists")) then -- check if player exist 				parse("equip "..id.." "..v) -- give to the player that weapon 			end 		end 	return 2 -- not see "Error unknown command". 	end return 0 end
Another Question not related to this, Are Local variables limited to the end statements, Like would
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
function Random(id) local Randomer = 1 if (id == 1) then bla bla bla end end if (Randomer == 2)then print ("Hi") else print("Bye") end
edited 1×, last 18.01.10 05:46:39 pm
1
2
3
2
3
function none(a,b,c) 	local val end
That's better explanation.
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
function none() 	if not val then 		local val = 1 	end 	if not val then print("local does not exist!") end --"val" is equal nil end none()
It's easy to check if variable exist or not. You could try it yourself thought, it's too easy
What script you want exactly?
If i download a lua-script and edit it. Can i then say hear in the forums that i made it? Or shall i say that i edited the persons script? :p
you need permission to edit & publish files made by others! it's illegal without permission of the original author(s). It's called copyright infringement.
you EDITED the file. You didn't make the whole file yourself. So you have to say that you actually just edited the file. Saying that you made it is illegal as well!
so:
always ask for permission (or check the applied license if there is any)
always say sth like "original file by XYZ, edited by YOURNAME" (unless the original author allows you to publish it under your name only)
and btw: my cs2d sample lua scripts are open for editing and re-publishing. you don't need to ask me if you want to edit them.
------------------------------------------------------------------------
addhook("use","weaponshop")
funtion weaponshop(id,trigger)
if trigger=="HE" then
if (player(id,"money")>399 then
parse("setmoney"..id.." "..player(id,"money")-400)
parse("equip"..id.." "..player(id,"51"))
end
end
end
end
-------------------------------------------------------------------------
I want the player press the button to buy the HE(get it equiped, and loses 400$)
WHY IT IS NOT WORKING ?
HELP ! (IM NOT EXPERIENCED, THIS IS MY FIRST)
And your parses are wrong, you forgot to add a space after the command:
1
2
2
parse("setmoney "..id.." "..(player(id,"money")-400)) parse("equip "..id.." 51")
you see on sys/lua/info.txt
and here is it..
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
addhook("use","weaponshop") function use(id,event,data,x,y) 	if (even==100) then 		if (x==trigger x in here) and (y==trigger y in here) then 			if player(id,"money")>=400 then 				parse("equip "..id.." 51") 				parse("setmoney "..id.." "..player(id,"money")-400) 			else 				msg2(id,"Not enough money!@C") 			end 	end end
you can see the Tile position of the trigger using this.
1
2
3
4
2
3
4
addhook("move","pos") function pos(id,x,y) 	parse('hudtxt2 '..id..' 100 "Tile Position: X: '..player(id,"tilex")..' Y: '..player(id,"tiley")..'" 13 145') end
1
if (x==trigger x in here) and (y==trigger y in here) then
x in here?
info.txt has written
triggerentity(x,y) on trigger (for triggered entities)
-x: entity x position (tiles)
-y: entity y position (tiles)
>return:
0 - proceed normally
1 - don't trigger
-x: entity x position (tiles)
-y: entity y position (tiles)
>return:
0 - proceed normally
1 - don't trigger
I have a question:
is possible use lua buttons on dedicated server?
hook: use
because i see my map in one dedicated server.
and is not possible to press button.
doesn't work, only with server work it works. (not dedicated)
what they are and what they do.
http://lua-users.org/wiki/SampleCode