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 230 31 32338 339 Next To the start

old Another problem... :\

MatheusMK3
User Off Offline

Quote
Ok, thanks for the help last time, now i have another problem, with a team chat command, again, i need help...

Here i only created functions to sell weapons to players, send money and to show weapons, but the send money and sell weapons is not working, it returns: "attempt to compare number with string", and now???

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
addhook("sayteam","mk3.utils.sayteam")
function mk3.utils.sayteam(id,message)

	if(message=="!comandos") then
		parse("sv_msg2 "..id.." ©255000000|~~~| LISTA DE COMANDOS: |~~~|")
		parse("sv_msg2 "..id.." ©255255255[COMANDO]   [O QUE FAZ]")
--		parse("sv_msg2 "..id.." ©255255255!sms [id] [mensagem] - Envia mensagem pessoal para jogador (máximo de 30 letras).")
		parse("sv_msg2 "..id.." ©255255255!pagar [id] [quantia] - Da a quantia desejada ao jogador.")
--		parse("sv_msg2 "..id.." ©255255255!credito [quantia] - Troca dinheiro normal por créditos ($1000 > 1CR)")
		parse("sv_msg2 "..id.." ©255255255!vender [id] [arma] [preço] - Vende arma ao jogador, baseado no id da arma (!armas).")

	elseif(message=="!armas") then
		parse("sv_msg2 "..id.." ©255000000|~~~| Lista DE ARMAS E SEUS ID: |~~~|")
		parse("sv_msg2 "..id.." ©255255255[ID]   [ARMA]")
		parse("sv_msg2 "..id.." ©255255255[1]   [USP]")
		parse("sv_msg2 "..id.." ©255255255[3]   [Desert Eagle]")
		parse("sv_msg2 "..id.." ©255255255[10]   [M3]")
		parse("sv_msg2 "..id.." ©255255255[11]   [XM1014]")
		parse("sv_msg2 "..id.." ©255255255[20]   [MP5]")
		parse("sv_msg2 "..id.." ©255255255[21]   [TMP]")
		parse("sv_msg2 "..id.." ©255255255[30]   [AK-47]")
		parse("sv_msg2 "..id.." ©255255255[31]   [SG552]")
		parse("sv_msg2 "..id.." ©255255255[35]   [AWP]")
		parse("sv_msg2 "..id.." ©255255255[33]   [AUG]")
		parse("sv_msg2 "..id.." ©255255255[32]   [M4A1]")
		parse("sv_msg2 "..id.." ©255255255[40]   [M249]")

	elseif(string.sub(message, 1, 7)=="!vender") then
		posx = player(id, "tilex")
		posy = player(id, "tiley")
		if(posx>=5) then 
		if(posy>=40) then
		if(posx<=13) then
		if(posy<=43) then
--			if(id!=id) then
				if(string.sub(message, 9,10) >= 10) then
					para = string.sub(message, 9, 10)
					if(string.sub(message, 12, 13) >= 10) then
						arma = string.sub(message, 12, 13)
						preco = string.sub(message, 15, 20)
					else
						arma = string.sub(message, 12, 12)
						preco = string.sub(message, 14, 19)
					end
				else
					para = string.sub(message, 9, 9)
					if(string.sub(message, 11, 12) >= 10) then
						arma = string.sub(message, 11, 12)
						preco = string.sub(message, 14, 19)
					else
						arma = string.sub(message, 11, 11)
						preco = string.sub(message, 13, 18)
					end	
				end
				parse("equip "..para.." "..arma)
				parse("setmoney "..para.." "..player(para,"money") - preco)
				parse("setmoney "..id.." "..player(id,"money") + preco)
--			else
--				parse("msg2 "..id.." ©255000000ERRO: Você não pode vender para você mesmo!")
--			end
		end
		end
		end
		end

	elseif(string.sub(message, 1, 6)=="!pagar") then
		if(string.sub(message, 8, 9)>10) then
			para = string.sub(message, 8, 9)
			quantia = string.sub(message, 11, 16)
		else
			para = string.sub(message, 8, 8)
			quantia = string.sub(message, 12, 17)
		end
		parse("setmoney "..para.." "..player(para,"money") + quantia)
		parse("setmoney "..id.." "..player(id, "money") - quantia)
		parse("msg2 "..para.." O jogador "..player(id,"name").." te deu $"..quantia..".")

	else
		parse("sv_msg2 "..id.." ©255000000ERRO: Comando Inválido! O chat de time foi substituído onde você pode colocar comandos.")
	end
	return 1
end

old Re: Lua Scripts/Questions/Help

DC
Admin Off Offline

Quote
your problem:
1
if(string.sub(message, 9,10) >= 10) then
what you are doing is extracting a number and from a string and comparing it with another number. for you the extracted number looks like a number but for Lua it is still a string. Lua can't compare strings with numbers. you have to convert it first with:
1
number=tonumber(string)

also see:
http://lua-users.org/wiki/NumbersTutorial
(the conversion part)

so for your code it should be like
1
if(tonumber(string.sub(message, 9,10)) >= 10) then

old hudtxt

Captain Kenpachi
User Off Offline

Quote
How i can make a hudtext what a function ???
I dont know that can every help me please ???

old Re: Lua Scripts/Questions/Help

wups
User Off Offline

Quote
@Tahifun

Can't read the code because it's so packed and doesn't have many tabs so it's not possible to debug with the eyes.

And next time when you need help with such a big codes, use a pastebin.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Quote
-- Hero Classes by Tajifun

Realy?
I though I made that first
Anyway there is several bugs in my old classes script.

Btw that:.
if herelvl=1...
if herolvl=2.......
you can change it with one line.

as example:
just like sethealth 100+5*herolvl[1]

You can optimize this code to 100 lines.

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
MatheusMK3 has written
Can i write/read xml databases for cs2d? How?


Yes

1. use lua's io library to open and save the files
2. Create your own xml schema for storing the data
3. Put it all together.

I don't recommend this unless you're trying to create data that can either be syndicated or pushed through a web service or data that needs to be parsed externally.

old Re: Lua Scripts/Questions/Help

MatheusMK3
User Off Offline

Quote
leegao has written
I don't recommend this unless you're trying to create data that can either be syndicated or pushed through a web service or data that needs to be parsed externally.

Is why i want to use it to save players data, for my RPG server...

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
MatheusMK3 has written
Is why i want to use it to save players data, for my RPG server...


The question that I want to ask is why you need to use XML

old Re: Lua Scripts/Questions/Help

MatheusMK3
User Off Offline

Quote
Ok, lets this out, for now, i don't need to save, but, i really need to make these two PM and Pay systems, but i cannot...

PM:
1
2
3
4
5
6
7
8
9
10
11
12
elseif(string.sub(message, 1, 3)=="!pm") then
        if(tonum(string.sub(message, 5,6))>10) then
        if(string.sub(message, 8)) then
        parse("msg2 "..id.." Mensagem enviada com sucesso para "..player(id,"name").."!")
        parse("msg2 "..string.sub(message, 5, 6).." PM de "..player(id,"name")..": "..string.sub(message, 8))
        end
        else
        if(string.sub(message, 7)) then
        parse("msg2 "..id.." Mensagem enviada com sucesso para "..player(id,"name").."!")
        parse("msg2 "..string.sub(message, 5, 5).." PM de "..player(id,"name")..": "..string.sub(message, 7))
        end
        end

Pay:
1
2
3
4
5
6
7
8
9
10
11
elseif(string.sub(message, 1, 6)=="!pagar") then
		if(tonum(string.sub(message, 8, 9))>10) then
			para = string.sub(message, 8, 9)
			quantia = string.sub(message, 11, 16)
		else
			para = string.sub(message, 8, 8)
			quantia = string.sub(message, 12, 17)
		end
		parse("setmoney "..para.." "..player(para,"money") + quantia)
		parse("setmoney "..id.." "..player(id, "money") - quantia)
		parse("msg2 "..para.." O jogador "..player(id,"name").." te deu $"..quantia..".")

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Matheus - Please for future say commands, download this first so you don't get hang up on writing the command's say structure itself

http://www.unrealsoftware.de/files_show.php?file=1054

for PM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if not string.split then dofile("sys/lua/string.lua") end
if not msg2 then dofile("sys/lua/wrapper.lua") end

addhook("say", "hook_say_pm")

function hook_say_pm(p, text)
	--text:qsplit() splits a string based on spaces and quotes
	local cmd = text:qsplit()

	if cmd[1] == "!pm" then
		local p2 = tonumber(cmd[2])
		local msg = tonumber(cmd[3])
		if not (p and msg) then return end
		msg2(p, "Message sent to "..player(p2, "name"))
		msg2(p2, "[PM]"..player(p, "name") .. ": "..msg)
	end
end

here, type in !pm 3 "Text that you want to send" to send player 3 this pm.

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
omg, i was trying to do this for ages. thanks leegao!


EDIT: For some uknown reason, i can't get it to work
edited 1×, last 18.07.09 06:26:09 pm

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
oh crap, I made it convert the message into a number...

Change line 11, where it says
1
local msg = tonumber(cmd[3])

to

1
local msg = cmd[3]

basically just delete the tonumber. It should work then

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Very simple , just where is problem?
It sets health for only source , but not for id.

1
2
3
4
5
addhook("hit","hits")
function hits(id,source)
	parse("sethealth "..source.." "..player(source,"health")+100) 
	parse("sethealth "..id.." "..player(id,"health")+100) 
end

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Think about the logic of all of this. The only way that the hit_hook can return false is if the hook is activated before the in game action occurs. Meaning, if you type in player(id, "health"), you'll see that it's 100 instead of whatever it is. Take that logic and see if you can figure out what's wrong.

Oh, and you'll have to realize that the heal gun heals the SOURCE not the Victim.

Here's an example of an artificial damage script

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
33
function hook_hit_dmg(v, p, wep, hp, ap)
	if not dmg.players[p] and not dmg.hp[v] then return 0 end
	--Only concerns hp, no AP
	local i = v
	v_hp = player(v, "health")
	if dmg.players[p] then
		hp = hp*dmg.players[p]
	end
	local crit = false

	if dmg.crit[p] then
		local prob = dmg.crit[p]*100
		math.randomseed(os.time())
		local magic = math.random(100)
		if magic <= prob then
			hp = hp*dmg.crithp
		end
		crit = true
	end

	if dmg.hp[i] then
		hp = dmg.hp[v]*hp
	end

	if v_hp-hp <= 0 then
		dmg.fake_kill(p, wep, v, crit)
		return 1
	end

	sethealth(v, v_hp-hp)

	return 1
end

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
nosence.
I get number of victim... But parse still not working.
Even If I would do
parse("sethealth "..id.." 100")
Your script looks to long

Heal gun heals victim & it was working before month
To the start Previous 1 230 31 32338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview