[QUOTE=Jewno;44994959]..... Are you listening to what they're saying?[/QUOTE]
IK I CHANGED IT
[editline]4th June 2014[/editline]
[code]
ITEM.Name = 'Zoey'
ITEM.Price = 40000
ITEM.Model = 'models/player/zoey.mdl'
function ITEM:OnEquip(ply, modifications)
if ply:Team() == "TEAM_HUMAN" then return
if not ply._OldModel then
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function() ply:SetModel(self.Model) end)
end
end
function ITEM:OnHolster(ply)
if ply._OldModel then
ply:SetModel(ply._OldModel)
end
end
function ITEM:PlayerSetModel(ply)
ply:SetModel(self.Model)
end
[/code]
This is still not working
You changed nothing except for the ==. Look at the code Mors posted.
[QUOTE=code_gs;44995175]You changed nothing except for the ==. Look at the code Mors posted.[/QUOTE]
that breaks the code!
[editline]4th June 2014[/editline]
[QUOTE=Mors Quaedam;44992633][code]
if ply:Team() == TEAM_HUMAN then
-- code here
end
[/code]
The last part is not needed.[/QUOTE]
breaks the code
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == "TEAM_HUMAN" then return
if not ply._OldModel then
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function() ply:SetModel(self.Model) end)
end
end[/lua]
What...
[lua]
if ply:Team() == "TEAM_HUMAN" then return
-- Code Stuff Here, focus on the above and below
end[/lua]
Unless I'm just being stupid, but does that even work?
Your code is already broken...
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == "TEAM_HUMAN" then return
if not ply._OldModel then
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function() ply:SetModel(self.Model) end)
end
end[/lua]
If player == "TEAM_HUMAN" then return -- you need an end here, or return something then end.
Instead of returning a value, you're using an IF in place of a return.
If you want to return an "IF" statement, or return x or y based on a condition ( supports nesting too ), use a ternary operation: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/ternary_operations.lua.html[/url]
You should also properly tab your code...
Then you'd see this:
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == "TEAM_HUMAN" then
return -- code stops here
if not ply._OldModel then -- code errors on this line, expecting something else...
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function()
ply:SetModel(self.Model)
end)
end
end[/lua]
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == TEAM_HUMAN then
if not ply._OldModel then -- code errors on this line, expecting something else...
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function()
ply:SetModel(self.Model)
end)
return true; -- Usually a return is done after logic is taken care of.
else
-- This is if the team is NOT human... Put whatever here, or nothing and remove the else.
end
end[/lua]
If you want a ternary operation, here's how they work:
[lua]function ITEM:OnEquip(ply, modifications)
// THIS BLOCK OF CODE
local _value = false;
if ( ply:Team( ) == TEAM_HUMAN ) then
_value = true;
end
return _value;
// END THIS BLOCK OF CODE
// IS IDENTICAL TO THIS
return ( ply:Team( ) == TEAM_HUMAN ) && true || false;
// END IS IDENTICAL TO THIS
end[/lua]
Don't use both blocks at the same time, you'll get an error.
You probably meant this for your code:
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == TEAM_HUMAN then
if not ply._OldModel then -- code errors on this line, expecting something else...
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function()
ply:SetModel(self.Model)
end)
else
-- This is if the team is NOT human... Put whatever here, or nothing and remove the else.
end
end[/lua]
[QUOTE=Acecool;44995372]Your code is already broken...
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == "TEAM_HUMAN" then return
if not ply._OldModel then
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function() ply:SetModel(self.Model) end)
end
end[/lua]
If player == "TEAM_HUMAN" then return -- you need an end here, or return something then end.
Instead of returning a value, you're using an IF in place of a return.
If you want to return an "IF" statement, or return x or y based on a condition ( supports nesting too ), use a ternary operation: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/ternary_operations.lua.html[/url]
You should also properly tab your code...
Then you'd see this:
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == "TEAM_HUMAN" then
return -- code stops here
if not ply._OldModel then -- code errors on this line, expecting something else...
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function()
ply:SetModel(self.Model)
end)
end
end[/lua]
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == TEAM_HUMAN then
if not ply._OldModel then -- code errors on this line, expecting something else...
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function()
ply:SetModel(self.Model)
end)
return true; -- Usually a return is done after logic is taken care of.
else
-- This is if the team is NOT human... Put whatever here, or nothing and remove the else.
end
end[/lua]
If you want a ternary operation, here's how they work:
[lua]function ITEM:OnEquip(ply, modifications)
// THIS BLOCK OF CODE
local _value = false;
if ( ply:Team( ) == TEAM_HUMAN ) then
_value = true;
end
return _value;
// END THIS BLOCK OF CODE
// IS IDENTICAL TO THIS
return ( ply:Team( ) == TEAM_HUMAN ) && true || false;
// END IS IDENTICAL TO THIS
end[/lua]
Don't use both blocks at the same time, you'll get an error.
You probably meant this for your code:
[lua]function ITEM:OnEquip(ply, modifications)
if ply:Team() == TEAM_HUMAN then
if not ply._OldModel then -- code errors on this line, expecting something else...
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function()
ply:SetModel(self.Model)
end)
else
-- This is if the team is NOT human... Put whatever here, or nothing and remove the else.
end
end[/lua][/QUOTE]
Ty for explaining so if I used that will it not ally if your TEAM_ZOMBIE?
OnEquip only does something if they're on TEAM_HUMAN. I believe Pointshop also has a CanEquip function; if you don't want the ZOMBIE team equipping at all, then make sure this is the right function and do this:
This one only blocks TEAM_ZOMBIE, but anyone else CAN equip.
[lua]function ITEM:CanEquip( ply )
if ( ply:Team( ) == TEAM_ZOMBIE ) then
return false;
end
return true; -- Same thing if you use an else return false; end - it doesn't need to be in an IF, if it is the fall-through statement.
end[/lua]
If you only want humans, and no one else, this handles it:
[lua]function ITEM:CanEquip( ply )
if ( ply:Team( ) == TEAM_HUMAN ) then
return true;
else
return false; -- This is what I mentioned above; the fall-through doesn't need to be in the if; it would work the same if you changed else to end, and deleted the end right below this line.
end
end[/lua]
[QUOTE=Acecool;44998474]OnEquip only does something if they're on TEAM_HUMAN. I believe Pointshop also has a CanEquip function; if you don't want the ZOMBIE team equipping at all, then make sure this is the right function and do this:
This one only blocks TEAM_ZOMBIE, but anyone else CAN equip.
[lua]function ITEM:CanEquip( ply )
if ( ply:Team( ) == TEAM_ZOMBIE ) then
return false;
end
return true; -- Same thing if you use an else return false; end - it doesn't need to be in an IF, if it is the fall-through statement.
end[/lua]
If you only want humans, and no one else, this handles it:
[lua]function ITEM:CanEquip( ply )
if ( ply:Team( ) == TEAM_HUMAN ) then
return true;
else
return false; -- This is what I mentioned above; the fall-through doesn't need to be in the if; it would work the same if you changed else to end, and deleted the end right below this line.
end
end[/lua][/QUOTE]
TY SO MUCH
[QUOTE=Acecool;44998474]OnEquip only does something if they're on TEAM_HUMAN. I believe Pointshop also has a CanEquip function; if you don't want the ZOMBIE team equipping at all, then make sure this is the right function and do this:
This one only blocks TEAM_ZOMBIE, but anyone else CAN equip.
[lua]function ITEM:CanEquip( ply )
if ( ply:Team( ) == TEAM_ZOMBIE ) then
return false;
end
return true; -- Same thing if you use an else return false; end - it doesn't need to be in an IF, if it is the fall-through statement.
end[/lua]
If you only want humans, and no one else, this handles it:
[lua]function ITEM:CanEquip( ply )
if ( ply:Team( ) == TEAM_HUMAN ) then
return true;
else
return false; -- This is what I mentioned above; the fall-through doesn't need to be in the if; it would work the same if you changed else to end, and deleted the end right below this line.
end
end[/lua][/QUOTE]
Simpler form:
[lua]
return (ply:Team() == TEAM_ZOMBIE)
[/lua]
or
[lua]
return (ply:Team() == TEAM_HUMAN)
[/lua]
Yes, boolean statements can be returned directly if you prefer short-hand.
You can also use ternary operations as return statements and string multiple together..
[lua]return ( ply:Team( ) == TEAM_HUMAN ) && true || ( ply:Team( ) == TEAM_ZOMBIE ) && false || true;[/lua]
Is identical to this:
[lua]if ( ply:Team( ) == TEAM_HUMAN ) then
return true;
else
if ( ply:Team( ) == TEAM_ZOMBIE ) then
return false;
else
return true;
end
end[/lua]
But, yes, brandon is right; short-hand can be much appreciated for things like this.
[QUOTE=Acecool;45001725]Yes, boolean statements can be returned directly if you prefer short-hand.
You can also use ternary operations as return statements and string multiple together..
[lua]return ( ply:Team( ) == TEAM_HUMAN ) && true || ( ply:Team( ) == TEAM_ZOMBIE ) && false || true;[/lua]
Is identical to this:
[lua]if ( ply:Team( ) == TEAM_HUMAN ) then
return true;
else
if ( ply:Team( ) == TEAM_ZOMBIE ) then
return false;
else
return true;
end
end[/lua]
But, yes, brandon is right; short-hand can be much appreciated for things like this.[/QUOTE]
&& true can be left out, it doesn't change anything. A && false || true can be simplified to not A.
This makes it much easier to read:
return ply:Team( ) == TEAM_HUMAN or ply:Team( ) != TEAM_ZOMBIE
This code doesn't work for my pointshop on my ZS server. When I become a zombie I equip the model automatically.
[code]ITEM.Name = 'Us Assault'
ITEM.Price = 250
ITEM.Model = 'models/steinman/bf4/us_01.mdl'
ITEM.AllowedUserGroups = { "superadmin", "owner" }
function ITEM:OnEquip(ply, modifications)
if not ply._OldModel then
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function() ply:SetModel(self.Model) end)
end
function ITEM:CanEquip( ply )
if ( ply:Team( ) == TEAM_UNDEAD ) then
return false;
end
return true;
end
function ITEM:OnHolster(ply)
if ply._OldModel then
ply:SetModel(ply._OldModel)
end
end
function ITEM:PlayerSetModel(ply)
ply:SetModel(self.Model)
end[/code]
Can anyone help me?
Sorry, you need to Log In to post a reply to this thread.