Thanks _Kilburn for this script:
[lua]SpawnableModels = {
{model="models/props_c17/oildrum001.mdl", health = 10, cost = 1 },
{model="models/props_lab/blastdoor001a.mdl", health = 10, cost = 1 },
{model="models/props_lab/blastdoor001b.mdl", health = 10, cost = 1 },
{model="models/props_lab/blastdoor001c.mdl", health = 10, cost = 1 },
{model="models/nova/chair_office01.mdl", health = 10, cost = 1 },
{model="models/props_c17/concrete_barrier001a.mdl", health=10, cost=1},
{model="models/props_junk/trafficcone001a.mdl", health = 10, cost = 1 },
{model="models/props_c17/oildrum001.mdl", health = 10, cost = 1 },
{model="models/props_wasteland/controlroom_desk001a.mdl", health = 10, cost = 1 },
{model="models/props_c17/furniturecouch001a.mdl", health = 10, cost = 1 },
{model="models/props_combine/breendesk.mdl", health = 10, cost = 1 },
{model="models/props_c17/door01_left.mdl", health = 10, cost = 1 },
{model="models/props_c17/Lockers001a.mdl", health = 10, cost = 1 },
{model="models/props_debris/metal_panel01a.mdl", health = 10, cost = 1 },
{model="models/props_junk/propane_tank001a.mdl", health = 10, cost = 1 },
{model="models/props_wasteland/kitchen_shelf001a.mdl", health=10, cost=1},
{model="models/props_c17/shelfunit01a.mdl", health = 10, cost = 1 },
{model="models/props_c17/signpole001.mdl", health = 10, cost = 1 },
{model="models/props_c17/furniturestove001a.mdl", health = 10, cost = 1 },
{model="models/props_c17/furnituretable002a.mdl", health = 10, cost = 1 },
{model="models/props_interiors/VendingMachineSoda01a.mdl", health = 10, cost = 1 },
{model="models/props_interiors/VendingMachineSoda01a_door.mdl", health = 10, cost = 1 },
{model="models/props_wasteland/wood_fence01a.mdl", health = 10, cost = 1 },
{model="models/props_junk/wood_crate001a.mdl", health = 10, cost = 1 },
{model="models/props_junk/wood_crate002a.mdl", health = 10, cost = 1 },
{model="models/props_junk/sawblade001a.mdl", health = 10, cost = 1 },
}
local function SpawnProp(ply, cmd, args)
local num = tonumber(args[1])
if not num then return end
local modeldata = SpawnableModels[num]
if not modeldata then return end
if ply.Money < modeldata.cost then
ply:PrintMessage( HUD_PRINTTALK, "You cannot afford this prop." )
return false
end
ply.Money = ply.Money - modeldata.cost
ply:EmitSound("buttons/button15.wav")
ply:PrintMessage( HUD_PRINTTALK, "Money left: "..ply.Money.."$" )
local ent = ents.Create("prop_physics")
local trace = ply:GetEyeTraceNoCursor()
ent:SetPos(trace.HitPos + trace.HitNormal * 32)
ent:SetModel(modeldata.model)
ent:SetHealth(modeldata.health)
ent:Spawn()
ent:Activate()
end
concommand.Add("spawn_prop", SpawnProp)[/lua]
This works perfectly, the only problem is the [B]Health.[/B] This script spawns the prop, it removes money based on prop's cost, but, the prop is unbreakable (except for wooden stuff).
I tried making a real enitity with a damage function but I failed, same goes for [lua]ent:Fire( "SetHealth", modeldata.health )[/lua] I hope you will be able to help me. Thanks!
come on, 20 hours passed and there are already 20 new help requests :eng99:
You need to make the props take damage. [b][url=wiki.garrysmod.com/?title=Gamemode.EntityTakeDamage]Gamemode.EntityTakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[QUOTE=20 Smartness;19629323]You need to make the props take damage. [b][url=wiki.garrysmod.com/?title=Gamemode.EntityTakeDamage]Gamemode.EntityTakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b][/QUOTE]
Isn't it for [B]players[/B]?
No. It's called Entity, not Player.
I new to lua but i think i saw a thread where they used
Entity.SetNWInt
so they when the value assigned to the prop == 0 they used a function to bread it
[B][/B]
[QUOTE=sweeneypaul;19630442]I new to lua but i think i saw a thread where they used
Entity.SetNWInt
so they when the value assigned to the prop == 0 they used a function to bread it
[B][/B][/QUOTE]
Nooooo dont do this, it will lag like hell Seting networked variables constantly is a bad idea.
No it won't, not unless you create multitudes of unnecessary variables. Networked integers (or DTVars, which I would recommend) are an easy way of retrieving information from an entity.
Here's a sample from an entity I made:
[lua]function ENT:OnTakeDamage( dmg )
if dmg:GetAttacker():Team() == self.Entity:GetNWInt("Team") then return end
self.HealthPts = self.HealthPts - dmg:GetDamage()
self.Entity:SetNWInt("Health",self.HealthPts)
if self.HealthPts <= 0 then
self.Entity:Remove()
end
end[/lua]
[QUOTE=20 Smartness;19629870]No. It's called Entity, not Player.[/QUOTE]
[lua]if ( ent:IsPlayer() ) then[/lua]
Okay, I'm going to test "Entoros" code.
Just a question: Once I put it in the [B]entity[/B]'s code, will I have to create "self.HealthPts" as [B]modeldata.health[/B]?
[lua]ent:SetHealth("Health", modeldata.health)[/lua]
Error at this line:
[lua] self.HealthPts = self.HealthPts - dmg:GetDamage() [/lua]
Why would you need to SetHealth AND keep your own variables for help?
[QUOTE=20 Smartness;19660262]Why would you need to SetHealth AND keep your own variables for help?[/QUOTE]
And what should I use... "HealthPts"?
Sorry, you need to Log In to post a reply to this thread.