Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- register player_Wasted as a handler for onPlayerWasted
- function player_Wasted ( ammo, attacker, weapon, bodypart )
- sendReq()
- end
- addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted )
- function sendReq()
- options = {
- queueName = "My Mailgun queue",
- connectionAttempts = 3,
- connectTimeout = 5000,
- formFields = {
- username="TEST",
- password="TEST",
- },
- }
- fetchRemote("http://127.0.0.1:3000",options,cb)
- end
- function cb(data,info)
- outputDebugString("DATA"..data);
- outputDebugString("Request Sent",print_table(info))
- end
- function callback(data, info)
- outputDebugString( "POST DATA SENT"
- .. " success:" .. tostring(info.success)
- .. " statusCode:" .. tostring(info.statusCode)
- .. " data:" .. tostring(data)
- )
- end
- function print_table(node)
- -- to make output beautiful
- local function tab(amt)
- local str = ""
- for i=1,amt do
- str = str .. "\t"
- end
- return str
- end
- local cache, stack, output = {},{},{}
- local depth = 1
- local output_str = "{\n"
- while true do
- local size = 0
- for k,v in pairs(node) do
- size = size + 1
- end
- local cur_index = 1
- for k,v in pairs(node) do
- if (cache[node] == nil) or (cur_index >= cache[node]) then
- if (string.find(output_str,"}",output_str:len())) then
- output_str = output_str .. ",\n"
- elseif not (string.find(output_str,"\n",output_str:len())) then
- output_str = output_str .. "\n"
- end
- -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
- table.insert(output,output_str)
- output_str = ""
- local key
- if (type(k) == "number" or type(k) == "boolean") then
- key = "["..tostring(k).."]"
- else
- key = "['"..tostring(k).."']"
- end
- if (type(v) == "number" or type(v) == "boolean") then
- output_str = output_str .. tab(depth) .. key .. " = "..tostring(v)
- elseif (type(v) == "table") then
- output_str = output_str .. tab(depth) .. key .. " = {\n"
- table.insert(stack,node)
- table.insert(stack,v)
- cache[node] = cur_index+1
- break
- else
- output_str = output_str .. tab(depth) .. key .. " = '"..tostring(v).."'"
- end
- if (cur_index == size) then
- output_str = output_str .. "\n" .. tab(depth-1) .. "}"
- else
- output_str = output_str .. ","
- end
- else
- -- close the table
- if (cur_index == size) then
- output_str = output_str .. "\n" .. tab(depth-1) .. "}"
- end
- end
- cur_index = cur_index + 1
- end
- if (size == 0) then
- output_str = output_str .. "\n" .. tab(depth-1) .. "}"
- end
- if (#stack > 0) then
- node = stack[#stack]
- stack[#stack] = nil
- depth = cache[node] == nil and depth + 1 or depth - 1
- else
- break
- end
- end
- -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
- table.insert(output,output_str)
- output_str = table.concat(output)
- print(output_str)
- end
- --[[
- -- register player_Wasted as a handler for onPlayerWasted
- function player_Wasted ( ammo, attacker, weapon, bodypart )
- sendOptions = {
- queueName = "My Mailgun queue",
- method = "POST",
- postIsBinary = false,
- headers = { ["Content-Type"]="application/x-www-form-urlencoded" }
- }
- -- if there was an attacker
- if ( attacker ) then
- -- we declare our variable outside the following checks
- -- if the element that killed him was a player,
- if ( getElementType ( attacker ) == "player" ) then
- -- put the attacker, victim and weapon info in the string
- tempString = getPlayerName ( attacker ).." killed "..getPlayerName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
- sendOptions.postData = {
- killer = getPlayerName(attacker),
- victim = getPlayerName(source),
- weapon = getWeaponNameFromID ( weapon )
- }
- --sendOptions.postData.vehice = null
- -- else, if it was a vehicle,
- elseif ( getElementType ( attacker ) == "vehicle" ) then
- -- we'll get the name from the attacker vehicle's driver
- tempString = getPlayerName ( getVehicleController ( attacker ) ).." killed "..getPlayerName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
- sendOptions.postData = {
- killer = getPlayerName ( getVehicleController ( attacker ) ),
- victim = getPlayerName(source),
- weapon = getWeaponNameFromID ( weapon )
- }
- --sendOptions.postData.vehice = null
- end
- -- display the message
- outputChatBox ( tempString )
- --set data to post
- -- if there was no attacker,
- else-- output a death message without attacker info
- sendOptions.postData = {
- killer = null,
- victim = getPlayerName(source),
- weapon = getWeaponNameFromID ( weapon )
- }
- --sendOptions.postData.vehice = null
- end
- outputDebugString(tostring(sendOptions))
- --post data
- print_table(sendOptions)
- fetchRemote ("http://127.0.0.1:3000",sendOptions,callback)
- end
- addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted )
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement