Now this might sound like a joke, but it really isn't.
I have done some research, but I haven't been able to find anything on it, and I was like "Hang on, doesn't the spawn menu make it so all props entity size / bounds are the same as the model size?" but I had no luck in that area of research...
All I am trying to do, is make a prop resize its self and split (like agario)
I have got it working, the problem is the entity bounds / size is always the same from the original model size (I think)
[CODE]net.Receive( "dissolve_prop", function( len, pl )
local ent = pl:GetEyeTrace().Entity
_model = ent:GetModel()
_pos = ent:GetPos()
_size = ent:GetModelScale() * 0.10
ent:Remove()
for i = 1,10 do
_G[ "ent_"..i ] = ents.Create( "prop_physics" )
_G[ "ent_"..i ]:SetModel( _model )
_G[ "ent_"..i ]:SetPos( _pos + Vector( i*2, 0, 5 ) )
_G[ "ent_"..i ]:SetModelScale( _size ) -- Here is where it scales it, but doesn't scale the entity.
_G[ "ent_"..i ]:Spawn()
end
end )[/CODE]
Where did you learn to use the _G table and _ before every variable name? I've never seen anyone do that before. You shouldn't need to use any global variables for this.
[CODE]
net.Receive( "dissolve_prop", function( len, ply )
local ent = ply:GetEyeTrace().Entity
for i = 1, 10 do
local new = ents.Create( "prop_physics" )
new:SetModel( ent:GetModel() )
new:SetPos( ent:GetPos() + Vector( i * 2, 0, 5 ) )
new:SetModelScale( ent:GetModelScale() * 0.10 )
new:Spawn()
end
ent:Remove()
end )
[/CODE]
I didn't change the code in any way, I just formatted it to what most regular code looks like. Sorry.
Hopefully someone else knows the answer.
[QUOTE=MPan1;52582905]Where did you learn to use the _G table and _ before every variable name? I've never seen anyone do that before. You shouldn't need to use any global variables for this.
[CODE]
net.Receive( "dissolve_prop", function( len, ply )
local ent = ply:GetEyeTrace().Entity
for i = 1, 10 do
local new = ents.Create( "prop_physics" )
new:SetModel( ent:GetModel() )
new:SetPos( ent:GetPos() + Vector( i * 2, 0, 5 ) )
new:SetModelScale( ent:GetModelScale() * 0.10 )
new:Spawn()
end
ent:Remove()
end )
[/CODE]
I didn't change the code in any way, I just formatted it to what most regular code looks like. Sorry.
Hopefully someone else knows the answer.[/QUOTE]
I understand what you have done, and I knew to do this.
(Just later in the code I recognise the entity using its number value etc)
[editline]17th August 2017[/editline]
Oh wait, I can just use SetName ha
[editline]17th August 2017[/editline]
Oh wait, I can just use SetName ha
If you need to recognise it using the number, then you can always create a variable such as a table beforehand to avoid unnecessary globals, E.G.
[CODE]
local ents = {}
for i = 1, 10 do
local new = ents.Create( "prop_physics" )
new:SetModel( ent:GetModel() )
new:SetPos( ent:GetPos() + Vector( i * 2, 0, 5 ) )
new:SetModelScale( ent:GetModelScale() * 0.10 )
new:Spawn()
table.insert( ents, new )
end
[/CODE]
And you generally never need to index _G. If you don't use local, it's already a global variable.
Sorry, styling bothers me
[editline]17th August 2017[/editline]
I just tested the code I posted before this, and it seems to actually work (at least on a bathtub model), but it keeps lagging because of all the collisions.
What prop are you trying to scale?
Oh, I recommend making it Vector ( i * 10, 0, 5 ) (reduces lag).
The models will appear scaled, but if you pick the little critters up it is the entire model box before it was scaled (use a barrel for example)
[editline]17th August 2017[/editline]
(Oh and I might get away from props doe, and move to NPCS)
[editline]17th August 2017[/editline]
Ok, so I have this.. (don't judge please lol)
[CODE]net.Receive( "dissolve_prop", function( len, pl )
local ent = pl:GetEyeTrace().Entity
if ent:IsNPC() then
for k,v in pairs( ents.GetAll() ) do
if v:GetOwner() == pl then
for i = 1,10 do
if v:GetName() == ( "Member "..i ) then
v:Remove()
end
end
end
end
_model = ent:GetModel()
_pos = ent:GetPos()
_size = ent:GetModelScale() * 0.50
_class = ent:GetClass()
if ent:IsNPC() then
_weapon = ent:GetActiveWeapon():GetClass()
end
ent:Remove()
for i = 1,10 do
local new = ents.Create( _class )
new:SetModel( _model )
new:SetPos( _pos + Vector( i*15, 0, 5 ) )
new:SetModelScale( _size )
if _weapon != nil then
new:Give( _weapon )
end
new:SetName( "Member "..i )
new:SetOwner( pl )
new:Spawn()
end
end
end )[/CODE]
It duplicates the target NPC, into more little versions, problem is now that they don't seem to be "NPCS" anymore, all they do is hit you if you get too close, but they don't shoot?
Ok, I get it. You mean the physics don't get updated. Sorry again.
Well, according to the wiki page for [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetModelScale]Entity:SetModelScale[/url], it says that sometimes calling [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/Activate]Entity:Activate[/url] will update the physics. Maybe that works?
(to make them hit you remove the "setowner" line
[editline]17th August 2017[/editline]
Oh and Ent:Activate doesn't seem to work?
[editline]17th August 2017[/editline]
NVM it works.
[editline]17th August 2017[/editline]
Thanks MPan :)
Last problem is, the "NPC" side doesn't shoot.
You know how to fix this?
I don't know if this is the right way to do it, but you could probably use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/NPC/AddEntityRelationship]NPC:AddEntityRelationship[/url] to make the NPC hate the player so they shoot them (if this is what you mean).
[CODE]
ent:AddEntityRelationship( ply, D_HT, 99 )
[/CODE]
[editline]17th August 2017[/editline]
Also, your code still uses a ton of unnecessary global variables:
[CODE]
_model = ent:GetModel()
_pos = ent:GetPos()
_size = ent:GetModelScale() * 0.50
_class = ent:GetClass()
[/CODE]
All of these could be local, and none of them need a _ before them unless they're some kind of metatable meme
I understand MPan, I removed them and just put them in respectful places.
But the NPCs are how do I put this.. AFK? They spawn, and just sit there like nothing happen, not matter what happens they don't move, do I have to like re-trigger the npc or rewrite the ENTIRE entity?
[editline]17th August 2017[/editline]
(I solved this ^)
Just how do I make it the NPCs fear everything but me? because I don't want to set the relation ship EVERY time I spawn a new character..
[editline]17th August 2017[/editline]
(oh and the relation ship thing works... but they still don't shoot?)
Sorry, you need to Log In to post a reply to this thread.