I took me a lot figure it out, and did not found any information on the forums, so I made a sample application that teach you how to change the weapon from a model taken from the Darkmatter 2 library, to another weapon taken from the same library.
The weapon is a limb, so If you know the limb number or the limb name, then the rest is easy.
The example is for the Agent.x model, so when you open this model in an mesh viewer (I use the one that comes with DirectX SDK) you can find out the name. For the Agent.x was "muzi", for other models It could be "weapon" or "sword"
(see attached file for a screen capture)
Once you got the name, write a routine to find the limb number, then use this number to glue and unglue the weapons.
The code explains it all.
Rem Project: ChangeWeaponSample
Rem Created: 7/29/2006 6:47:11 PM
Rem by Andrés Cavallin (Methusen's Brother)
Rem I this sample I will show how to change the weapon of one of the Darkmatter 2 characters
#constant PlayerObject = 1 `The Agent
#constant GunObject = 2 `The Gun
global PlayerGunLimb `Pointer to the original Gun limb on object
global x# `X Rotation for PlayerObject
global y# `Y Rotation for PlayerObject
global z# `Z Rotation for PlayerObject
Initialize()
LoadMainCharacter()
do
`Display menu
text 0,10,"1 - Micro UZI"
text 0,20,"2 - Ray Gun"
text 0,30,"3 - Auto Pistol"
text 0,40,"4 - Sub Tech"
`Check for pressed key
if Scancode() > 0
if Keystate(2)
`WearWeapon(CharacterObject,GunLimb,WeaponName$)
WearWeapon(PlayerObject,PlayerGunLimb,"Micro UZI")
endif
if Keystate(3)
WearWeapon(PlayerObject,PlayerGunLimb,"Ray Gun")
endif
if Keystate(4)
WearWeapon(PlayerObject,PlayerGunLimb,"Phaser")
endif
if Keystate(5)
WearWeapon(PlayerObject,PlayerGunLimb,"Auto Pistol")
endif
if Keystate(6)
WearWeapon(PlayerObject,PlayerGunLimb,"Sub Tech")
endif
REMSTART Uncomment this to add these weapons
if Keystate(7)
WearWeapon(PlayerObject,PlayerGunLimb,"Atomiser")
endif
if Keystate(8)
WearWeapon(PlayerObject,PlayerGunLimb,"Auto Gatt")
endif
if Keystate(9)
WearWeapon(PlayerObject,PlayerGunLimb,"Destructor")
endif
if Keystate(10)
WearWeapon(PlayerObject,PlayerGunLimb,"Disintergrator")
endif
if Keystate(11)
WearWeapon(PlayerObject,PlayerGunLimb,"Auto Frag")
endif
REMEND
endif
`Simple X rotate
mx = mousemovex()
my = mousemovey()
if mx<>0
y# = y# + mx
Rotate Object PlayerObject,x#,y#,z#
endif
sync
loop
function Initialize()
backdrop on
sync on
sync rate 30
hide mouse
if check display mode(1280,800,32)=1
SET DISPLAY MODE 1280,800,32
else
SET DISPLAY MODE 1024,768,32
endif
Autocam off
Set Camera Range 2,5000
endfunction
function LoadMainCharacter()
load object "mediaAgentAgent.x",PlayerObject
`Get the weapon LimbNumber
PlayerGunLimb = GetWeaponLimbNumber(PlayerObject)
rem Override some properties of the object
set object diffuse PlayerObject,rgb(255,255,255)
set object specular PlayerObject,0
rem Standard conversion for DM2 object use
xrotate object PlayerObject,270
fix object pivot PlayerObject
rem Good first view
x#=0 : y# = 150 : z# = 0
rotate object PlayerObject,x#,y#,z#
position object PlayerObject,0,0,200
position camera object position x(PlayerObject),object position y(PlayerObject)+20,object position z(PlayerObject)-150
rem Standard model animation speed
set object speed PlayerObject,15000
loop object PlayerObject
endfunction
function GetWeaponLimbNumber(CharacterObject)
n=0
do
n=n+1
if limb exist(CharacterObject,n)
`The Agent uses "muzi", but other characters may use "weapon" or "sword". So check them first with a Mesh Viewer
if limb name$(CharacterObject,n) = "muzi"
GunLimb = n
make object from limb GunObject , CharacterObject , GunLimb, 1
exit
endif
else
exit
endif
loop
if GunLimb > 0
remove limb CharacterObject,GunLimb
endif
endfunction GunLimb
function WearWeapon(CharacterObject,GunLimb,WeaponName$)
unglue object GunObject
delete object GunObject
`Put your own path, for example "mediaDisintergratorDisintergrator.x"
load object "media" + WeaponName$ + "" + WeaponName$ + ".X", GunObject
rotate object GunObject, LIMB ANGLE X (CharacterObject,GunLimb) , LIMB ANGLE Y (CharacterObject,GunLimb) , LIMB ANGLE Z (CharacterObject,GunLimb) + 90
GLUE OBJECT TO LIMB GunObject, CharacterObject, GunLimb
endfunction
I hope this helps someone.
Methusen
Playing is the very reason for life, Making games convert you in a God.