Print Message triggered by an entity.

Hi All,
I’ve just started learning LUA. I’m making a map for my server which has a Build area, DM area and a VIP area. These areas are all linked via teleports from a spawn room. In the spawn room & dm area I don’t allow props to be spawned, they are dissolved using “env_entity_dissolver” in my map. When props are dissolved I also would like a message to explain why. This message is called via a trigger_mutiple in the relevant area.

LUA



function noprops(ent)
	if (ent:GetClass() == "prop_physics") then
	ent:PrintMessage( HUD_PRINTCENTER, "Sorry, you cannot spawn props here. Please goto the Build area." )
end
end


lua_run Entity



Code= noprops(CALLER)


The above function isn’t working, any idea why? It may be totally wrong as I do a lot of trial and error.

You can’t print with ChatPrint directly to the entity, you have to do it to its owner. If you use a prop protection that uses CPPI (all known ones) you can do:
[lua] ent:CPPIGetOwner():PrintMessage(blabla) [/lua] instead.

I changed the lua to:



function noprops(ent)
	if (ent:GetClass() == "prop_physics") then
	ent:CPPIGetOwner():PrintMessage("Sorry, you cannot spawn props here. Please goto the Build area.")
end
end


It didn’t work. Have I done it wrong?

Are you sure that the function is created properly? Where is the code located?
Do a print just before the if statement, and see if it prints. Make sure you test it in singleplayer.

For now the code is located in a single lua file name thescrapyard.lua and it in the autorun/server folder.

Here is all the code so far:



function giveBuildWeapons(Player)
	Player:ChatPrint("Welcome to the Build area. Godmode has been enabled")
	Player:Give("gmod_tool")
	Player:Give("weapon_physgun")
	Player:Give("gmod_camera")
end

function giveWeapons(Player)
	Player:ChatPrint("Welcome to the Death Match area. Godmode has been disabled")
	Player:Give("weapon_pistol")
	Player:Give("weapon_smg1")
	Player:Give("weapon_ar2")
end

function weaponStrip(Player)
Player:StripWeapons()
end

function EnableGod(ply)
	ply:GodEnable()
end

function DisableGod(ply)
	ply:GodDisable()
end

function noprops(ent)
	if (ent:GetClass() == "prop_physics") then return end
	if ( !ent:IsValid() or !ent:IsPlayer() ) then return end
	ent:PrintMessage( HUD_PRINTCENTER, "Sorry, you cannot spawn props here. Please goto the Build area." )
end

function checkvip(ply)
if ply:IsUserGroup("vip") then
ply:ChatPrint("You are a vip, welcome to the VIP area!")
elseif ply:IsAdmin() then
ply:ChatPrint("You are an admin, welcome to the VIP area!")
else
ply:ChatPrint("You are not a vip! Sorry, you were slayed.")
ply:Kill()
end
end


The functions are called from lua_runs in my map. For example, if a player tries to enter the VIP area but is not a VIP they are killed.

as I said, try print some, debug it! (You don’t need that prop_physics check, at all) (ValidEntity is better, cause it first checks if ent even exists)
[lua]
function noprops(ent)
print(“Found entity!”)
print(ent:GetClass())
if ( !ValidEntity(ent) or !ent:IsPlayer() ) then print(“NOPE”) return end
print(“Print stuff now!”)
ent:PrintMessage( HUD_PRINTCENTER, “Sorry, you cannot spawn props here. Please goto the Build area.” )
end
[/lua]