Forum

> > CS2D > Scripts > Mobiles in CS2D
Forums overviewCS2D overview Scripts overviewLog in to reply

English Mobiles in CS2D

17 replies
To the start Previous 1 Next To the start

old Mobiles in CS2D

Ghost-Rider
BANNED Off Offline

Quote
I currently make my Roleplay map.. and i make a building(T-mobile) i got an idea to make phones in cs2d, of course you can send sms but only when you bought phone!

could you someone help me?
i know for me should use say function..
of course the sms will be costly

old Re: Mobiles in CS2D

DannyDeth
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

sms_cost = 500

addhook("say","sms_function")
function sms_function(id,txt)
	tbl = toTable(txt)
	if(tbl[1] == "!sms")
		msg2(tonumber(tbl[2]),table.concat(tbl," ",3))
		parse("setmoney "..id.." "..(player(id,"money")-sms_cost))
		return 1
	end
	return 0
end
There you go. Just change the cost of the SMS on line 18.

EDIT:
user Alistaire has written
You know, there's a chat function.

LET THEM HAVE THEIR FUN!

old Re: Mobiles in CS2D

HaRe
User Off Offline

Quote
user Alistaire has written
You know, there's a chat function.


You know theres no private message sending function as far as i know.

old Re: Mobiles in CS2D

Apache uwu
User Off Offline

Quote
Ah, then you must also place a check before sending a sms if the player has a phone or not.

Right after 'if(tbl[1] == "!sms")'

1
2
3
4
if has_cell[id]==false then
	msg2(id,"You do not own a cellphone!")
	return 1
end

old Re: Mobiles in CS2D

Alistaire
User Off Offline

Quote
user HaRe has written
user Alistaire has written
You know, there's a chat function.


You know theres no private message sending function as far as i know.


1
2
3
4
5
6
7
8
addhook('say', 'AA_say')

function AA_say(id, txt)
	if txt:sub(1, 3) == '!pm' then
		msg2(txt:sub(5, 7), txt:sub(8, 255))
		return 1;
	end
end

old Re: Mobiles in CS2D

Ghost-Rider
BANNED Off Offline

Quote
user DannyDeth has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

sms_cost = 500

addhook("say","sms_function")
function sms_function(id,txt)
	tbl = toTable(txt)
	if(tbl[1] == "!sms")
		msg2(tonumber(tbl[2]),table.concat(tbl," ",3))
		parse("setmoney "..id.." "..(player(id,"money")-sms_cost))
		return 1
	end
	return 0
end



i get this:
LUA ERROR: sys/lua/server.lua:16: 'then' expected near 'msg2'

old Re: Mobiles in CS2D

EngiN33R
Moderator Off Offline

Quote
user Alistaire has written
Hudtxt2


You'd be better off using @C after the message text. So, for example,

1
msg2(id,"Example text@C")

Would display "Example text" at the centre of the screen.

old Re: Mobiles in CS2D

Bowlinghead
User Off Offline

Quote
Untested!
Just change the "mobile_price" value at line 10.
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
-- New code
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end
mobile = initArray(32)
mobile_price = 1000

addhook("serveraction","buyPhone")
function buyPhone(id,b)
	if b==1 then
		if mobile[id]==0 then
			if player(id,"money")>=mobile_price then
				mobile[id]=1
				msg2(id,"You succesfully bought a mobile")
			end
		end
	end
end


-- Old code

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

sms_cost = 500

addhook("say","sms_function")
function sms_function(id,txt)
     tbl = toTable(txt)
     if (tbl[1] == "!sms") then
	if mobile[id]==1 then --> Added "if player has a mobile"
          msg2(tonumber(tbl[2]),table.concat(tbl," ",3))
          parse("setmoney "..id.." "..(player(id,"money")-sms_cost))
          return 1
	end
     end
     return 0
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview