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 2139 140 141338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Yea, I understood everything but the table part of it.
And I don't get how the table has anything to do with it. Sorry

old Please HELP me !

BrunoRZ
User Off Offline

Quote
I'm trying to make a lua.(But i never made one before)
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 ?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Homer:
This is the toTable function by leegao:
1
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
And your command function would look like this:
1
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

old Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Quote
or this other mode..

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

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Eh, thanks, I understand
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
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
Would this be legal? Or do the end statements mark the ending point of the local variable.
edited 1×, last 18.01.10 05:46:39 pm

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Yea, all local variable exists only in that statement, where it was declared.

1
2
3
function none(a,b,c)
	local val
end

That's better explanation.
1
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

old Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Quote
Can it transfer between hooks? Cause this script isn't doing something, even if it does, it's not taking the persons health, it takes everyones health.

old Is it my script?

Anders4000
User Off Offline

Quote
DC.
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

old Re: Lua Scripts/Questions/Help

DC
Admin Off Offline

Quote
okay... I thought this would be absolutely obvious...

• 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.

old Please HELP me !

BrunoRZ
User Off Offline

Quote
THIS IS MY LUA SCRIPT
------------------------------------------------------------------------
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)

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
As TKD told you, you shouldn't be using the "use" hook, use the "trigger" hook instead.
And your parses are wrong, you forgot to add a space after the command:
1
2
parse("setmoney "..id.." "..(player(id,"money")-400))
parse("equip "..id.." 51")
And you did something weird there.

old Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Quote
wtf player(id,"51") is not value.
you see on sys/lua/info.txt

and here is it..

1
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
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

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Oh, but wouldn't it be better to use trigger entity?
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

old Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Quote
hmm.. i don't know. . for me is more easy the hook use.

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)
To the start Previous 1 2139 140 141338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview