Fortress Forever

Go Back   Fortress Forever > Editing > Mapping > Lua

Reply
 
Thread Tools Display Modes
Old 04-03-2009, 07:02 PM   #1
hlstriker
QUAD ROCKET
Server Owner
Fortress Forever Staff
 
hlstriker's Avatar
 
Join Date: Jul 2007
Class/Position: Soldier
Gametype: Rocket Jumping
Affiliations: -g1 ]qS[ -eC- :e0: [ESAD]
Posts Rated Helpful 11 Times
Logging custom message on entity touch

Is there a way for me to log a custom message when a player touches an entity?
hlstriker is offline   Reply With Quote


Old 04-04-2009, 09:51 AM   #2
Dexter
internet user
Fortress Forever Staff
 
Dexter's Avatar
 
Join Date: Jun 2007
Posts Rated Helpful 42 Times
Sure.. easiest and quickest way I can think of is

Code:
some_thing = info_ff_script:new(
{
    -- your stuff here w/e blah
    touchflags = {AllowFlags.kOnlyPlayers,AllowFlags.kBlue, AllowFlags.kRed, AllowFlags.kYellow, AllowFlags.kGreen}
})

function some_thing:touch( touch_ent )
    if IsPlayer( touch_ent ) then
        ConsoleToAll("A player  touched my info script!")
    end
end
Naturally that will send the message to everyone. You can cast the player if you need info from it
__________________
9:17 PM - DEXTER: can you teach me how to play o
9:17 PM - squeek.: you jump a lot
9:18 PM - squeek.: and do sweet moves

8:55 PM - FDA: fart in you fridge and blame it on wild animals
Dexter is offline   Reply With Quote


Old 04-04-2009, 10:17 AM   #3
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 352 Times
Send a message via AIM to squeek.
I think he means server logs.

Plus, ConsoleToAll() only sends the message to the server's console.

You're looking for LogLuaEvent()
Quote:
Originally Posted by AfterShock
SERVER LOGGING: added valve-standard LUA triggered logs. use like this:

LogLuaEvent(int victimID, int attackerID, string eventname)
LogLuaEvent(int victimID, int attackerID, string eventname, string key0, string value0)
LogLuaEvent(int victimID, int attackerID, string eventname, string key0, string value0, string key0, string value0, string key1, string value1)
LogLuaEvent(int victimID, int attackerID, string eventname, string key0, string value0, string key0, string value0, string key1, string value1, string key2, string value2)

e.g.

LogLuaEvent(0, player:GetId(), "flag_touch", "flag_name", flag:GetName())

outputs

L 09/18/2008 - 00:50:33: "AfterShock<1><STEAM_ID_LAN><#FF_TEAM_BLUE>" triggered "flag_touch" (flag_name "yellow_flag")

For world triggered stuff just called with ID 0 for both players

e.g.

LogLuaEvent(0, 0, "flag_returned", "flag_name", flag:GetName());

outputs

L 09/18/2008 - 00:58:58: World triggered "flag_returned" (flag_name "green_flag")
There are some examples in base_teamplay.lua:
Code:
LogLuaEvent(player:GetId(), 0, "flag_dropped", "flag_name", flag:GetName(), "player_origin", (string.format("%0.2f",player:GetOrigin().x) .. ", " .. string.format("%0.2f",player:GetOrigin().y) .. ", " .. string.format("%0.1f",player:GetOrigin().z) ));
__________________
#FF.Pickup ¤ Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 04-04-2009, 11:11 AM   #4
Dexter
internet user
Fortress Forever Staff
 
Dexter's Avatar
 
Join Date: Jun 2007
Posts Rated Helpful 42 Times
ohhh. I'm retarded. Very nice and easy
__________________
9:17 PM - DEXTER: can you teach me how to play o
9:17 PM - squeek.: you jump a lot
9:18 PM - squeek.: and do sweet moves

8:55 PM - FDA: fart in you fridge and blame it on wild animals
Dexter is offline   Reply With Quote


Old 04-04-2009, 05:51 PM   #5
hlstriker
QUAD ROCKET
Server Owner
Fortress Forever Staff
 
hlstriker's Avatar
 
Join Date: Jul 2007
Class/Position: Soldier
Gametype: Rocket Jumping
Affiliations: -g1 ]qS[ -eC- :e0: [ESAD]
Posts Rated Helpful 11 Times
Alright, thanks

Also, how does the LUA know what entity in the map to use?

Quote:
some_thing = info_ff_script:new(
{
-- your stuff here w/e blah
touchflags = {AllowFlags.kOnlyPlayers,AllowFlags.kBlue, AllowFlags.kRed, AllowFlags.kYellow, AllowFlags.kGreen}
})
Is this creating the entity itself or is it only creating a hook to the entity?
hlstriker is offline   Reply With Quote


Old 04-05-2009, 01:49 AM   #6
Crazycarl
D&A Member
Wiki Team
Fortress Forever Staff
 
Crazycarl's Avatar
 
Join Date: Apr 2007
Posts Rated Helpful 31 Times
It's a hook. The entity has to be in the map already so that players can interact with it. These are usuallyan info_ff_script or trigger_ff_script, but any named trigger can be used.
__________________
Support FF:
Crazycarl is offline   Reply With Quote


Old 04-06-2009, 07:03 AM   #7
hlstriker
QUAD ROCKET
Server Owner
Fortress Forever Staff
 
hlstriker's Avatar
 
Join Date: Jul 2007
Class/Position: Soldier
Gametype: Rocket Jumping
Affiliations: -g1 ]qS[ -eC- :e0: [ESAD]
Posts Rated Helpful 11 Times
I might be missing something but I'm still confused on how to specify which entity to hook
hlstriker is offline   Reply With Quote


Old 04-06-2009, 07:33 AM   #8
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 352 Times
Send a message via AIM to squeek.
Quote:
Originally Posted by hlstriker View Post
I might be missing something but I'm still confused on how to specify which entity to hook
Code:
some_thing = info_ff_script:new({})
Will hook ALL entities named "some_thing" (even non-info_ff_script entities). You can't really discriminate between entities of the same name within lua.

EDIT: What exactly are you trying to do?
__________________
#FF.Pickup ¤ Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 04-06-2009, 06:23 PM   #9
hlstriker
QUAD ROCKET
Server Owner
Fortress Forever Staff
 
hlstriker's Avatar
 
Join Date: Jul 2007
Class/Position: Soldier
Gametype: Rocket Jumping
Affiliations: -g1 ]qS[ -eC- :e0: [ESAD]
Posts Rated Helpful 11 Times
I was thinking 'some_thing' was a variable but I guess that really doesn't make sense when I look at the prototype :S

I'm making a speed run plugin for skill maps and need to detect when a player touches the start/end timers. Currently SourceMod can't hook touches for FF so I decided to use a hackish method and use LUA to log when a player touches the entity so I can hook the log in SourceMod

(I'll eventually need to figure out how to add a delay between client touches so it doesn't spam the log too.)

Last edited by hlstriker; 04-06-2009 at 06:50 PM.
hlstriker is offline   Reply With Quote


Old 04-09-2009, 07:18 AM   #10
hlstriker
QUAD ROCKET
Server Owner
Fortress Forever Staff
 
hlstriker's Avatar
 
Join Date: Jul 2007
Class/Position: Soldier
Gametype: Rocket Jumping
Affiliations: -g1 ]qS[ -eC- :e0: [ESAD]
Posts Rated Helpful 11 Times
I got the entity touches working but now I'm having problems trying to create a delay between each touch.

You can see I'm just trying to use a simple bool array...
- When player spawns set players array index to true.
- When player touches ent, set array index to false, and AddSchedule.
- AddSchedules function resets players array index to true.

How can I do this?

Code:
-----------------------------------------------------------------------------
-- Delay for touching the timer so it doesn't constantly spam the player
-----------------------------------------------------------------------------
local bCanTouchTimer[] -- How do I make an array?

function sr_delay_reset(player)
	bCanTouchTimer[player] = true
end

function player_spawn(player)
	bCanTouchTimer[player] = true
end


-----------------------------------------------------------------------------
-- Start Timer
-----------------------------------------------------------------------------
sr_start_timer = info_ff_script:new({
	model = "models/items/ball/ball.mdl",
	touchflags = {AllowFlags.kOnlyPlayers, AllowFlags.kBlue, AllowFlags.kRed, AllowFlags.kYellow, AllowFlags.kGreen}
})

function sr_start_timer:precache( )
	PrecacheModel(self.model)
end

function sr_start_timer:touch(touch_entity)
	if IsPlayer(touch_entity) then
		local player = CastToPlayer(touch_entity)
		
		-- Check the delay
		if bCanTouchTimer[player] then
			RemoveHudItem(player, "touched_start")
			AddSchedule("sr_touch_delay", 2, sr_delay_reset, player)
			bCanTouchTimer[player] = false
		end
	end
end
hlstriker is offline   Reply With Quote


Old 04-09-2009, 07:28 AM   #11
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 352 Times
Send a message via AIM to squeek.
Try using player:GetId() for the index of the array.

And you make an array using:
Code:
local bCanTouchTimer = {}
__________________
#FF.Pickup ¤ Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 04-09-2009, 08:08 PM   #12
hlstriker
QUAD ROCKET
Server Owner
Fortress Forever Staff
 
hlstriker's Avatar
 
Join Date: Jul 2007
Class/Position: Soldier
Gametype: Rocket Jumping
Affiliations: -g1 ]qS[ -eC- :e0: [ESAD]
Posts Rated Helpful 11 Times
Thanks it's working perfect now
hlstriker is offline   Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:46 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.