ETMods.net

N!tmod, a Wolfenstein: Enemy Territory Modification!

You are not logged in.

Announcement

You can donate to help us keeping services online.

#1 16-Feb-14 20:54:11

Doc
BETA Tester
Registered: 23-Feb-11
Posts: 30
Website

Command /kill Next time remaining of spawn

Hello!
I had the idea of limiting the /kill command with time remaining of spawn. So I find a lua and I edit this.

But the problem I have is that I can't get it to work properly. I have no error message and yet I do not have the limitation ..

Knowing little about the lua, I can't find my mistakes.

If a kind soul goes through the..

This is my lua :

function et_ClientSpawn(client, revived)
    level_time = levelTime
    init_time = leveltime
    players = { }
    players[0] = 0 --all
    players[1] = 0 --axis
    players[2] = 0 --allies
    players[3] = 0 --spectators
	
  -- pre SELFKILL restriction
    if revived == 0 then
        players["lastspawn"] = et.gentity_get(client, "pers.lastSpawnTime")
    end

  -- SELFKILL restriction
    if command == "kill" then
        local game_state = tonumber(et.trap_Cvar_Get("gamestate"))

    if game_state ~= 1 and game_state ~= 2 then
        local player_ingame = level_time - players["lastspawn"]
	    local player_team = et.gentity_get(client, "sess.sessionTeam")
		local player_respawn;
     
    if player_team == 1 then
        player_respawn = tonumber(et.trap_Cvar_Get("g_redlimbotime"))
    elseif player_team == 2 then
        player_respawn = tonumber(et.trap_Cvar_Get("g_bluelimbotime"))
    end
     
    player_ingame = math.mod(player_ingame, player_respawn)
     
    if ( player_respawn - player_ingame ) > 3000 and ( players["lastspawn"] - init_time ) > player_respawn then
        et.trap_SendServerCommand(client, "chat \SELFKILLS are allowed only before respawn.\"")
    return 1
    end
    end

    return 0
  end
end

Thank you in advance cordially Doc!

Offline

#2 18-Feb-14 12:37:24

Doc
BETA Tester
Registered: 23-Feb-11
Posts: 30
Website

Re: Command /kill Next time remaining of spawn

Maybe with this lua? After some modification the script works a half.

It works only on the first connection, and when the map changes, it no longer works. :<

function et_InitGame(leveltime, randomseed, restart)
    init_time = leveltime
	players = { }
	players[0] = 0 --all
	players[1] = 0 --axis
	players[2] = 0 --allies
	players[3] = 0 --spectators
end

function et_ClientSpawn(client, revived)
    -- pre SELFKILL restriction
    if revived == 0 then
        players_lastspawn = et.gentity_get(client, "pers.lastSpawnTime")
    end
end
  -- SELFKILL restriction

function et_ClientCommand(client, command)
    if string.lower(command) == "kill" then
        local game_state = tonumber(et.trap_Cvar_Get("gamestate"))

    if game_state ~= 1 and game_state ~= 2 then
        local player_ingame = level_time - players_lastspawn
        local player_team = et.gentity_get(client, "sess.sessionTeam")
        local player_respawn;
     
    if player_team == 1 then
        player_respawn = tonumber(et.trap_Cvar_Get("g_redlimbotime"))
    elseif player_team == 2 then
        player_respawn = tonumber(et.trap_Cvar_Get("g_bluelimbotime"))
    end
     
    player_ingame = math.mod(player_ingame, player_respawn)
     
    if ( player_respawn - player_ingame ) > 3000 and ( players_lastspawn - level_time ) > player_respawn then
        et.trap_SendServerCommand(client, "chat \"SELFKILLS are allowed only 3 seconds before respawn.\"")
    return 1 
    end
    end
    end
return 0
end

function et_RunFrame(levelTime)
    level_time = levelTime
end

Last edited by Doc (18-Feb-14 20:52:43)

Offline

#3 18-Feb-14 22:15:01

Micha
Member
From: Germany
Registered: 11-Feb-13
Posts: 38
Website

Re: Command /kill Next time remaining of spawn

Hello Doc, I tried your lua and I reworked it a bit. I couldn't get it fully working yet. maybe we will find a solution for first spawn.
Atleast it is fully working after first player spawn.

spawnvalue = 	3 			--disable /kill before next respawn [sec]

printplace = 	"chat"		--print position of msg
msg = 			"^3SELFKILLS ^naren't allowed ^3"..spawnvalue.." ^nseconds before respawn."

---------------------------------------------------------------------------------------------------------------

Modname = "kill"
Version = "0.1"

samplerate = 1000 --convert refresh rate ms to sec
players_lastspawn = {}

function et_InitGame(leveltime, randomseed, restart)
    et.G_Print("^z["..Modname.."^z] Version:"..Version.." Loaded\n")
    et.RegisterModname(et.Q_CleanStr(Modname).."   "..Version.."   "..et.FindSelf())
	gamestate = tonumber(et.trap_Cvar_Get("gamestate"))
end

function et_ClientSpawn(client, revived)
    -- pre SELFKILL restriction
	local player_team = et.gentity_get(client, "sess.sessionTeam")
     
	if player_team == 1 then
		player_respawn = tonumber(et.trap_Cvar_Get("g_redlimbotime"))
	elseif player_team == 2 then
		player_respawn = tonumber(et.trap_Cvar_Get("g_bluelimbotime"))
	end
	
    if revived == 0 then
        players_lastspawn[player_respawn] = et.gentity_get(client, "pers.lastSpawnTime")
    end
end
  
function et_RunFrame(levelTime)
	if math.mod(levelTime, samplerate) ~= 0 then return end --slows down the update of leveltime
	leveltime = levelTime
end

function et_ClientCommand(client, command)
	local teamnumber = tonumber(et.gentity_get(client,"sess.sessionTeam"))
	local playershp = tonumber(et.gentity_get(client,"health"))
    if string.lower(command) == "kill" and teamnumber ~= 3 and playershp > 0 then -- SELFKILL restriction

		local player_team = et.gentity_get(client, "sess.sessionTeam")
     
		if player_team == 1 then
			player_respawn = tonumber(et.trap_Cvar_Get("g_redlimbotime"))
		elseif player_team == 2 then
			player_respawn = tonumber(et.trap_Cvar_Get("g_bluelimbotime"))
		end
	
        local player_ingame = leveltime - players_lastspawn[player_respawn]
     
		local spawntimer = (player_respawn - math.mod(player_ingame, player_respawn))
		
		--et.trap_SendServerCommand(client, "chat \"Debug spawntimer: "..spawntimer.."\"") --debug line
		if spawntimer < (spawnvalue*1000) then
			et.trap_SendServerCommand(client, string.format(""..printplace.."  \""..msg..""))
			return 1 
		end
    end
	return 0
end

Offline

#4 18-Feb-14 23:02:25

Doc
BETA Tester
Registered: 23-Feb-11
Posts: 30
Website

Re: Command /kill Next time remaining of spawn

Yes it is already that, thank you to you. I'll keep looking.
Ok, I tested your lua, and it seems to work.

I just added this :

 if string.lower(command) == "kill" or string.lower(command) == "kill; forcetapout"

It's pretty cool, it works well!

Last edited by Doc (19-Feb-14 12:02:32)

Offline

#5 21-Feb-14 17:03:59

Doc
BETA Tester
Registered: 23-Feb-11
Posts: 30
Website

Re: Command /kill Next time remaining of spawn

Plop !
I do not know if it changes some things, but after adding:

	maxclients = tonumber( et.trap_Cvar_Get( "sv_maxClients" ) )

End :

	players_lastspawn = {}
	for i = 0, maxclients - 1 do
		players_lastspawn[i] = 0
	end

The kill is restricted to the first part. Is this correct?

spawnvalue = 	5 			--disable /kill before next respawn [sec]
printplace = 	"chat"		--print position of msg
msg = 			"^3SELFKILLS ^naren't allowed ^3"..spawnvalue.." ^nseconds before respawn." --^3"..spawnvalue.."

---------------------------------------------------------------------------------------------------------------

Modname = "kill"
Version = "0.1"

samplerate = 1000 --convert refresh rate ms to sec
--players_lastspawn = {}

function et_InitGame(leveltime, randomseed, restart)
    et.G_Print("^z["..Modname.."^z] Version:"..Version.." Loaded\n")
    et.RegisterModname(et.Q_CleanStr(Modname).."   "..Version.."   "..et.FindSelf())
	maxclients = tonumber( et.trap_Cvar_Get( "sv_maxClients" ) )
	gamestate = tonumber(et.trap_Cvar_Get("gamestate"))
	players_lastspawn = {}
	for i = 0, maxclients - 1 do
		players_lastspawn[i] = 0
	end
end

function et_ClientSpawn(client, revived)
    -- pre SELFKILL restriction
	local player_team = et.gentity_get(client, "sess.sessionTeam")
     
	if player_team == 1 then
		player_respawn = tonumber(et.trap_Cvar_Get("g_redlimbotime"))
	elseif player_team == 2 then
		player_respawn = tonumber(et.trap_Cvar_Get("g_bluelimbotime"))
	end
	
    if revived == 0 then
        players_lastspawn[player_respawn] = et.gentity_get(client, "pers.lastSpawnTime")
    end
end
  
function et_RunFrame(levelTime)
	if math.mod(levelTime, samplerate) ~= 0 then return end --slows down the update of leveltime
	leveltime = levelTime
end

function et_ClientCommand(client, command)
	local teamnumber = tonumber(et.gentity_get(client,"sess.sessionTeam"))
	local playershp = tonumber(et.gentity_get(client,"health"))
    if string.lower(command) == "kill" or string.lower(command) == "kill; forcetapout" and teamnumber ~= 3 and playershp > 0 then -- SELFKILL restriction

		local player_team = et.gentity_get(client, "sess.sessionTeam")
     
		if player_team == 1 then
			player_respawn = tonumber(et.trap_Cvar_Get("g_redlimbotime"))
		elseif player_team == 2 then
			player_respawn = tonumber(et.trap_Cvar_Get("g_bluelimbotime"))
		end
	
        local player_ingame = leveltime - players_lastspawn[player_respawn]
     
		local spawntimer = (player_respawn - math.mod(player_ingame, player_respawn))
		
		--et.trap_SendServerCommand(client, "chat \"Debug spawntimer: "..spawntimer.."\"") --debug line
		if spawntimer < (spawnvalue*1000) then --(spawnvalue*1000)
			et.trap_SendServerCommand(client, string.format(""..printplace.."  \""..msg..""))
			return 1 
		end
    end
	return 0
end

Offline

#6 21-Feb-14 21:23:12

N!trox*
Administrator
Registered: 30-Mar-10
Posts: 1,098

Re: Command /kill Next time remaining of spawn

players_lastspawn[] is an array that contains last spawn time for each players (from 0 to 63), here you're using "player_respawn" as an index, instead of the clientNum, so this will definitely cause some problems.

Use

players_lastspawn[client]

instead of

players_lastspawn[player_respawn]

and i bet it should work.


iluvnitmod.png

Offline

#7 21-Feb-14 22:22:53

Doc
BETA Tester
Registered: 23-Feb-11
Posts: 30
Website

Re: Command /kill Next time remaining of spawn

Hi Nitrox !
He works, but not the first spawn that's what I try to "correct", but I can not find how. :<

If a person don't kills us, the / kill does not work the first respawn

EDIT :
I have retest :
During the warmup, I can kill me from 2 seconds, same for the first spawn. But after then it does not work. Infact if, but the time of / kill is completely shifted.  It' strange O.o

I understand nothing xD

Last edited by Doc (21-Feb-14 23:10:44)

Offline

#8 22-Feb-14 16:19:11

Doc
BETA Tester
Registered: 23-Feb-11
Posts: 30
Website

Re: Command /kill Next time remaining of spawn

Infact during the warmup and the first spawn, he does not calculate the exact time, he takes the values 30 (axis) and 20 (allies) per default.
This is why we can not kill ...

I'm not sure that it is feasible in lua :<


if you use

sess.spawnObjectiveIndex

it may function better?

Last edited by Doc (22-Feb-14 21:15:47)

Offline

#9 23-Feb-14 21:08:02

Doc
BETA Tester
Registered: 23-Feb-11
Posts: 30
Website

Re: Command /kill Next time remaining of spawn

Ok, I found a solution for the 1st spawn and i have deactivated the announce for warmup, even if it's not super.
For the first / kill I added a prevention message.

EDIT : Update lua

spawnvalue = 	5 			--disable /kill before next respawn [sec]
printplace = 	"cp"		--print position of msg
msg = 			"^3SELFKILLS ^naren't allowed ^3"..spawnvalue.." ^nseconds before respawn." 

msg2 =          "^1Warning, your next selfkill will be limited."

---------------------------------------------------------------------------------------------------------------

Modname = "kill"
Version = "0.1"
selfkill_limit = 0
samplerate = 1000 --convert refresh rate ms to sec
players_lastspawn = {}

function et_InitGame(leveltime, randomseed, restart)
    et.G_Print("^z["..Modname.."^z] Version:"..Version.." Loaded\n")
    et.RegisterModname(et.Q_CleanStr(Modname).."   "..Version.."   "..et.FindSelf())
	local gamestate = tonumber(et.trap_Cvar_Get("gamestate"))
	maxclients = tonumber( et.trap_Cvar_Get( "sv_maxClients" ) )	--gets the maxclients
		skcount = {}
		for i = 0, maxclients - 1 do
			skcount[i] = 0
		end
end

function et_ClientDisconnect( clientNum )
	skcount[clientNum] = 0
end

function et_Obituary( victim, killer, meansOfDeath )
if tonumber(et.trap_Cvar_Get( "gamestate" )) == 1 then return 0 end
if tonumber(et.trap_Cvar_Get( "gamestate" )) == 0 then
	if meansOfDeath == 37 then
		skcount[victim] = skcount[victim] + 1
		if skcount[victim] == 1 then
			et.trap_SendServerCommand( victim, "cp \""..msg2.."\n" )
		end
	end
end
end

function et_ClientSpawn(client, revived)
    -- pre SELFKILL restriction
	local player_team = et.gentity_get(client, "sess.sessionTeam")
     
	if player_team == 1 then
		player_respawn = tonumber(et.trap_Cvar_Get("g_redlimbotime"))
	elseif player_team == 2 then
		player_respawn = tonumber(et.trap_Cvar_Get("g_bluelimbotime"))
	end
	
    if revived == 0 then
        players_lastspawn[player_respawn] = et.gentity_get(client, "pers.lastSpawnTime")
    end
end
  
function et_RunFrame(levelTime)
	if math.mod(levelTime, samplerate) ~= 0 then return end --slows down the update of leveltime
	leveltime = levelTime
end

function et_ClientCommand(client, command)
    if skcount[client] == 0 then return 0 end
		if skcount[client] == (selfkill_limit + 1) then
		end
	if tonumber(et.trap_Cvar_Get( "gamestate" )) == 0 then
	local teamnumber = tonumber(et.gentity_get(client,"sess.sessionTeam"))
	local playershp = tonumber(et.gentity_get(client,"health"))
    if string.lower(command) == "kill" or string.lower(command) == "kill; forcetapout" and teamnumber ~= 3 and playershp > 0 then -- SELFKILL restriction
		
		local player_team = et.gentity_get(client, "sess.sessionTeam")
     
		if player_team == 1 then
			player_respawn = tonumber(et.trap_Cvar_Get("g_redlimbotime"))
		elseif player_team == 2 then
			player_respawn = tonumber(et.trap_Cvar_Get("g_bluelimbotime"))
		end
		
        local player_ingame = leveltime - players_lastspawn[player_respawn]
     
		local spawntimer = (player_respawn - math.mod(player_ingame, player_respawn))
		
		-- et.trap_SendServerCommand(client, "chat \"Debug spawntimer: "..spawntimer.."\"") --debug line
		if skcount[client] >= 1 then
		    if spawntimer < (spawnvalue*1000) then 
			    et.trap_SendServerCommand(client, string.format(""..printplace.."  \""..msg..""))
			return 1 
		    end
		end
    end
	return 0
	end
end

Last edited by Doc (23-Feb-14 23:47:36)

Offline

Board footer

Powered by FluxBB