Difference between revisions of "Manual:DIL Manual/set weight"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
= set_weight( u : unitptr, lbs : integer ) =
+
= set_weight() =
 +
'''Procedure.''' Sets a unit's total weight.
  
−
''' Parameters '''
+
set_weight(u : unitptr, weight : integer)
−
  u : the unit on which you wish to alter the weight.
 
−
  lbs : the new weight in pounds (½ kg)
 
  
−
''' Description '''
+
Sets the [[Manual:DIL Manual/weight|weight]] of <code>u</code>, and changes the weight of every
−
Use this procedure on a unit to change it's weight (not the base
+
unit it is in by the same amount. Its [[Manual:DIL Manual/baseweight|baseweight]] stays as it is.
−
weight).
 
  
 +
A unit's weight should be its base weight plus the weight of what is inside it, and the server
 +
keeps it so as things move in and out. To make something heavier or lighter, use
 +
[[Manual:DIL Manual/set weight base|set_weight_base()]]; <code>set_weight()</code> is for putting
 +
a weight right that has gone wrong, as <code>fixweight</code> in basis.zon does.
  
−
See also:
+
== Parameters ==
−
  [[Manual:DIL_Manual/set_weight_base|set_weight_base()]]
+
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| u || unitptr || The unit.
 +
|-
 +
| weight || integer || Its new weight, in pounds.
 +
|}
 +
 
 +
== Notes ==
 +
* Works on every kind of unit. With a null unit nothing happens.
 +
* A weight below the base weight is set anyway, with a line in the zone log ("setting unit ... weight to ... less than base weight").
 +
* Afterwards the server goes on adding and subtracting what moves in and out, so a wrong weight stays wrong.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin fix_weight(u : unitptr);
 +
var
 +
  item : unitptr;
 +
  wgt : integer;
 +
code
 +
{
 +
  item := u.inside;
 +
  while (item != null)
 +
  {
 +
      wgt := wgt + item.weight;
 +
      item := item.next;
 +
  }
 +
  if (u.weight != u.baseweight + wgt)
 +
  {
 +
      log(u.symname + " weight " + itoa(u.weight) + " should be " +
 +
          itoa(u.baseweight + wgt) + ". Resetting.");
 +
      set_weight(u, u.baseweight + wgt);
 +
  }
 +
  return;
 +
}
 +
dilend
 +
</pre>
 +
Puts a container's weight right: its base weight plus what is in it, as in basis.zon.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/set weight base|set_weight_base()]]
 +
* [[Manual:DIL Manual/weight|weight]]
 +
* [[Manual:DIL Manual/baseweight|baseweight]]

Latest revision as of 23:21, 14 November 2026

set_weight()

Procedure. Sets a unit's total weight.

set_weight(u : unitptr, weight : integer)

Sets the weight of u, and changes the weight of every unit it is in by the same amount. Its baseweight stays as it is.

A unit's weight should be its base weight plus the weight of what is inside it, and the server keeps it so as things move in and out. To make something heavier or lighter, use set_weight_base(); set_weight() is for putting a weight right that has gone wrong, as fixweight in basis.zon does.

Parameters

Name Type Meaning
u unitptr The unit.
weight integer Its new weight, in pounds.

Notes

  • Works on every kind of unit. With a null unit nothing happens.
  • A weight below the base weight is set anyway, with a line in the zone log ("setting unit ... weight to ... less than base weight").
  • Afterwards the server goes on adding and subtracting what moves in and out, so a wrong weight stays wrong.

Example

dilbegin fix_weight(u : unitptr);
var
   item : unitptr;
   wgt : integer;
code
{
   item := u.inside;
   while (item != null)
   {
      wgt := wgt + item.weight;
      item := item.next;
   }
   if (u.weight != u.baseweight + wgt)
   {
      log(u.symname + " weight " + itoa(u.weight) + " should be " +
          itoa(u.baseweight + wgt) + ". Resetting.");
      set_weight(u, u.baseweight + wgt);
   }
   return;
}
dilend

Puts a container's weight right: its base weight plus what is in it, as in basis.zon.

See also