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 2109 110 111338 339 Next To the start

old Re: Lua Scripts/Questions/Help

DaveRodec
BANNED Off Offline

Quote
Toa Hero 92 has written
Toa Hero 92 has written
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 has written
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

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

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

Spoiler >

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
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
edited 1×, last 03.12.09 07:46:22 am

old Money giving lua

Deatherr
User Off Offline

Quote
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

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
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
edited 1×, last 05.12.09 02:20:40 am

old Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Quote
at saying !money it gives you money?


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

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
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
To the start Previous 1 2109 110 111338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview