English Mobiles in CS2D

17 replies
Goto Page
To the start Previous 1 Next To the start
10.07.12 04:19:11 pm
Up
Ghost-Rider
BANNED
Offline Off
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
10.07.12 04:24:29 pm
Up
Alistaire
User
Offline Off
You know, there's a chat function.
IMG:http://i.imgur.com/5zhwOTP.png
10.07.12 04:31:29 pm
Up
DannyDeth
User
Offline Off
Code:
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!
10.07.12 04:38:33 pm
Up
HaRe
User
Offline Off
user Alistaire has written:
You know, there's a chat function.


You know theres no private message sending function as far as i know.
w0w im so eXotiK
10.07.12 04:41:29 pm
Up
Apache uwu
User
Offline Off
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")'

Code:
1
2
3
4
if has_cell[id]==false then
     msg2(id,"You do not own a cellphone!")
     return 1
end
10.07.12 04:46:02 pm
Up
Alistaire
User
Offline Off
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.


Code:
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
IMG:http://i.imgur.com/5zhwOTP.png
10.07.12 04:57:54 pm
Up
DannyDeth
User
Offline Off
@user Apache uwu:
oh ye. too stoned fo now.
10.07.12 05:01:03 pm
Up
Ghost-Rider
BANNED
Offline Off
user DannyDeth has written:
Code:
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'
10.07.12 05:06:38 pm
Up
Alistaire
User
Offline Off
Code:
1
if(tbl[1] == "!sms")

to
Code:
1
if(tbl[1] == "!sms") then
IMG:http://i.imgur.com/5zhwOTP.png
10.07.12 05:09:04 pm
Up
Ghost-Rider
BANNED
Offline Off
Possible to make the message to center of screen?
10.07.12 05:10:36 pm
Up
Alistaire
User
Offline Off
Hudtxt2
IMG:http://i.imgur.com/5zhwOTP.png
10.07.12 05:11:28 pm
Up
Ghost-Rider
BANNED
Offline Off
user Alistaire has written:
Hudtxt2


thanks so much to all!
10.07.12 05:37:55 pm
Up
EngiN33R
Moderator
Offline Off
user Alistaire has written:
Hudtxt2


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

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


Would display "Example text" at the centre of the screen.
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
10.07.12 07:22:25 pm
Up
Alistaire
User
Offline Off
That'd work too yes.
IMG:http://i.imgur.com/5zhwOTP.png
11.07.12 08:41:16 pm
Up
Nhugg3t
User
Offline Off
So what's the full code?
Leave the Memories in the Past - Kamikaze87, 2012
14.08.12 07:10:20 am
Up
Marcell
Super User
Offline Off
how can i buy phone by this script?
14.08.12 12:41:18 pm
Up
Bowlinghead
User
Offline Off
Untested!
Just change the "mobile_price" value at line 10.
Code:
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
Share time limited free games here
14.08.12 01:22:59 pm
Up
Marcell
Super User
Offline Off
Thanks but possible to buy only when you in a specific building?
To the start Previous 1 Next To the start