Hello, I have this code:
[code]
ply = LocalPlayer()
hook.Add( "Think", "Every Frame", function()
if(ply:GetNWInt('spawn', 0) == 1)then
if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
if(input.IsKeyDown(KEY_1) or input.IsKeyDown(KEY_2) or input.IsKeyDown(KEY_3) or input.IsKeyDown(KEY_4))then
ply:GetEyeTrace().Entity:Remove()
end
end
end
end)
[/code]
and it just gives the error, tried to remove server entity from client. so I was wondering how I can receive when I want it removed on the server, then remove it.
[QUOTE=Mattymoo14211;48620045]Hello, I have this code:
[code]
ply = LocalPlayer()
hook.Add( "Think", "Every Frame", function()
if(ply:GetNWInt('spawn', 0) == 1)then
if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
if(input.IsKeyDown(KEY_1) or input.IsKeyDown(KEY_2) or input.IsKeyDown(KEY_3) or input.IsKeyDown(KEY_4))then
ply:GetEyeTrace().Entity:Remove()
end
end
end
end)
[/code]
and it just gives the error, tried to remove server entity from client. so I was wondering how I can receive when I want it removed on the server, then remove it.[/QUOTE]
OMG! STOP CREATING THREADS. Use net library to send the entity and remove it in serverside.
[QUOTE=Mattymoo14211;48620045]Hello, I have this code:
[code]
ply = LocalPlayer()
hook.Add( "Think", "Every Frame", function()
if(ply:GetNWInt('spawn', 0) == 1)then
if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
if(input.IsKeyDown(KEY_1) or input.IsKeyDown(KEY_2) or input.IsKeyDown(KEY_3) or input.IsKeyDown(KEY_4))then
ply:GetEyeTrace().Entity:Remove()
end
end
end
end)
[/code]
and it just gives the error, tried to remove server entity from client. so I was wondering how I can receive when I want it removed on the server, then remove it.[/QUOTE]
You will have to use the net library. I haven't used it before so I can't give much information, but in dumbed down form you need a sender and a receiver. In your above code where you try to remove the entity, you would send a net message containing the entity you want to remove. The server would then have a net receiver that would take that entity and remove it.
[QUOTE=SteppuFIN;48620102]OMG! STOP CREATING THREADS. Use net library to send the entity and remove it in serverside.[/QUOTE]
Cant help needing loads of help in different subjects
[editline]5th September 2015[/editline]
Is this correct?
[code]
ply = LocalPlayer()
hook.Add( "Think", "Every Frame", function()
if(ply:GetNWInt('spawn', 0) == 1)then
if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
if(input.IsKeyDown(KEY_1) or input.IsKeyDown(KEY_2) or input.IsKeyDown(KEY_3) or input.IsKeyDown(KEY_4))then
net.Start( "Ghostent" )
net.WriteEntity( ply:GetEyeTrace().Entity )
net.SendToServer()
end
end
end
end)
[/code]
[QUOTE=Mattymoo14211;48620123]Cant help needing loads of help in different subjects
[editline]5th September 2015[/editline]
Is this correct?
[code]
ply = LocalPlayer()
hook.Add( "Think", "Every Frame", function()
if(ply:GetNWInt('spawn', 0) == 1)then
if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
if(input.IsKeyDown(KEY_1) or input.IsKeyDown(KEY_2) or input.IsKeyDown(KEY_3) or input.IsKeyDown(KEY_4))then
net.Start( "Ghostent" )
net.WriteEntity( ply:GetEyeTrace().Entity )
net.SendToServer()
end
end
end
end)
[/code][/QUOTE]
[url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
[url]http://wiki.garrysmod.com/page/Category:net[/url]
Don't trust the client and verify that it is the correct entity before removing it, but I believe that will work as long as there is a valid entity.
[QUOTE=InfernusN;48620154][url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
[url]http://wiki.garrysmod.com/page/Category:net[/url]
Don't trust the client and verify that it is the correct entity before removing it, but I believe that will work as long as there is a valid entity.[/QUOTE]
It will be the correct entity always, as the entity is set o the players EyeTrace
[QUOTE=Mattymoo14211;48620171]It will be the correct entity always, as the entity is set o the players EyeTrace[/QUOTE]
A person could use hacks to send another entity which you don't want removed through the net library.
Why don't you call it on the server instead? ply:GetEyeTrace().Entity works on server as well.
[QUOTE=InfernusN;48620183]A person could use hacks to send another entity which you don't want removed through the net library.[/QUOTE]
also, is this correct to receive the entity?
[code]
net.Receive("Ghostent", function(ply)
net.ReadEntity():Remove()
end)
[/code]
[QUOTE=Mattymoo14211;48620123]Cant help needing loads of help in different subjects[/QUOTE]
Different subjects? What are you talking about? Every single thread has the same code, where you try to fix bug in the stronghold gamemode. You can just ask in same thread and not to spam fp with same threads.
Just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerButtonDown]GM/PlayerButtonDown[/url] instead of a Think hook and the input library and you can do this all serverside. If you want an example of how this could be abused:
[code]
RunThisLuaOnClient([[
for i, v in pairs(player.GetAll()) do
net.Start('Ghostent')
net.WriteEntity(v)
net.SendToServer()
end
]]) -- rip server
[/code]
[QUOTE=Mattymoo14211;48620216]also, is this correct to receive the entity?
[code]
net.Receive("Ghostent", function(ply)
net.ReadEntity():Remove()
end)
[/code][/QUOTE]
Yes, but as I have said before you should verify that it's the entity you want removed or as darkjacky suggested do it serverside.
[QUOTE=Mattymoo14211;48620216]also, is this correct to receive the entity?
[code]
net.Receive("Ghostent", function(ply)
net.ReadEntity():Remove()
end)
[/code][/QUOTE]
Check if the entity's class is the ghost ent, if it is delete it otherwise do nothing.
[QUOTE=InfernusN;48620183]A person could use hacks to send another entity which you don't want removed through the net library.[/QUOTE]
also, is this correct to receive the entity?
[code]
net.Receive("Ghostent", function(ply)
net.ReadEntity():Remove()
end)
[/code]
I am now running this serverside, and will be testing it:
[code]
hook.Add( "PlayerButtonDown", "Check button press", function(ply,key)
while(spawn == 1)do
if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
if(input.IsKeyDown(KEY_1) or input.IsKeyDown(KEY_2) or input.IsKeyDown(KEY_3) or input.IsKeyDown(KEY_4))then
ply:GetEyeTrace().Entity:Remove()
end
end
end
end)
[/code]
spawn is defined in the playerspawn hook
[QUOTE=Mattymoo14211;48620318]also, is this correct to receive the entity?
[code]
net.Receive("Ghostent", function(ply)
net.ReadEntity():Remove()
end)
[/code]
I am now running this serverside, and will be testing it:
[code]
hook.Add( "PlayerButtonDown", "Check button press", function(ply,key)
while(spawn == 1)do
if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
if(input.IsKeyDown(KEY_1) or input.IsKeyDown(KEY_2) or input.IsKeyDown(KEY_3) or input.IsKeyDown(KEY_4))then
ply:GetEyeTrace().Entity:Remove()
end
end
end
end)
[/code]
spawn is defined in the playerspawn hook[/QUOTE]
Okay, here's what's wrong:
1. Why in gods name are you using a while loop like that. There's no need for it there.
2. The input library is clientside - you need to be checking if the key equals KEY_1 or KEY_2 and so on.
3. You still are not checking if the entity is the class you want them to be able to remove. With that code, you could remove the player entities, delete other people's items, etc.
Ive tested the script, and the server will let me join, but when I spawn, I will walk for like 2 seconds and it will freeze. then I lose connection and it says my server is using 12% cpu, which is a lot more than usual
Look at problem number one to see what causes that.
[QUOTE=AK to Spray;48620392]Okay, here's what's wrong:
1. Why in gods name are you using a while loop like that. There's no need for it there.
2. The input library is clientside - you need to be checking if the key equals KEY_1 or KEY_2 and so on.
3. You still are not checking if the entity is the class you want them to be able to remove. With that code, you could remove the player entities, delete other people's items, etc.[/QUOTE]
im running it serverside, so players shouldnt be able to change stuff like that, should they? What is the best code to use?
Ive been trying to solve this for days now, I just really need help :)
You can delete any entity that you look at with that code (if it worked, that is). You need to have checks to make sure it is the entity you want them to be able to delete. The while loop you have is basically an infinite loop as long as spawn stays at 1, so it is crashing your server. The input library is only clientside, and the key that is pressed is passed to the PlayerButtonDown hook. With this information, make the necessary edits to the code.
[QUOTE=AK to Spray;48620485]You can delete any entity that you look at with that code (if it worked, that is). You need to have checks to make sure it is the entity you want them to be able to delete. The while loop you have is basically an infinite loop as long as spawn stays at 1, so it is crashing your server. The input library is only clientside, and the key that is pressed is passed to the PlayerButtonDown hook. With this information, make the necessary edits to the code.[/QUOTE]
What way can I check for a number key press on the server?
[QUOTE=Mattymoo14211;48620489]What way can I check for a number key press on the server?[/QUOTE]
[code]
if key == KEY_ENUM then
[/code]
In the hook, of course.
[QUOTE=AK to Spray;48620498][code]
if key == KEY_ENUM then
[/code]
In the hook, of course.[/QUOTE]
oh yeah, I forgot :)
the code:
[code]
hook.Add( "PlayerButtonDown", "Check button press", function(ply,key)
if(spawn == 2)then
if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
if(key == KEY_1 or key == KEY_2 or key == KEY_3 or key == KEY_4)then
if(ply:GetEyeTrace().Entity == "GhostEntity")then
SafeRemoveEntity(ply:GetEyeTrace().Entity)
end
end
end
end
end)
[/code]
I basically, dont want the ent to exist unless using the toolgun, so if there is a better way of doing it, feel welcome to say about it
also, holstering might be an option
[code]
if SERVER then
local shitKeys =
{
[KEY_1] = true,
[KEY_2] = true,
[KEY_3] = true,
[KEY_4] = true
}
hook.Add( "PlayerButtonDown", "Check button press", function(ply,key)
-- if spawn == 2 (removed this because I don't see what it is)
if ply:GetActiveWeapon():GetClass() != "weapon_sh_tool" then return end
if !shitKeys[key] then return end
if !IsValid(ply:GetEyeTrace().Entity) or ply:GetEyeTrace().Entity:GetClass() != "GhostEntity" then return end
local FacingEntity = ply:GetEyeTrace().Entity
SafeRemoveEntity(FacingEntity)
end )
end
[/code]
i don't know, something like that.
[QUOTE=tyguy;48620616][code]
if SERVER then
local shitKeys =
{
[KEY_1] = true,
[KEY_2] = true,
[KEY_3] = true,
[KEY_4] = true
}
hook.Add( "PlayerButtonDown", "Check button press", function(ply,key)
-- if spawn == 2 (removed this because I don't see what it is)
if ply:GetActiveWeapon():GetClass() != "weapon_sh_tool" then return end
if !shitKeys[key] then return end
if !IsValid(ply:GetEyeTrace().Entity) or ply:GetEyeTrace().Entity:GetClass() != "GhostEntity" then return end
local FacingEntity = ply:GetEyeTrace().Entity
SafeRemoveEntity(FacingEntity)
end )
end
[/code]
i don't know, something like that.[/QUOTE]
thankyou, really useful, I just need to find the name of the entity im trying to remove.
[code]
spawn = 0
hook.Add("PlayerSpawn", "onSpawn", function(ply)
spawn = spawn+1
end)
hook.Add("PlayerDeath", "onDeath", function(ply,inflictor,attacker)
spawn = 0
end)
if SERVER then
local shitKeys =
{
[KEY_1] = true,
[KEY_2] = true,
[KEY_3] = true,
[KEY_4] = true
}
hook.Add( "PlayerButtonDown", "Check button press", function(ply,key)
if !spawn == 2 then return end
if ply:GetActiveWeapon() and ply:GetActiveWeapon():GetClass() != "weapon_sh_tool" then return end
if !shitKeys[key] then return end
if !IsValid(ply:GetEyeTrace().Entity) or ply:GetEyeTrace().Entity:GetClass() != "GhostEntity" then return end
SafeRemoveEntity("GhostEntity")
SafeRemoveEntity("C_BaseFlex")
end )
end
[/code]
ive tried GhostEntity and C_BaseFlex as that was what was returned when I got the class of the entity.
The files of the tool gun: [url]http://185.38.148.82/~moogamin/tool%20gun/weapon_sh_tool/[/url]
The entity name should be in one of those files.
in the lua files in stools, its GhostEntity, but that doesnt seem to work.
I was trying to avoid spoon-feeding you, but I guess he did it anyway. The entity object should be the argument for SafeRemoveEntity, not the class name. Also, since this is serverside, you'll want to put the number of spawns on the player object instead of making a global variable.
[QUOTE=AK to Spray;48621031]I was trying to avoid spoon-feeding you, but I guess he did it anyway. The entity object should be the argument for SafeRemoveEntity, not the class name. Also, since this is serverside, you'll want to put the number of spawns on the player object instead of making a global variable.[/QUOTE]
I looked over all the responses and he looked pretty tired of trying to do it.
For SafeRemoveEntity, you'll need to have some kind of reference to the entity - then you can remove it (assuming it's called server)
[QUOTE=AK to Spray;48621031]I was trying to avoid spoon-feeding you, but I guess he did it anyway. The entity object should be the argument for SafeRemoveEntity, not the class name. Also, since this is serverside, you'll want to put the number of spawns on the player object instead of making a global variable.[/QUOTE]
but, GhostEntity is the entity object, so surely it should work, right?
[editline]5th September 2015[/editline]
[QUOTE=tyguy;48621181]I looked over all the responses and he looked pretty tired of trying to do it.
For SafeRemoveEntity, you'll need to have some kind of reference to the entity - then you can remove it (assuming it's called server)[/QUOTE]
When you said I was tired of doing it, I was just hungry :)
[editline]5th September 2015[/editline]
the code now:
[code]
hook.Add("PlayerSpawn", "onSpawn", function(ply)
ply:SetNWInt('spawn', 1)
end)
hook.Add("PlayerDeath", "onDeath", function(ply,inflictor,attacker)
spawn = 0
end)
if SERVER then
local Keys =
{
[KEY_1] = true,
[KEY_2] = true,
[KEY_3] = true,
[KEY_4] = true
}
hook.Add( "PlayerButtonDown", "Check button press", function(ply,key)
if ply:GetNWInt('spawn', 0) != 1 then return end
if ply:GetActiveWeapon() and ply:GetActiveWeapon():GetClass() != "weapon_sh_tool" then return end
if !Keys[key] then return end
if !IsValid(ply:GetEyeTrace().Entity) or ply:GetEyeTrace().Entity:GetClass() != "GhostEntity" then return end
for k,v in pairs(ents.FindByName("GhostEntity"))do
SafeRemoveEntity( v )
end
end )
end
[/code]
[QUOTE=Mattymoo14211;48621330]but, GhostEntity is the entity object, so surely it should work, right?
[editline]5th September 2015[/editline]
When you said I was tired of doing it, I was just hungry :)
[editline]5th September 2015[/editline]
the code now:
[code]
hook.Add("PlayerSpawn", "onSpawn", function(ply)
ply:SetNWInt('spawn', 1)
end)
hook.Add("PlayerDeath", "onDeath", function(ply,inflictor,attacker)
spawn = 0
end)
if SERVER then
local shitKeys =
{
[KEY_1] = true,
[KEY_2] = true,
[KEY_3] = true,
[KEY_4] = true
}
hook.Add( "PlayerButtonDown", "Check button press", function(ply,key)
if !spawn == 2 then return end
if ply:GetActiveWeapon() and ply:GetActiveWeapon():GetClass() != "weapon_sh_tool" then return end
if !shitKeys[key] then return end
if !IsValid(ply:GetEyeTrace().Entity) or ply:GetEyeTrace().Entity:GetClass() != "GhostEntity" then return end
for k,v in pairs(ents.FindByName("GhostEntity"))do
SafeRemoveEntity( v )
end
end )
end
[/code][/QUOTE]
GhostEntity is the name of the object
[QUOTE=tyguy;48621366]GhostEntity is the name of the object[/QUOTE]
Then how else should I refer to the entity?
Sorry, you need to Log In to post a reply to this thread.