forked from Devieth/Halo-Lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.lua
146 lines (132 loc) · 4.13 KB
/
commands.lua
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
-- Commands by Devieth.
-- Script for SAPP
api_version = "1.10.0.0"
-- Vanished player list
player_vanished = {}
player_respawn_time = {}
function OnScriptLoad()
register_callback(cb['EVENT_TICK'], "OnEventTick")
register_callback(cb['EVENT_COMMAND'], "OnEventCommand")
register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
end
function OnScriptUnload() end -- We need this cause SAPP.
function OnEventCommand(PlayerIndex, Command, Enviroment, Password)
-- Make 'Message' a local and default it to false to prevent blocking other commands.
local Message = false
-- Tokenize the string (and remove quotations.)
local t = tokenizestring(string.lower(string.gsub(Command, '"', "")), " ")
-- Get command mode (enable or disable.)
local Command, Mode = process_command(t[1])
-- Are they an admin or is this being executed from the console.
if get_var(PlayerIndex, "$lvl") ~= "-1" or Enviroment == "0" then
if Command == "vanish" then
-- Execute the command.
Message = command_vanish(t[2], PlayerIndex, Mode)
elseif Command == "resp" then
Message = command_respawn_time(t[2], PlayerIndex, t[3])
Allow = false
end
end
-- Wes a message return from the command.
if Message then
-- Return result to the executer.
rcon_return(tonumber(Enviroment), PlayerIndex, Message)
return false
end
end
function OnEventTick()
for i = 1,16 do
if player_present(i) then
if player_vanished[i] then
-- Set player's visable bipd Z coord below the map.
write_float(get_player(i) + 0x100, -1000)
end
end
end
end
function OnPlayerDeath(VictimIndex, KillerIndex)
if player_respawn_time[tonumber(VictimIndex)] then
-- Set player respawn time.
write_dword(get_player(VictimIndex) + 0x2C, player_respawn_time[tonumber(VictimIndex)] * 30)
end
end
function command_vanish(TargetIndex, UserIndex, Mode)
-- Is there a target?
if TargetIndex then
-- If so make sure they are a valid target.
local PlayerIndex = get_valid_player(TargetIndex, UserIndex)
if PlayerIndex then
-- Mode 1 = enable
if Mode == 1 then
player_vanished[PlayerIndex] = true
return get_name(PlayerIndex).. " has vanished."
else -- mode 0 = disable
player_vanished[PlayerIndex] = false
return get_name(PlayerIndex).. " has unvanished."
end
end
return "Error: Player is not present."
end
return "Error: No player specified."
end
function command_respawn_time(TargetIndex, UserIndex, Time)
if TargetIndex then
local PlayerIndex = get_valid_player(TargetIndex, UserIndex)
if PlayerIndex then
if tonumber(Time) then
player_respawn_time[PlayerIndex] = tonumber(Time)
return get_name(PlayerIndex).."'s respawn time set to "..tonumber(Time).." seconds."
end
player_respawn_time[PlayerIndex] = nil
return get_name(PlayerIndex).."'s respawn time has been reset."
end
return "Error: Player is not present."
end
return "Error: No player specified."
end
function get_name(PlayerIndex)
return get_var(PlayerIndex, "$name")
end
function get_valid_player(Player, UserIndex)
local PlayerIndex = nil
if Player ~= nil then
if string.lower(Player) == "me" then
return tonumber(UserIndex)
end
if tonumber(Player) then
if tonumber(Player) > 0 and tonumber(Player) < 17 then
if player_present(tonumber(Player)) then
PlayerIndex = tonumber(Player)
end
end
end
end
return PlayerIndex
end
function rcon_return(Enviroment, PlayerIndex, Message)
local Compatable_Message = string.gsub(tostring(Message), "|t", " ")
if Enviroment == 0 then -- Console
cprint(Compatable_Message,14)
elseif Enviroment == 1 then -- Rcon
rprint(PlayerIndex, Message)
elseif Enviroment == 2 then -- Chat
say(PlayerIndex, Compatable_Message)
end
end
function process_command(Command)
if string.sub(Command, 1,2) == "un" then
return string.sub(Command, 3, string.len(Command)), 0
end
return Command, 1
end
function tokenizestring(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end