Przejdź do treści
Gothic MultiplayerMultiplayer
Gothic MP Wiki

Functions

Global functions available to both client-side and server-side scripts: eventValue.

since 0.1.31-alpha

Functions that client-side and server-side scripts both have - the same name and meaning on both sides.

Functions

eventValue

since 0.1.31-alpha
eventValue(value)

Sets the value of the event being handled - called inside an event handler. Events that take a value:

  • client "hit" - in the game that takes the damage (the victim is the local player, or a server-side NPC this game controls; offline every character): how much health the victim loses. The handler runs before the health drops, so eventValue(0) means no damage (the hit reaction still plays).
  • server "onPlayerHit" - the damage the victim gets in the end. By default it is what the victim's game applied (its own eventValue, otherwise the game's damage). A different value is applied a moment later (one exchange with the server): more damage is taken, less is given back.

Several handlers of one event: the last eventValue wins. In other events (and outside handlers) the function does nothing and returns false.

-- client.lua: the player's game takes no damage by itself - the server decides
addEventHandler("hit", function(attacker, victim, damage, hitType, weapon)
  if victim == getLocalPlayer() then eventValue(0) end
end)

-- main.lua: the server decides (damage = what the game computed, applied = what the client took)
addEventHandler("onPlayerHit", function(attackerId, victimId, damage, hitType, weapon, applied)
  if attackerId and damage > 500 then
    print("suspicious hit by " .. getPlayerName(attackerId) .. ": " .. damage)
    eventValue(0)
  else
    eventValue(damage)   -- the game's damage (without this: what the client applied, here 0)
  end
end)
ParameterTypeDescription
valuenumberThe value, 0 or more (for hits: health points).

Returns: boolean - true when the event being handled takes a value.

Na tej stronie