I know I probably worded the title wrong for what I am trying to do, but here goes. I have a weapon SWEP that I want to load a value from the gamemode I am playing (stranded)
In the gamemode init.lua file it says this
[lua]function PlayerMeta:HasUnlock( text )
if ( self.FeatureUnlocks and self.FeatureUnlocks[text] ) then return true end
return false
end[/lua]
And in the SWEP I tried this, even though I kinda knew it wasn't going to work
[lua]function SWEP:SecondaryAttack()
local ply = self.Owner
if ( ply:HasUnlock( "Knife_Throwing" ) ) then --cut the rest out to make the post size smaller[/lua]
Of course the value HasUnlock returns nil when trying to use the secondary attack. How can I load the HasUnlock from the init, and have it read the values properly from within the SWEP? If I can't do it within the SWEP how else can I do it?
I am not looking for free code, just point me in the right direction and I can figure it out ;)
It cannot return nil. Make sure your ply is a player.
[QUOTE=Robotboy655;42912819]It cannot return nil. Make sure your ply is a player.[/QUOTE]
I don't quite understand what you are saying, would ply = self.Owner not equal the player using the weapon?
(5:40 AM for me right now, if I have said anything stupid ill fix it in the morning)
I get no errors regarding ply, the error says HasUnlock returned as a nil value.
[code][ERROR] gamemodes/gmstranded/entities/weapons/kermite_knife_tanto/shared.lua:60: attempt to call method 'HasUnlock' (a nil value)
1. unknown - gamemodes/gmstranded/entities/weapons/kermite_knife_tanto/shared.lua:60
[/code]
do print( ply ) and see what it prints.
The PlayerMeta and the self.Owner both equal the same value when printed, (did a print of a spawn function that used PlayerMeta) and still no go on this, same error as before. You are sure it has nothing to do with the fact it's a SWEP? Are SWEP's allowed to load values from the init.lua file from a gamemode?
[editline]19th November 2013[/editline]
Should also add, so I don't get too many "dumb" votes, that I am new to Lua and I learn best by doing things, not reading - which is why I am here for advice =p
The results of both PlayerMeta when called, and self.Owner is
Player [1][TRUE]Kevin]
This is nothing to do with the fact that it's a SWEP, the function should be available everywhere as long as the gamemode is active.
Ah, then there is something wrong on my end, I will figure it out thanks for the information.
For anyone looking at this in the future, it was a very stupid fix, I wasn't running the script as SERVER so it wasn't detecting it.
Sorry, you need to Log In to post a reply to this thread.