Entity to server communication?

Hey everyone,

I’m learning lua and I need a little help please. Ive made an entity that (with any luck) will add a point to the players team when touched. Ive done the entity and it dissapears on touch after identifying the players team etc.

My problem is, how do I get the entities code to add to the team points variable which is in the gamemode lua files?

Here’s the code for the entity…



function ENT:Touch( touchEnt )
	if ( touchEnt:IsValid() and touchEnt:IsPlayer() ) then
		if ( team.GetName(touchEnt:Team()) == "French" ) then
			--- Add points to french here
		self.Entity:Remove()
		end
	end
end


Any help or suggestions would be greatly appreciated.

I think you would have to use ‘include’ in init.lua

If it’s a global variable just add to it like you would in the gamemode files.

[editline]04:57PM[/editline]

If it’s a local variable you can add a global function for adding on to it.
[lua]
function AddScoreFrench()

FrenchScore=FrenchScore+1

end
[/lua]
And call that in your entity.

-snip-
Misread.

Thanks for the suggestions guys. How would I make it a global variable or will I be able to find that on the Gmod LUA wiki?

[lua]
variable = variable --This is global
local variable = variable --This is local
[/lua]

It seems you don’t get this stuff yet.

Entities are automatically included.
SWEPs are automatically included.
Effects are automatically included.

For everything else, there’s include.

So you’re saying that if I just simply put the code to add 1 to the team points variable the gamemode would do the rest for me? I’d not need to include anything or make any extra links between the entity and the game mode code?

Im trying out some of these now so I will let you know if it works guys :slight_smile:

Ok I’ve tried updating the variable without any includes, no luck. Even though it’s a global variable. So this requires some sort of specific command or code from what I can tell…here’s the entity code I just tried:



function ENT:Touch( touchEnt )
	if ( touchEnt:IsValid() and touchEnt:IsPlayer() ) then
		if ( team.GetName(touchEnt:Team()) == "Brits" ) then
			britPoints = britPoints+1
		self.Entity:Remove()
		end
	end
end


[editline]07:30PM[/editline]

Never mind, forgot to call on the points update function after. The above code does work. Just needed to tell the scoreboard to update after adding.

Thank you everyone :slight_smile: