Jump to content

Question


xeon17

Recommended Posts

Hello there,

I'm creating this topic because of a friend , he told me that using server side functions and events to prevent players or peds get damaged is a better way than using client side functions and events , i asked him why he think so but he no wanted to give me a answer. So my question is , which is the better way ? which way would be better for the players and server performance.

I hope someone can give me a good answer on my question :)

Regards.

Link to comment

From a performance view you should count with similar performance on your server as you have on your clients, due to that it's pretty smart to do the heavy calculations on the clients instead of the server (if possible). In the case with player and ped damage it's client side you should go for as well, client side events will trigger before the damage is set, and can therefore be blocked by cancelling the event. Doing it on the server means using timers to restore health after the ped/player is damaged, which is a huge waste of valuable performance. Here's a client example from wiki:

function cancelPedDamage ( attacker ) 
    cancelEvent() -- cancel any damage done to peds 
end 
addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage ) 

Link to comment
You can't cancel damage server side, your friend is simply wrong.

Yes ,Yes , you're true , but i didn't wrote he tried to cancel the damage on server side , also it should work with toggleControl but i didn't tried it.

addEventHandler("onPlayerDamage",root, function() 
 local god = 1 
 while(1+1 == 2) do 
  setElementData(source, "god" ..god, god) 
  god = god + 1 
 end 
end) 

From a performance view you should count with similar performance on your server as you have on your clients, due to that it's pretty smart to do the heavy calculations on the clients instead of the server (if possible). In the case with player and ped damage it's client side you should go for as well, client side events will trigger before the damage is set, and can therefore be blocked by cancelling the event. Doing it on the server means using timers to restore health after the ped/player is damaged, which is a huge waste of valuable performance. Here's a client example from wiki:

Thanks for the good answer Mr Brutus , i thought it's so but wanted to be sure

function onAfkZoneDamage ( attacker, weapon, bodypart ) 
    if source:getData("AfkZone") or attacker:getData("AfkZone") then  
        cancelEvent()  
    end 
end 
addEventHandler ( "onClientPlayerDamage", getRootElement(), onAfkZoneDamage ) 

Link to comment

That loop you got there will proceed forever as 1+1 will always be 2 ;)

If you intend to use element data for what can be assumed as a safe zone (colshape), you should set it's value to true respective false once a player enter or exit that area and then check it client side.

local safeArea = createColRectangle ( 0, 0, 15, 15 ) 
function safeEnter ( plr, matchingDimension ) 
    if getElementType ( plr ) == "player" then 
        setElementData(plr, "AfkZone", true)    
    end 
end 
addEventHandler ( "onColShapeHit", safeArea, safeEnter ) 
function safeExit ( plr, matchingDimension ) 
    if getElementType ( plr ) == "player" then 
        setElementData(plr, "AfkZone", nil) 
    end 
end 
addEventHandler ( "onColShapeLeave", safeArea, safeExit ) 

Link to comment

I know that MrBrutus , i already created my code for this today , but still thanks and sorry for wasting your time :)

----------------------------------------------------- 
-- @script  AFK Zones (Server) 
-- @author XeoN 
-- @version 1.0 
-- @update 17.01.2015 
----------------------------------------------------- 
  
-- Blip ,RadarArea,Colshape 
  
  
AfkZoneLVBLIP = Blip.create(1876.12769, 2308.55151, 24.11217,49) 
AfkZoneLVBLIP:setVisibleDistance(300) 
AfkZoneLVRadarArea = RadarArea.create(1835.53528, 2283.05396,80,80,255,0,0,255) 
AfkZoneLVColshape = ColShape.Rectangle(1835.53528, 2283.05396,80,80) 
AfkZoneLVColshape:setData("isAfkZone",true) 
  
           function onAfkZoneEnter (thePlayer) 
           if (getElementType(thePlayer) == "player") then 
           if source:getData("isAfkZone") then 
           exports["TopBarChat"]:sendClientMessage("Afk Zone: Welcome in a Afk Zone.", thePlayer, 255, 0, 0) 
           thePlayer:setData("AfkZone",true) 
         end 
    end 
end         
addEventHandler ( "onColShapeHit", getRootElement(), onAfkZoneEnter ) 
  
           function onAfkZoneLeave (thePlayer) 
           if (getElementType(thePlayer) == "player") then 
           if source:getData("isAfkZone") then 
            exports["TopBarChat"]:sendClientMessage("Afk Zone: You left a Afk Zone.", thePlayer, 255, 0, 0) 
           if thePlayer:getData("AfkZone") then 
           thePlayer:setData("AfkZone",false) 
           end 
       end 
   end 
end 
addEventHandler ( "onColShapeLeave", getRootElement(), onAfkZoneLeave ) 
  
 local player = getPlayerFromName("XeoN") 
 player:giveWeapon(31,500,true) 

Edited by Guest
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...