Deathmatch Mod (Lua)
jamesbch
Join Date: 2004-04-20 Member: 28035Members, Constellation
<div class="IPBDescription">What we need</div>Now that we can customize a little bit the game I think we can make a deathmatch mod. We could modify the lua files to do it so.
What's mandatory :
1/ Shot reaches player and we can detect it
Look for Rifle.lua @ l.161 (target)
2/ We can handle damage or do it: touched = dead
Look for Rifle.lua @ l.190 (TakeDamange ?)
3/ Add more respawn in the map / do real maps for DM (spawn random)
Look for Server.lua @ l.44 (spawn)
Better with:
1/ Step/Jumpsound !
2/ Scoreboard / Score text
3/ Better UI with HP
4/ Death animation
5/ Crouch
What do you think ? It's possible after all isn't it ?
What's mandatory :
1/ Shot reaches player and we can detect it
Look for Rifle.lua @ l.161 (target)
2/ We can handle damage or do it: touched = dead
Look for Rifle.lua @ l.190 (TakeDamange ?)
3/ Add more respawn in the map / do real maps for DM (spawn random)
Look for Server.lua @ l.44 (spawn)
Better with:
1/ Step/Jumpsound !
2/ Scoreboard / Score text
3/ Better UI with HP
4/ Death animation
5/ Crouch
What do you think ? It's possible after all isn't it ?
Comments
Wait for the beta/alpha for gameplay and all these features will already be there.
I'm working on a skulk. Biting animations and model switches are in, but that's simple enough. Looking at the model viewer the skulk run animation appears to be missing though :(
Good exercise to get familiar with the layout of their Lua code though.
@carlgm, good work on the negativity. Someone's got to do it.
Better to work on stuff that's actually going to be worthwhile and should be migrated to alpha/beta/full game. This really shouldn't be.
I bet you there's already a few mods underway which people have been planning since the announcement of NS2, and I cant wait to get my hands on them.
Making a simplistic DM-mod isnt that hard, since most of the functions needed are already implementated. Since a targetdummy already can be shot, we just need to find exactly which part handles being hit and copy that into the Player-class.
If we look in the Rifle.lua L183 it checks if there is a target and that the target has the function TakeDamage. That is the main difference between a target dummy and a player, as the Player-class lacks TakeDamage. In Target.lua L91 they define the TakeDamage functionas the following
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Target:TakeDamage(attacker, damage, doer, point, direction)
if (self.state == Target.State.Popped) then
self:PlaySound(self.dieSound)
self.state = Target.State.Killed
// Inform the game that a target was destroyed so that points
// can be awarded, etc.
Game.instance:DestroyTarget(attacker, self)
// Create a rag doll.
self:SetPhysicsActor()
// Give the target an impulse at the kill location to make it
// fly around a bit.
self.impulsePosition = point
self.impulseDirection = direction
end<!--c2--></div><!--ec2-->
Adding the following function to Player.lua should allow a player to be "hit".
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Target:TakeDamage(attacker, damage, doer, point, direction)
// Inform the game that a target was destroyed so that points
// can be awarded, etc.
Game.instance:DestroyPlayer(attacker, self)
// Note that DestroyPlayer is a new function that doesnt exsist in Game.lua, but we will fix this soon
end<!--c2--></div><!--ec2-->
In Target.lua the function seems to be defined in two ways, depending on wheter it is a client or a server. This is the server-version as it seems the client-version is only used for an aesthetical purpose.
Although a player can be "hit" we need to make sure that the game actually reacts to the hit. In the Game.lua we need to add function DestroyPlayer, similair to how the targetdummies uses the DestroyTarget-function. The following version should just add score to whoever shoots someone. (its almost a copy of how the game reacts when a target dummy is hit)
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Game:DestroyPlayer(player, target)
player.score = player.score + 1
end<!--c2--></div><!--ec2-->
This isnt a real DM though. What we want to do is somehow "respawn" a player if he or she is hit. Doing a proper respawn is quite hard, but we can circumvent this by just "teleporting" the player to a spawnpoint when the player is hit. The following is partly taken from Server.lua L25. What it does is that it finds a empty spawnpoint where we safely can teleport a player to
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Game:DestroyPlayer(player, target)
player.score = player.score + 1
// Get an unobstructured spawn point for the player.
local extents = Player.extents
local offset = Vector(0, extents.y + 0.01, 0)
repeat
spawnPoint = Shared.FindEntityWithClassname("player_start", spawnPoint)
until spawnPoint == nil or not Shared.CollideBox(extents, spawnPoint:GetOrigin() + offset)
local spawnPos = Vector(0, 0, 0)
if (spawnPoint ~= nil) then
spawnPos = Vector(spawnPoint:GetOrigin())
// Move the spawn position up a little bit so the player won't start
// embedded in the ground if the spawn point is positioned on the floor
spawnPos.y = spawnPos.y + 0.01
end
//And now we teleport the poor player to the found position
//I found the SetOrigin-function in Player.lua L407 and I hope it works like this. This is the part which i doubt the most.
target:SetOrigin(spawnPos)
end<!--c2--></div><!--ec2-->
Hopefully you'll understand what i mean, sorry if its confusing but im really bad at explaining things. There might a lot of fatal flaws in this but i think for me this code seems resonable and hopefully this can start a discussion on how to improve it.
<!--quoteo(post=1765321:date=Apr 10 2010, 06:16 PM:name=Ekhos)--><div class='quotetop'>QUOTE (Ekhos @ Apr 10 2010, 06:16 PM) <a href="index.php?act=findpost&pid=1765321"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->stuff<!--QuoteEnd--></div><!--QuoteEEnd-->
I did a very similar dirty-hack-dm to this. Basic concepts are the same - didn't see your post, but came to the same conclusions about the quickest way to get something up and running. (dirty) Code is in my other thread if you want to check it out.
Maybe our work will help them ! So while some are playing and bug-tracking others are playing with lua. I think it's the optimal way to "wait".