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 2139 140 141338 339 Nächste Zum Anfang

alt Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Zitieren
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

alt Please HELP me !

BrunoRZ
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

Homer
User Off Offline

Zitieren
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.
1× editiert, zuletzt 18.01.10 17:46:39

alt Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

Homer
User Off Offline

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

alt Is it my script?

Anders4000
User Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

DC
Admin Off Offline

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

alt Please HELP me !

BrunoRZ
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

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

alt Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Zitieren
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

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
Oh, but wouldn't it be better to use trigger entity?
info.txt hat geschrieben
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

alt Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

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