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 2109 110 111338 339 Nächste Zum Anfang

alt Re: Lua Scripts/Questions/Help

DaveRodec
BANNED Off Offline

Zitieren
Toa Hero 92 hat geschrieben
Toa Hero 92 hat geschrieben
Hello People, I want to start off with displaying these values:(dynamic objects are used for buildings, mines etc.!)

- object(id,"value") Return a value of a dynamic object:
exists, typename, type,
health, mode, team, player,
x, y, rot, tilex, tiley,
countdown, rootrot, idle,
rotvar, target, upgrade
Moreover there is:
object(0,"table"): table with all dynamic object IDs

In this script : Code:
addhook("build","buildmessage")
function buildmessage(p,type,x,y,mode,objectid)
--object = (objectid)
--id=(type)
print("You have built building type: "..type.." At X="..x.." At Y="..y.." With Mode: "..mode.." And With Object Id:"..objectid.."")
--print("Object type "..object(id,"typename").."")
end


As you can see I have tried to fix this error:LUA ERROR: sys/lua/samples/toainstabuild.lua:58: attempt to call global 'object' (a nil value)

& this error: LUA ERROR: sys/lua/samples/toainstabuild.lua:59: attempt to call local 'object' (a number value)

and this error too:LUA ERROR: sys/lua/samples/toainstabuild.lua:60: attempt to call global 'object' (a number value)

So.... how can i fix it please help because I'm stumped


Flacko hat geschrieben
You can't.
That means that object hasn't been declared as a function.


Well If I Can't Then How can I Make it So?

And, If no-one can answer me with a solution, I will seriously consider Private Messaging DC with the question.
Mostly because no-one seems to have any clue as to how to find and manipulated those values...


Try this:

1
2
3
4
5
addhook("build","buildmessage")
function buildmessage(p,type,x,y,mode,objectid)
print("Type: "..type.."at x ="..x)
print("Object type "..object(objectid,"typename"))
end

[quote = "Some GUy"]
Where can I find all the os. io. ect. and there definitions?
[/quote]
http://www.lua.org/manual/5.1/manual.html#5

alt Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Zitieren
Can someone test this code for me please? I'm tryin to test out Lua Library functions

Spoiler >

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
Why don't you just write this
1
print(os.tmpname())

It saves a lot of work

And your script wouldn't work and it's weird
1
2
3
local 0 = 1,32 --Blazing told u that this was ridiculous, why would u do it again?
Temporary_Name = os.tmpfile() --Wait, weren't we talking about os.tmpname?
player = tonumber(string.sub(txt, 2, string.len(txt)) ) --This would convert the string name 1 to a number.
And ur tabbing is weird
1× editiert, zuletzt 03.12.09 07:46:22

alt Money giving lua

Deatherr
User Off Offline

Zitieren
This lua is for my Town map so players can give money to other player.So far CmDark have helped me make it but its not working.

addhook("say","givemoney")
function givemoney(id,txt)
          
if (string.sub(txt, 1, 1) == "!give "player" "money"") then
          if player(id,"money") > money then
money = tonumber(string.sub(txt, 2, string.len(txt)) )
           player = tonumber(string.sub(txt, 3, string.len(txt)) )
parse("setmoney "..player.." "+money)
           parse("setmoney "..id.." "..player(id,"money")-money)
end
end
end

alt Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Zitieren
oh yeah deatherr

1
2
3
4
5
6
7
8
9
10
11
12
addhook("say","givemoney")
function givemoney(id,txt)

     if (string.sub(txt, 1, 1) == "$") then
		if player(id,"money") > 10 then
          money = tonumber(string.sub(txt, 2, string.len(txt)) )
		  pl = tonumber(string.sub(txt, 3, string.len(txt)) )
          parse("setmoney "..pl.." "..player(pl,"money"))+money)
		  parse("setmoney "..id.." "..player(id,"money"))-money)
     end
end
end

I don't know if This one works either
1× editiert, zuletzt 05.12.09 02:20:40

alt Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Zitieren
at saying !money it gives you money?


Zitat
addhook("say","givemoney")
function givemoney(id,txt)
mn = player(id,"money")
     if (txt=="$") then
          parse("setmoney "..id.." "..mn)
     end
end
1× editiert, zuletzt 05.12.09 02:32:09

alt Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Zitieren
Try this

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
26
27
28
29
30
31
32
function toTable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end
	return cmd
end
addhook("say","sayz")
function sayz(id, text)
	local ptxt = toTable(text)
	if ptxt[1] == "$" and #ptxt == 3 then --Ok the format would be "$ PLAYER MONEY"
		local rcvp = tonumber(ptxt[2]) --Recieving player
		local rcvm = tonumber(ptxt[3]) --Money
		if player(rcvp,"exists") then --If the player exists
			if player(id,"money") >= rcvm then --and this dude has enough money
				if player(rcvp,"money") + rcvm <= 16000 then --check if we won't give him too much money (so we don't waste cash)
					parse("setmoney "..id.." "..player(id,"money")-rcvm)
					parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm)
				elseif player(rcvp,"money") < 16000 then --Ok this guy would overpass $16000 with our donation so we deduct this
					rcvm = 16000 - player(rcvp,"money") --Here
					parse("setmoney "..id.." "..player(id,"money")-rcvm)
					parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm)
				end
			end
		end
	end
end

Edit: Page 111 is mine too
Zum Anfang Vorherige 1 2109 110 111338 339 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht