I dont know how hard it would be but this is what I want for darkrp, I dont know if darkrp uses its own health system or what but ill lay it out, if player has less then 200 hp you can type the command /buyarmor and it will set there health to 200 wont give them +100 just set it to 200, and if they already have 200 a hint that says you dont need armor.
[editline]10:54PM[/editline]
This is what my friend came up with, but all it does is spawn a HEV suit that does not go away does not add health, any help?
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( "body_armor" )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Initialize()
self.Entity:SetModel( "models/Items/hevsuit.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
local phys = self.Entity:GetPhysicsObject()
if(phys:IsValid()) then phys:Wake() end
self.Activator():SetHealth(self.Activator():Health() + 200)
local armor = ents.Create("body_armor")
armor:SetPos(vPoint)
armor:Spawn()
self.Entity:Remove()
armor.Remove()
end
function ENT:Think() end
[/CODE]
maybe add a ENT:OnTouch?
This isnt my code, where would I add that?
[code]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( "body_armor" )
ent:SetModel( "models/Items/hevsuit.mdl")
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Touch( player )
if player:IsValid() and player:IsPlayer() then
player:SetHealth(player:Health() + 200)
self:Remove()
end
end
[/code]
for some strange reason this file is not being re-downloaded when I make the changes, is there an extra step I have to take?
I edited it up abit again. Make sure you hit save. You need to either restart your map, restart your game, or type lua_reloadents in the console
I put it in the init file and save it re-upload it and it deducts 200 dollars from me but adds no health.
[code]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( "body_armor" )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Initialize()
self.Entity:SetModel( "models/Items/HealthKit.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
local phys = self.Entity:GetPhysicsObject()
if(phys:IsValid()) then phys:Wake() end
end
function ENT:Touch( player )
if player:IsValid() and player:IsPlayer() then
player:SetHealth(player:Health() + 200)
self.Entity:Remove()
end
end
[/code]
Use self.Entity:SetModel( "models/Items/HealthKit.mdl") or
self.Entity:SetModel( "models/Items/battery.mdl") instead because the hev suit doesn't seem to have physics thus you can't touch it.
Well I just want the thumbnail in the f4 menu of darkrp to look like armor, I could care less if it spawned and I want it to apply automatically not on touch, + it does not set health to 200 it keeps adding 200 over and over again.
What do you mean it doesnt set it to 200? You said you wanted it to add 200 everytime someone picks one up.
There I even added a little health pack sound to it.
[code]
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( "body_armor" )
ply:SetHealth(ply:Health() + 200)
ent:EmitSound("items/smallmedkit1.wav", 100, 100)
ent:Spawn()
return ent
end
function ENT:Initialize()
self.Entity:SetModel( "models/Items/hevsuit.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
local phys = self.Entity:GetPhysicsObject()
if(phys:IsValid()) then phys:Wake() end
self.Entity:Remove()
end
[/code]
I can honestly tell you that I didnt say to add 100 everytime, just wanted it set to 200 health if below 200.
Okay well it works now, but it adds 200 health over and over and spawns a medical kit, could you make it automatically be picked up and just set the health to 200 if the health is below 200.
[code]function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( "body_armor" )
ply:SetMaxHealth(200)
ply:SetHealth(200)
ent:EmitSound("items/smallmedkit1.wav", 100, 100)
ent:Spawn()
return ent
end
function ENT:Initialize()
self.Entity:SetModel( "models/Items/hevsuit.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
local phys = self.Entity:GetPhysicsObject()
if(phys:IsValid()) then phys:Wake() end
self.Entity:Remove()
end[/code]
It deducts money from my rp server when I purchase it but does not increase the health.
[QUOTE=mishappp;16653160]if player has less then 200 hp you can type the command /buyarmor and it will set there health to 200 wont give them +100 just set it to 200, and if they already have 200 a hint that says you dont need armor.
[/QUOTE]
To me this said that you wanted it to go beyond 200.
[Code]
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( "body_armor" )
ply:SetHealth(200)
ent:EmitSound("items/smallmedkit1.wav", 100, 100)
ent:Spawn()
return ent
end
function ENT:Initialize()
self.Entity:SetModel( "models/Items/hevsuit.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
local phys = self.Entity:GetPhysicsObject()
if(phys:IsValid()) then phys:Wake() end
self.Entity:Remove()
end
[/Code]
This automaticly picks it up nothing will be spawned.
Still spends money but does not give armor.
You just asked for health, Not armour?
Thats what I meant, health, It does not add any health still.
Well the last script I posted works perfectly fine on my game.
It does not even show up in my sents list.
Works for me and TB.
very strange, ill keep trying.
Where are you putting it? Any errors in the console?
lua>entitys>body_armor
and I will check the console in a bit.
It should be:
Lua/Entities/Body_armour/init.lua
Lua/Entities/Body_armour/shared.lua
Lua/Entities/Body_armour/cl_init.lua
I dont think it should be Armour it is that but spelt armor
It can be whatever you want it to be as long as the folder name matchs whatever you name it here.
local ent = ents.Create( " " )
Words that are spelled ending with "our" are from British English and usually end in "or" in American English.
[QUOTE=mishappp;16696248]I dont think it should be Armour it is that but spelt armor[/QUOTE]
Armour = English
Armor = American.
Okay, I changed local ent = ents.Create( "body_armor" ) to body_armour , and the folder to body_armour, so I could see if it would redownload the files, and it did not download anything.
that most likely means you have an error in you code for init.lua or shared.lua
Anybody having a problem posting on FP recently? It takes like 4 minuets to post a reply... and thats with a good internet connection.
Sorry, you need to Log In to post a reply to this thread.