Jump to content

Difference between client and server-side


ÆBKV

Recommended Posts

-- CLIENT --

function consoleSetPlayerPosition ( commandName, posX, posY, posZ )
	setElementPosition ( localPlayer, posX, posY, posZ )
end
addCommandHandler ( "setpos", consoleSetPlayerPosition  )
-- SERVER --

function consoleSetPlayerPosition ( source, commandName, posX, posY, posZ )
	setElementPosition ( source, posX, posY, posZ )
end
addCommandHandler ( "setpos", consoleSetPlayerPosition  )

What is the difference between this client and server-side code?

Link to comment

Well some functions can only be used on either client-side or server-side but in your particular situation it simply means that if used client-side the position will be changed only to you, meaning that other players will not see the change. Whereas if used server-side all other players will see you in your new position.

  • Like 1
Link to comment

 

"If used client-side the position will be changed only to you, meaning that other players will not see the change. Whereas if used server-side all other players will see you in your new position."

Does that mean when I change my position, I'm still standing next to the player who was next to me?

Like a lagg, or did I misunderstand?

-- CLIENT --

function PeaceMode()
  local vehicle = getPedOccupiedVehicle(localPlayer)
  for _,p in ipairs(getElementsByType("player")) do
    for _,v in ipairs(getElementsByType("vehicle")) do
      if getElementData(localPlayer,"PeaceMode") then
        setElementCollidableWith(localPlayer,p,false)
        setElementCollidableWith(localPlayer,v,false)
        setPedWeaponSlot(localPlayer,0)
        setElementAlpha(localPlayer,230)
        setElementAlpha(p,230)
        setElementAlpha(v,230)
      else
        setElementCollidableWith(localPlayer,p,true)
        setElementCollidableWith(localPlayer,v,true)
        setElementAlpha(localPlayer,255)
        setElementAlpha(p,255)
        setElementAlpha(v,255)
      end
      if getElementData(localPlayer,"PeaceMode") and isPedInVehicle(localPlayer) then
        setElementCollidableWith(vehicle,p,false)
        setElementCollidableWith(vehicle,v,false)
      elseif not getElementData(localPlayer,"PeaceMode") and isPedInVehicle(localPlayer) then
        setElementCollidableWith(vehicle,p,true)
        setElementCollidableWith(vehicle,v,true)
      end
    end
  end
end
setTimer(PeaceMode,50,0)
-- SERVER -- 

addCommandHandler("peacemode",
function(player)
  if getElementData(player,"PeaceMode") then
    setElementData(player,"PeaceMode",false)
    toggleControl(player,"fire",true)
    toggleControl(player,"vehicle_fire",true)
    toggleControl(player,"vehicle_secondary_fire",true)
    toggleControl(player,"aim_weapon",true)
    toggleControl(player,"previous_weapon",true)
    toggleControl(player,"next_weapon",true)
    outputChatBox("[Peace Mode]: #FF0000disabled",player,255,255,0,true)
else
    setElementData(player,"PeaceMode",true)
    toggleControl(player,"fire",false)
    toggleControl(player,"vehicle_fire",false)
    toggleControl(player,"vehicle_secondary_fire",false)
    toggleControl(player,"aim_weapon",false)
    toggleControl(player,"previous_weapon",false)
    toggleControl(player,"next_weapon",false)
    outputChatBox("[Peace Mode]: #00FF00enabled",player,255,255,0,true)
  end
end
)

like here, what would happen if I do this all on the client side?

Link to comment
  • Moderators

Maybe knowing the background of both sides will help you understand why that is.

 

Serverside(code): Running on another computer/server (or application if hosted on the same pc).

Clientside(code): Every player(his computer) is called a client.

 


Between two sides there is something called ping. This it the communication delay between the client(your pc) and the server. You must have seen it in games.

 


So if you are executing code clientside, other players will not see the result, because it is are only running on your machine.

And if you are executing code serverside, other players will see the changes, because the server tells every player that something has changed. When you use a function serverside there there will be a delay before every client/player will see that something has changed. Which is related to the ping as well as to the internet speed.

 

Also some client functions have the same result as serverside functions. Like setElementPosition or setElementRotation if you use them on a player. The player(you) are streaming your position/rotation to the server. So if you change your position clientside, the server will catch up slowly because of the streaming. But if you use these functions clientside on objects, other players will not see it changed, because objects aren't streamed like players are. Yet, I think serverside should always be in control of position and rotation because it might cause lagg or de-sync.

 

 

 

 

 

Edited by IIYAMA
  • Like 1
  • Thanks 2
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...