Jump to content

Server-side or client-side for this?


Cronoss

Recommended Posts

I want to make a "damage system", but I just realized that I'm triggering a serverEvent everytime the player """"dies"""", the event only contains setPedAnimation 

So... i don't know if this is necessary, I know I could make the same system on server side using "onPlayerDamage"(that way I'm not triggering an event just for animation), but i want to optimize this as much as i can.

function playerWasted(attacker, damage)
	local health = getElementHealth(localPlayer) or 1
	if health - damage <= 1 then
		if getElementData(localPlayer, "wasted.player") ~= 1 then 
			cancelEvent()
			setElementData(localPlayer, "wasted.player", 1, false)
			setElementFrozen(localPlayer, true)
			triggerServerEvent("wastedEvent", localPlayer, localPlayer) -- necessary?
      --

The final question is; I should make the script again on server side, or keep it like this?(client-side) ^

Link to comment

actually everything looks right here, if you want to cancel this event, I say go to the client side, but the onPlayerDamage event cannot be canceled and will be ineffective when you animate the player, so your code looks correct, but you can delete the second localPlayer parameter in the triggerServerEvent, instead use the source inside the server event

triggerServerEvent("wastedEvent", localPlayer) --use source on server side so no second localPlayer parameter is required

 

  • Thanks 1
Link to comment

In this case, I made the animation part in server-side so all the players can see the animation but for some reason the player can "cancel" the animation even if I set FALSE the interruptable part. What's the problem in this?

setPedAnimation(source, "crack", "crckdeth1", -1, false, false, false, true)
								--should make it interruptable

 

Link to comment

What you can do is:

On server side

  1. Make a temporary ped using event "wastedEvent".
  2. Make this ped have the same features of the player dieing (skin, rotation) etc.
  3. Make ped collison disabled. (makes ped free from damage from other elements)
  4. Set the alpha of player to 0 and make him froze.
  5. Perform the animation on the ped.
  6. Afterwards destroy ped and reset alpha on player respawn.

 

Edited by Ayush Rathore
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...