User Tools

Site Tools


script:module:world

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
script:module:world [2019-12-22 10:54] skyjakescript:module:world [2021-08-01 04:55] (current) skyjake
Line 1: Line 1:
 +====== World (Module) ======
 +
 +Native module that provides bindings to objects in the game world.
 +
 +
 +===== Functions =====
 +
 +#@Identifier_HTML~listThings~@# ( #@Arg_HTML~Text,thingId~@# )
 +
 +Searches the map for all things of type //thingId// and returns an array of [[#World.Thing]] references.
 +
 +
 +#@Identifier_HTML~spawnThing~@# (
 + #@Arg_HTML~Text,type~@#,
 + #@Arg_HTML~Array,pos~@#,
 + #@Arg_HTML~Number,angle~@# = None,
 + #@Arg_HTML~Number,flags~@# = 0
 + )
 +
 +Spawns a new thing at the specified coordinates //pos//. The //type//  must be an existing [[ded:Thing]] ID, for example "POSSESSED".
 +
 +The //pos// can be specified either in 2D or 3D:
 +  * [350, -1000] would place the new thing on the floor at X=350, Y=-1000.
 +  * [350, -1000, 50] would place the new thing at X=350, Y=-1000, Z=50.
 +
 +Note that positions of existing things can be queried with ''Thing.pos()''.
 +
 +//angle// is the compass direction where the new thing will be facing (degrees). If None, a random direction is chosen.
 +
 +//flags// is for spawn flags. [[#flags_for_spawnthing|See the World.MSF constants.]]
 +
 +
 +===== World.Thing =====
 +
 +Base class for mobjs.
 +
 +#@Identifier_HTML~addMom~@# ( #@Arg_HTML~Array,momentum~@# )
 +
 +Modifies the momentum of the thing by adding the 3D vector //momentum//. For example, this would throw the thing up in the air a bit:
 +
 +  self.addMom([0, 0, 10])
 +
 +#@Identifier_HTML~angle~@# ( )
 +
 +(Availability: added in [[version:2.3.2]])
 +
 +Returns the angle of the thing: 0 = East, 90 = North, 180 = West, 270 = South.
 +
 +#@Identifier_HTML~attack~@# (
 + #@Arg_HTML~Number,damage~@#,
 + #@Arg_HTML~Text,missileId~@# )
 +
 +(Availability: [[version:2.2]], only in Heretic.)
 +
 +Starts the attack action of an enemy by calling the native function ''P_Attack()''. If the current target of the enemy is in the melee range, //damage// points of damage will be dealt. Otherwise, a missile is spawned. //missileId// must be a valid [[ded:Thing]] ID.
 +
 +#@Identifier_HTML~changeFlags~@# (
 + #@Arg_HTML~Number,index~@#,
 + #@Arg_HTML~Number,flags~@#,
 + #@Arg_HTML~Number,doSet~@# )
 +
 +Changes thing flags. Each thing has three 32-bit integers for storing flags: //index// is 1, 2 or 3, for ''flags'', ''flags2'' and ''flags3''. //flags// is a bitmask specifying which flags are being changed. If //doSet// evaluates to True, the flags will be set. Otherwise they will be unset.
 +
 +
 +#@Identifier_HTML~dropItem~@#
 + #@Arg_HTML~Text,type~@#, 
 + #@Arg_HTML~Number,force~@# = 1.0,
 + #@Arg_HTML~Number,lift~@# = 0.0,
 + #@Arg_HTML~Number,height~@# = 0.5,
 + #@Arg_HTML~Number,prob~@# = 1.0 )
 +
 +Spawns an item at the position of the //self// thing.
 +
 +  ; //type// : [[ded:Thing#ID|Thing definition ID]] of the dropped item.
 +  ; //force// : XY momentum of the dropped item (direction is randomly chosen).
 +  ; //lift// : Z momentum of the dropped item. Positive values cause the item to be thrown upward after being spawned.
 +  ; //height// : Spawn position Z offset. The default value 0.5 causes the item to be spawned at the middle of the dropper. 1.0 would spawn the item at the top of the dropper.
 +  ; //prob// : Chance of dropping. The default 1.0 means 100% certainty.
 +  
 +Returns the dropped thing as a World.Thing, or None.
 +
 +
 +#@Identifier_HTML~flags~@# (
 + #@Arg_HTML~Number,index~@# )
 +
 +Returns thing flags. Each thing has three 32-bit integers for storing flags: //index// is 1, 2 or 3, for ''flags'', ''flags2'' and ''flags3''.
 +
 +
 +#@Identifier_HTML~health~@# ( )
 +
 +Returns the remaining hit points of the thing (as a Number).
 +
 +#@Identifier_HTML~height~@# ( )
 +
 +Returns the current height of the thing.
 +
 +#@Identifier_HTML~id~@# ( )
 +
 +Returns the ID number of the thing.
 +
 +#@Identifier_HTML~info~@# ( )
 +
 +Returns the [[ded:Thing|definition]] of the thing.
 +
 +#@Identifier_HTML~mom~@# ( )
 +
 +Returns the 3D momentum of the thing as an array (XYZ).
 +
 +#@Identifier_HTML~player~@# ( )
 +
 +If the thing belongs to a player, returns an object representing that player (see [[script:module:App#App.Player|App.Player]]). Otherwise returns ''None''.
 +
 +#@Identifier_HTML~pos~@# ( )
 +
 +Returns the 3D position of the thing as an array (XYZ). This position is at the bottom center of the thing's bounding box.
 +
 +One can add ''Thing.height()'' to the returned Z coordinate to get the top of the thing's bounding box.
 +
 +#@Identifier_HTML~recoil~@# ( #@Arg_HTML~Number,force~@# )
 +
 +Pushes the thing backwards by //force// units. For example, the Heretic Phoenix Rod uses a recoil of 4 units. The current direction of the thing determines which direction the recoil is applied. 
 +
 +
 +#@Identifier_HTML~setAngle~@# ( #@Arg_HTML~Number,degrees~@# )
 +
 +(Availability: added in [[version:2.3.2]])
 +
 +Changes the angle of the thing to //degrees//. 0 = East, 90 = North, 180 = West, 270 = South.
 +
 +
 +#@Identifier_HTML~setNoBlocking~@# ( )
 +
 +Unsets the MF_SOLID (0x2) flag.
 +
 +
 +#@Identifier_HTML~spawnMissile~@# (
 + #@Arg_HTML~Text,id~@#,
 + #@Arg_HTML~Number,angle~@# = None,
 + #@Arg_HTML~Number,momz~@# = 0.0
 + )
 +
 +Spawns a missile originating from the thing.
 +
 +//id// is the Thing definition ID of the spawned missile.
 +
 +The //angle// is a compass direction (0...360, degrees). 0 = East, 90 = North, etc. If its value is set, the missile will use this compass direction instead of being aimed at the thing's current target object. Setting this is useful if spawning multiple missiles going in multiple directions, e.g., with 45 degree increments. A for loop could be used in the script for this purpose.
 +
 +//momz// is the vertical momentum of the missile, so this can give it a slope going up or down, but on the XY plane the speed will always be the same regardless.
 +
 +
 +
 +#@Identifier_HTML~startSound~@# (
 + #@Arg_HTML~Text,id~@#,
 + #@Arg_HTML~Number,volume~@# = 1.0 )
 +
 +Starts playing a sound using the thing as the emitter. By default, the volume is at maximum (1.0). There must be a [[ded:sound|Sound definition]] with a matching //id//.
 +
 +
 +#@Identifier_HTML~target~@# ( )
 +
 +Returns a reference to the thing's target, or None.
 +
 +
 +#@Identifier_HTML~tracer~@# ( )
 +
 +Returns a reference to the tracer thing, or None. This is typically used for homing missiles.
 +
 +
 +#@Identifier_HTML~type~@# ( )
 +
 +Returns the internal type number of the thing. This is an element index number in the [[script:module:defs#order|Defs.things.order]] array.
 +
 +Note that the [[ded:Thing|Thing definition ID]] (a text string) can be queried by ''Thing.info().id''.
 +
 +===== Constants =====
 + 
 +==== Flags for spawnThing() ====
 +
 +  ; MSF_AMBUSH : Spawn thing as deaf.
 +  ; MSF_Z_CEIL : Spawn thing in the ceiling.
 +  ; MSF_Z_FLOOR : Spawn thing at the floor.
 +
 +===== Old versions =====
 +
 +  * [[/script/module/world?rev=1576428056|2.2]]