Jump to content

sendMessageToAdmins on client side?


Recommended Posts

Hello everyone! So I made a little script which is warns you if you punch the car with fist. But I want to make it to send a message to admins with a player name when somebody punches a car. But I don't know how can I make sendMessageToAdmins as a client side function, or how to trigger the client side things to server side and then in server side make the message to send. Can somebody help me in this please? Thank you!

Link to comment

Hmm not sure but maybe try this.

-- Client Sided

  
  
addEventHandler("onClientVehicleDamage", root, 
  
function (attacker, weapon, loss, x, y, z, tyre) 
 local veh = getVehicleController ( source ) or source 
local theKiller = getPlayerName ( attacker ) 
local thePSource =  getPlayerName ( veh ) 
    for _, v in ipairs( getElementsByType ( "player" ) ) do  
     if getElementData ( v, "adminism") == "Admin" then 
triggerServerEvent (v, "onAdminMessageRec", v, tostring ( theKiller ), tostring ( thePSource ) ) -- source is admin ^ 
         end 
    end 
end 
) 

-- Server Sided

  
  
   for _, v in ipairs( getElementsByType ( "player" ) ) do  
  local accName = getAccountName ( getPlayerAccount ( v ) )  
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then  
setElementData ( v, "adminism", "Admin") 
end 
end 
  
addEventHandler("onPlayerJoin", getRootElement(), 
      local accName = getAccountName ( getPlayerAccount ( source ) )  
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then  
setElementData ( source, "adminism", "Admin") 
    end 
end 
) 
  
addEvent ("onAdminMessageRec", true ) 
addEventHandler ("onAdminMessageRec", getRootElement(), 
function ( theKiller, thePSource ) 
 outputChatBox (  theKiller.." has punched ".. thePSource .."'s Vehicle", source, 255, 255, 0, false )  
end ) 

Edited by Guest
Link to comment

LOoooool!!

Did you read outputChatBox client arguments?

  
  
  
addEventHandler("onClientVehicleDamage", root, 
  
function (attacker, weapon, loss, x, y, z, tyre) 
 local veh = getVehicleController ( source ) or source 
    for _, v in ipairs( getElementsByType ( "player" ) ) do 
     if getElementData ( v, "adminism") == "Admin" then 
 outputChatBox (  getPlayerName ( attacker ).." has punched ".. getPlayerName ( veh ).."'s Vehicle", 255, 255, 0, false ) 
-- Only admins will see this 
         end 
    end 
end 
) 
  

Link to comment
LOoooool!!

Did you read outputChatBox client arguments?

  
  
  
addEventHandler("onClientVehicleDamage", root, 
  
function (attacker, weapon, loss, x, y, z, tyre) 
 local veh = getVehicleController ( source ) or source 
    for _, v in ipairs( getElementsByType ( "player" ) ) do 
     if getElementData ( v, "adminism") == "Admin" then 
 outputChatBox (  getPlayerName ( attacker ).." has punched ".. getPlayerName ( veh ).."'s Vehicle", 255, 255, 0, false ) 
-- Only admins will see this 
         end 
    end 
end 
) 
  

I fixed it already. :wink:

Link to comment

Doesn't work :( But I have an admin system and globals. I'm asking that how could I make exports.global:sendMessageToAdmins client sided or how to connect the client functions, (when somebody punches a vehicle) with server function (what I'm asking for [the exports.global bla bla] ). I have a client sided script only:

addEventHandler("onClientVehicleDamage", root, 
function (attacker,weapon) 
    if attacker == localPlayer and weapon == 0 then 
        exports.notifications:showBox( 'warning', "Ne üsd a kocsikat! Ha folytatod üzenet lesz küldve az adminok számára és gondok is lehetnek belőle!") 
    end 
    if attacker then 
        cancelEvent() 
    end 
end) 

So how can I attach exports.global:sendMessageToAdmins to this script?

Link to comment

Well, you can create an exported function with a triggerServerEvent. Like:

--client 
function sendMessageToAdmins ( message ) 
    local send = triggerServerEvent( "onClientMessageSend", root, message ) 
    if send then 
        return true 
    end 
    return false 
end 
  
--server 
addEvent ( "onClientMessageSend", true ) 
addEventHandler("onClientMessageSend", root, function ( message ) 
    local players = exports.pool:getPoolElementsByType("player") 
     
    for k, thePlayer in ipairs(players) do 
        if (exports.global:isPlayerAdmin(thePlayer)) then 
            outputChatBox(tostring(message), thePlayer, 255, 0, 0) 
        end 
    end 
end 

That's how I would do it.

Link to comment

Client side

  
 addEventHandler("onClientVehicleDamage", root, 
  
function (attacker, weapon, loss, x, y, z, tyre) 
if weapon == 0 then 
 local veh = getVehicleController ( source ) or source 
  
local theKiller = getPlayerName ( attacker ) 
  
local thePSource =  getPlayerName ( veh ) 
  
    for _, v in ipairs( getElementsByType ( "player" ) ) do  
  
     if getElementData ( v, "adminism") == "Admin" then 
  
triggerServerEvent (v, "onAdminMessageRec", v, tostring ( theKiller ), tostring ( thePSource ) ) -- source is admin ^ 
  
         end 
     end 
    end 
  
end 
  
) 

server side

  
  
  
   for _, v in ipairs( getElementsByType ( "player" ) ) do  
  
  local accName = getAccountName ( getPlayerAccount ( v ) )  
  
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then  
  
setElementData ( v, "adminism", "Admin") 
else 
setElementData ( v, "adminism", nil) 
  
end 
  
end 
  
  
  
addEventHandler("onPlayerJoin", getRootElement(), 
  
      local accName = getAccountName ( getPlayerAccount ( source ) )  
  
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then  
  
setElementData ( source, "adminism", "Admin") 
else 
setElementData ( source, "adminism", nil) 
  
    end 
  
end 
  
) 
  
  
  
addEvent ("onAdminMessageRec", true ) 
  
addEventHandler ("onAdminMessageRec", getRootElement(), 
  
function ( theKiller, thePSource ) 
  
 outputChatBox (  theKiller.." has punched ".. thePSource .."'s Vehicle", source, 255, 255, 0, false )  
  
end ) 

It should work this time if still no Luck then débug the script.

Link to comment
Client side
  
 addEventHandler("onClientVehicleDamage", root, 
  
function (attacker, weapon, loss, x, y, z, tyre) 
if weapon == 0 then 
 local veh = getVehicleController ( source ) or source 
  
local theKiller = getPlayerName ( attacker ) 
  
local thePSource =  getPlayerName ( veh ) 
  
    for _, v in ipairs( getElementsByType ( "player" ) ) do  
  
     if getElementData ( v, "adminism") == "Admin" then 
  
triggerServerEvent (v, "onAdminMessageRec", v, tostring ( theKiller ), tostring ( thePSource ) ) -- source is admin ^ 
  
         end 
     end 
    end 
  
end 
  
) 

server side

  
  
  
   for _, v in ipairs( getElementsByType ( "player" ) ) do  
  
  local accName = getAccountName ( getPlayerAccount ( v ) )  
  
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then  
  
setElementData ( v, "adminism", "Admin") 
else 
setElementData ( v, "adminism", nil) 
  
end 
  
end 
  
  
  
addEventHandler("onPlayerJoin", getRootElement(), 
  
      local accName = getAccountName ( getPlayerAccount ( source ) )  
  
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then  
  
setElementData ( source, "adminism", "Admin") 
else 
setElementData ( source, "adminism", nil) 
  
    end 
  
end 
  
) 
  
  
  
addEvent ("onAdminMessageRec", true ) 
  
addEventHandler ("onAdminMessageRec", getRootElement(), 
  
function ( theKiller, thePSource ) 
  
 outputChatBox (  theKiller.." has punched ".. thePSource .."'s Vehicle", source, 255, 255, 0, false )  
  
end ) 

It should work this time if still no Luck then débug the script.

He is using vG, this makes no sense.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...