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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
cmd_param = {"@tp","@cancel","@accept","@decline","@sayto"}
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
function noe(id)
rp_msg2(id,"255000000","This player doesn't exists!")
end
function Array(size,value)
local array = {}
for i = 1, size do
array[i]=value
end
return array
end
function rp_msg(clr,txt)
	msg("©"..clr..""..txt)
end
function rp_msg2(id,clr,txt)
	msg2(id,"©"..clr..""..txt)
end
function ExecuteParam(id,param,txt)
	local p = totable(txt)
		local pl = tonumber(p[1])
	if param==cmd_param[1] then
			if req[id]==0 and reqs[id]==0 then
				if player(id,"health") > 0 and player(pl,"health") > 0 then
					if req[pl]==0 then
				rp_msg2(id,"000255000","Request has been sent!")
				rp_msg2(pl,"000255000","Request for teleport in coming. Say @accept or @decline")
				req[pl]=id
				reqs[id]=1
				return 1
				else
				rp_msg2(id,"255000000","He has already a request!. Tell to him to say @cancel if there is a problem")
				return 1
				end
			else
			rp_msg2(id,"255000000","Both of you must be alive!")
			return 1
			end
		else
		rp_msg2(id,"255000000","You already sent a request!")
		end
	elseif param==cmd_param[2]then
		if reqs[id]>0 then
		req[id]=0
		reqs[id]=0
		rp_msg2(id,"255255000","Cancelled!")
		return 1
		end
	elseif param==cmd_param[3]then
		if req[id]>0 then
			if player(id,"health") > 0 then
			reqs[req[id]]=0
			parse("setpos "..req[id].." "..player(id,"x").." "..player(id,"y"))
			rp_msg2(req[id],"000255000","Your request has been accepted!")
			req[id]=0
			return 1
			else
			rp_msg2(id,"255000000","You must be alive!")
			end
		elseif req[id]==0 then
			rp_msg2(id,"255000000","You don't have a request in coming!")
			return 1
		end
	elseif param==cmd_param[4]then
		if req[id]>0 then
			reqs[req[id]]=0
			rp_msg2(req[id],"255000000","Your request has been declined!")
			rp_msg2(id,"000255000","Request has been declined!")
			req[id]=0
			return 1
		elseif req[id]==0 then
			rp_msg2(id,"255000000","You don't have a request to decline!")
			return 1
		end
	elseif param==cmd_param[5]then
		if pl ~= nil then		
			if player(pl,"exists") then
				local msg= string.sub(txt, #p[1]+2, #txt)
				rp_msg2(pl,"235143041",string.format("%s (PRIVATE): %s", player(id, "name"), msg))
				rp_msg2(id,"235143041",string.format("Private message to %s: %s", player(pl, "name"), msg))
			else
				noe(id)
			end
		end
	end
end
req = Array(32,0)
reqs = Array(32,0)
addhook("join","a")
function a(id)
	req[id] = 0
	reqs[id] = 0
end
addhook("say","b")
function b(id,txt)
	if txt:sub(1,1)=="@" then
		local p = totable(txt)
		local cmd = string.lower(tostring(p[1]))
		for k, v in pairs(cmd_param) do
			if cmd==v then
				txt = string.sub(txt, #cmd+2, #txt)
				ExecuteParam(id,cmd,txt)
				return 1
			end
		end
	end
end