Welcome, Guest. Please login or register.
Did you miss your activation email?
November 23, 2024, 12:25:41 AM
Home Help Login Register
News: Trouble in Terrorist Town? Site here, forum here.

Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: A couple of coding related questions.
Pages: [1] 2
Author Topic: A couple of coding related questions.  (Read 11414 times)
Kazaki
Poster

Posts: 25



« on: January 03, 2011, 06:28:16 PM »

Hello I've been making some costum weapons for a TTT server and one of them is a HL2 turret with some settings applied to it.

------------------
local turret = ents.Create("npc_turret_floor")
for _, v in pairs(player.GetAll()) do
  if v:IsActiveTraitor() or !v:Alive() or v:IsSpec() then
      turret:AddEntityRelationship(v, D_LI, 99 )
  end
end
------------------

Here i make the turret act friendly (D_LI) towards Traitor players, players who aren't alive, and players who are spectating, but apperently the turret still shots at some type of players (Missing in action or confirmed dead or something else like players in control of props).


Also I would like to how to make the Turret Kills count as kills for the TTT Scoreboard... I believe it will be some kind of serverside code that would look like this:

------------------
function playerDies( victim, weapon, killer )
  if (killer:GetClass() == "npc_turret_floor") and (victim:IsInno()) then
      Innocentkills = Innocentkills +1
  elseif (killer:GetClass() == "npc_turret_floor") and (victim:IsActiveTraitor()) then
      TraitorKills = TraitorKills + 1
end

hook.Add( "PlayerDeath", "playerDeathTest", playerDies )
------------------

If some1 can help me with these issues plz reply ;).
NOTE: im starting to learn lua :x....

http://ldt-clan.com/forum/forum.php
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #1 on: January 03, 2011, 07:51:44 PM »

Perhaps you need to update the entity relationship when a player dies. Right now it's not friendly to innocents who are alive when the turret is created (which is correct), but when they die later on it will still not be friendly to them even though they are now spectators (which is incorrect). You could hook PlayerDeath and loop through all turret entities (ents.FindByClass) and use AddEntityRelationship there to make them be friendly to anyone who dies.

As for the second part, try doing:
turret:SetDamageOwner(ply)

After you create the turret. That ply should be the player who should get the kills, so the person who planted the turret.
Kazaki
Poster

Posts: 25



« Reply #2 on: January 03, 2011, 08:45:52 PM »

I also made another entitie called a "Pain Station" which deals dmg to a player whenever he uses it.
     
if ply:Health() > 40 then
        local new = ply:Health() - 40
       
        ply:SetHealth(new)

        self:EmitSound(healsound)

  else
    ply:Kill()
end

if i use the "SetDamageOwner(ply)" at the spawning of the entitie will the scoreboard also count kills from the pain station ?

http://ldt-clan.com/forum/forum.php
phoenixf129
Poster

Posts: 476


I Rise from the Ashes.


« Reply #3 on: January 03, 2011, 09:32:16 PM »

Use ent:TakeDamage(new, self.GetOwner(), self)

New being the health percentage that wants taking.

self.GetOwner() being the entities owner (kill attribute)

self being the entity that inflicted the damage.

You may want to Add ENT.Projectile = true as this uses the icon(I think, will have to ask bku about this)

And don't forget to ENT.Icon = "icon" so an icon is used when the guy is killed by painstation.

This is how my painstation works.

« Last Edit: January 04, 2011, 12:40:12 AM by phoenixf129 »

Software Upgrade Paradox - If you improve a piece of software enough times, you eventually ruin it.
Kazaki
Poster

Posts: 25



« Reply #4 on: January 04, 2011, 12:32:48 AM »

I've tried this:

function ENT:GiveHealth(ply)
local dmg = ply:GetMaxHealth() - ply:Health()
        local healed = self:TakeFromStorage(math.min(self.MaxHeal, dmg))

ply:TakeDamage(40, self.Owner(), self)

        self:EmitSound(healsound)

        if not table.HasValue(self.fingerprints, ply) then
            table.insert(self.fingerprints, ply)
        end
end


and this:

function ENT:GiveHealth(ply)
local dmg = ply:GetMaxHealth() - ply:Health()
        local healed = self:TakeFromStorage(math.min(self.MaxHeal, dmg))

ply:TakeDamage(40, self.Owner())

        self:EmitSound(healsound)

        if not table.HasValue(self.fingerprints, ply) then
            table.insert(self.fingerprints, ply)
        end
end


and i get the error:
[gamemodes\terrortownedited\entities\entities\ttt_pain_station\shared.lua:91] attempt to call field 'Owner' (a nil value)(Hook: KeyRelease)

http://ldt-clan.com/forum/forum.php
phoenixf129
Poster

Posts: 476


I Rise from the Ashes.


« Reply #5 on: January 04, 2011, 12:39:02 AM »

self.GetOwner() perhaps. Try that. Can't look at my exact code right now, but its probably GetOwner().

function ENT:GiveHealth(ply)
local dmg = ply:GetMaxHealth() - ply:Health()
        local healed = self:TakeFromStorage(math.min(self.MaxHeal, dmg))

ply:TakeDamage(40, self.GetOwner(), self)

        self:EmitSound(healsound)

        if not table.HasValue(self.fingerprints, ply) then
           table.insert(self.fingerprints, ply)
        end
end

The below is my code:

local healsound = Sound("items/medshot4.wav")
local failsound = Sound("items/medshotno1.wav")
function ENT:GiveHealth(ply)
if self:GetStoredHealth() > 0 then
local dmg = ply:GetMaxHealth() - ply:Health()
if ply:Health() < 31 then
ply:TakeDamage(31,self:GetOwner(),self)
else
-- constant clamping, no risks
local healed = self:TakeFromStorage(25)
local new = math.min(ply:GetMaxHealth(), ply:Health() - healed)
       
ply:TakeDamage(new,self:GetOwner(),self)
self:EmitSound(healsound)
end
end
end


Use it as reference if you will, but its basically only the health station with this function edited.

You may want to make the machine loose 40 stored 'health' points for consistency.
« Last Edit: January 04, 2011, 12:53:57 AM by phoenixf129 »

Software Upgrade Paradox - If you improve a piece of software enough times, you eventually ruin it.
Kazaki
Poster

Posts: 25



« Reply #6 on: January 04, 2011, 01:41:36 AM »

Thanks for the help ;) everything I wanted is working perfectly now.
But also since u mentioned the:

ENT.Icon  and  ENT.Projectile ( which made it possible for the "killed by pain station" icon/message to show up on corpses )

I would like to know if it is possible to make an icon like this show up for players killed by the turret.
My problem here is that the turret isn't an actual entity but an NPC that is spawned and has some settings applied to it.


http://ldt-clan.com/forum/forum.php
phoenixf129
Poster

Posts: 476


I Rise from the Ashes.


« Reply #7 on: January 04, 2011, 02:02:28 AM »

Unless you overwrite it with your own custom turret entity, I don't think so :/

Software Upgrade Paradox - If you improve a piece of software enough times, you eventually ruin it.
Kazaki
Poster

Posts: 25



« Reply #8 on: January 04, 2011, 02:48:44 AM »

Got no idea how to make an SNPC but thinking about it.. cant  i just get the script for the normal turret and name it diferently and add the stuff :x ?

though i do not know anything about SNPCs.. where the lua files go ect...

http://ldt-clan.com/forum/forum.php
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #9 on: January 04, 2011, 02:18:23 PM »

It is not possible to do the icon thing without a scripted turret entity. The game looks directly in the SWEP or SENT table to find the icon.

Honestly I'd just leave it alone for the time being. There might be a way to work around it and get a working icon for the hl2 turret kills, but it would be quite a challenge even for experienced gmod lua programmers.
Kazaki
Poster

Posts: 25



« Reply #10 on: January 04, 2011, 03:35:30 PM »

wouldnt it be possible just to copy the turrets NPC script, name it diferently and add the ENT.Icon to it ?.. though as ive saied i dont know anything about snpcs.

http://ldt-clan.com/forum/forum.php
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #11 on: January 04, 2011, 05:39:51 PM »

There is no Lua script for the turret, it's hardcoded. That is the problem.
Kazaki
Poster

Posts: 25



« Reply #12 on: January 04, 2011, 06:39:27 PM »

ah i see

http://ldt-clan.com/forum/forum.php
Kazaki
Poster

Posts: 25



« Reply #13 on: January 05, 2011, 07:53:46 PM »

eh. Hello again... i used the playerdeath hook for to make the turrets friendly to who ever dies.. but appearently it still shoots at something... i think its when ppl take control over props... is there some kind of hook for that or im just crazy ?

http://ldt-clan.com/forum/forum.php
Kazaki
Poster

Posts: 25



« Reply #14 on: January 05, 2011, 08:41:58 PM »

I believe i found the cause of this!

atm im making the turret become friendly to ppl who are traitors or specators at the spawn of the turret and making any1 who dies friendly with it.. but there are still ppl who might join a server during the round and those are not set as Friendly XD...!!!!


http://ldt-clan.com/forum/forum.php
phoenixf129
Poster

Posts: 476


I Rise from the Ashes.


« Reply #15 on: January 06, 2011, 01:07:41 AM »

Add a hook that scans for turrets already existing and adds as friendly

(PlayerInitialSpawn hook)

Software Upgrade Paradox - If you improve a piece of software enough times, you eventually ruin it.
Kazaki
Poster

Posts: 25



« Reply #16 on: January 06, 2011, 02:09:11 AM »

Maybe its better to use PlayerLoadout because ppl that join a server during a round don't actually spawn right ?

http://ldt-clan.com/forum/forum.php
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #17 on: January 06, 2011, 10:19:05 AM »

PlayerInitialSpawn has a confusing name. It has nothing to do with spawning. It is called when a player has finished joining the server. TTT turns the player into a spectator at that point, so you will want to set the player as friendly there.
phoenixf129
Poster

Posts: 476


I Rise from the Ashes.


« Reply #18 on: January 06, 2011, 04:07:01 PM »

Now its my turn to ask for a hand..

hook.Add("PlayerDeath", "Kill and RDM Checker", function(vic, infl, att)
if (vic.was_headshot == true) then
print("Headpop Debug OK!")
local rag = vic.server_ragdoll
rag:SetNetworkedInt( "InflateSize"..rag:LookupBone("ValveBiped.Bip01_Head1"), -100 )
end
end


As you can see, im trying to make it so the victims head dissapears when he is headshotted. The check passes, proven by the print. Yet, i cant get it to shrink the dead ragdolls head, because well, i think vic.server_ragdoll isn't working here.

Software Upgrade Paradox - If you improve a piece of software enough times, you eventually ruin it.
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #19 on: January 06, 2011, 04:18:46 PM »

The ragdoll is created in TTT's PlayerDeath hook. Your code will be executed before TTT's code. Hence, vic.server_ragdoll does not exist yet. Wrap it in a timer that is set to run during the next game tick, like: timer.Simple(0, function() ... end)
Pages: [1] 2
Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: A couple of coding related questions. « previous next »
Jump to:  


Login with username, password and session length

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.009 seconds with 18 queries.