Skip to content

Commit 2d4ac95

Browse files
Refactor syscalls into separate files (#62)
1 parent 776a64e commit 2d4ac95

11 files changed

+3121
-3005
lines changed

amx/meta.xml

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
<script src="server/util.lua" type="server" />
77
<script src="server/_triggerqueue.lua" type="server" />
88
<script src="server/rcon.lua" type="server" />
9+
10+
<script src="server/natives/a_samp.lua" type="server" />
11+
<script src="server/natives/a_objects.lua" type="server" />
12+
<script src="server/natives/a_players.lua" type="server" />
13+
<script src="server/natives/a_vehicles.lua" type="server" />
14+
<script src="server/natives/a_actors.lua" type="server" />
15+
<script src="server/natives/a_npc.lua" type="server" />
16+
<script src="server/natives/a_http.lua" type="server" />
17+
<script src="server/natives/a_sampdb.lua" type="server" />
18+
<script src="server/natives/a_mta.lua" type="server" />
19+
920
<script src="server/syscalls.lua" type="server" />
1021
<script src="server/events.lua" type="server" />
1122
<script src="server/amx.lua" type="server" />

amx/server/natives/a_actors.lua

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
-----------------------------------------------------
2+
-- Actor funcs
3+
function CreateActor(amx, model, x, y, z, rotation)
4+
local actor = createPed(model, x, y, z, rotation, false)
5+
setElementData(actor, 'amx.actorped', true)
6+
return addElem(g_Actors, actor)
7+
end
8+
9+
function DestroyActor(amx, actor)
10+
for i,playerdata in pairs(g_Players) do
11+
playerdata.streamedActors[getElemID(actor)] = nil
12+
end
13+
14+
removeElem(g_Actors, actor)
15+
destroyElement(actor)
16+
end
17+
18+
function IsActorStreamedIn(amx, actorId, player)
19+
return g_Players[getElemID(player)].streamedActors[actorId] ~= nil
20+
end
21+
22+
function ApplyActorAnimation(amx, actor, animlib, animname, fDelta, loop, lockx, locky, freeze, time)
23+
setPedAnimation(actor, animlib, animname, time, loop, lockx or locky, false, freeze)
24+
setPedAnimationSpeed(actor, animname, fDelta)
25+
end
26+
27+
function ClearActorAnimations(amx, actor)
28+
setPedAnimation(actor, false)
29+
end
30+
31+
function SetActorFacingAngle(amx, actor, ang)
32+
local rotX, rotY, rotZ = getElementRotation(actor) -- get the local players's rotation
33+
setElementRotation(actor, rotX, rotY, ang, "default", true) -- turn the player 10 degrees clockwise
34+
end
35+
36+
function GetActorFacingAngle(amx, actor, refAng)
37+
local rX, rY, rZ = getElementRotation(vehicle)
38+
writeMemFloat(amx, refAng, rZ)
39+
end
40+
41+
-- stub
42+
function SetActorInvulnerable(amx)
43+
return 1
44+
end
45+
46+
-- stub
47+
function IsActorInvulnerable(amx)
48+
return 1
49+
end
50+
51+
function IsValidActor(amx, actorId)
52+
return g_Objects[actorId] ~= nil
53+
end
54+
55+
GetActorHealth = GetPlayerHealth
56+
GetActorVirtualWorld = GetPlayerVirtualWorld
57+
58+
function GetActorPoolSize(amx)
59+
local highestId = 0
60+
for id,v in pairs(g_Actors) do
61+
if id > highestId then
62+
highestId = id
63+
end
64+
end
65+
return highestId
66+
end
67+
68+
SetActorHealth = SetPlayerHealth
69+
SetActorPos = SetPlayerPos
70+
SetActorVirtualWorld = SetPlayerVirtualWorld
71+
72+
-- stub
73+
function GetPlayerCameraTargetActor(amx)
74+
return INVALID_ACTOR_ID
75+
end

amx/server/natives/a_http.lua

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- Now we have all of RESTful types of requests. Our function is better!
2+
-- The SAMP documentation said about 'url' - "The URL you want to request. (Without 'http://')"
3+
-- I made a check. The state without a protocol is called as 'default'.
4+
-- HTTP and HTTPS you can put into URL if you want. It works fine.
5+
-- TODO: An "index" argument only for compatibility.
6+
function HTTP(amx, index, type, url, data, callback)
7+
8+
local protomatch = pregMatch(url,'^(\\w+):\\/\\/')
9+
local proto = protomatch[1] or 'default'
10+
-- if somebody will try to put here ftp:// ssh:// etc...
11+
if proto ~= 'http' and proto ~= 'https' and proto ~= 'default' then
12+
print('Current protocol is not supporting')
13+
return 0
14+
end
15+
local typesToText = {
16+
'GET',
17+
'POST',
18+
'HEAD',
19+
[-4] = 'PUT',
20+
[-5] = 'PATCH',
21+
[-6] = 'DELETE',
22+
[-7] = 'COPY',
23+
[-8] = 'OPTIONS',
24+
[-9] = 'LINK',
25+
[-10] = 'UNLINK',
26+
[-11] = 'PURGE',
27+
[-12] = 'LOCK',
28+
[-13] = 'UNLOCK',
29+
[-14] = 'PROPFIND',
30+
[-15] = 'VIEW'
31+
}
32+
local sendOptions = {
33+
queueName = "amx." .. getResourceName(amx.res) .. "." .. amx.name,
34+
postData = data,
35+
method = typesToText[tonumber(type)],
36+
}
37+
local successRemote = fetchRemote(url, sendOptions,
38+
function (responseData, responseInfo)
39+
local error = responseInfo.statusCode
40+
if error == 0 then
41+
procCallInternal(amx, callback, index, 200, responseData)
42+
elseif error >= 1 and error <= 89 then
43+
procCallInternal(amx, callback, index, 3, responseData)
44+
elseif error == 1006 or error == 1005 then
45+
procCallInternal(amx, callback, index, 1, responseData)
46+
elseif error == 1007 then
47+
procCallInternal(amx, callback, index, 5, responseData)
48+
else
49+
procCallInternal(amx, callback, index, error, responseData)
50+
end
51+
end)
52+
if not successRemote then
53+
return 0
54+
end
55+
return 1
56+
end

0 commit comments

Comments
 (0)