Invalid DarkRP method stub! Field "metatable" is invalid!
19 replies, posted
The above error refers to this piece of code which I took from the IsCP() function and tried to edit for my own job.
DarkRP.PLAYER.isSaddam = DarkRP.stub{
name = "isSaddam",
description = "Whether this player is Saddam",
parameters = {
},
returns = {
{
name = "answer",
description = "Whether this player is Saddam",
type = "boolean"
}
},
metatable = DarkRP.PLAYER
}
Im quite new to lua and am still learning so I have probably done something really dumb, any help is appreciated.
You don't need that stub stuff unless you are making a wiki.
[QUOTE=Bo98;45579098]You don't need that stub stuff unless you are making a wiki.[/QUOTE]
Thanks.
I took out .stub and now get an error "attempt to call global 'DarkRP' (a table value)"
I mean that the whole stuff you posted is the wiki stub.
You want the Lua function:
[url]https://github.com/FPtje/DarkRP/blob/master/gamemode/modules/police/sh_init.lua#L18-22[/url]
Remember to include what sets plyMeta (line 1).
Thanks. I now get that im calling global isSaddam a nil value.
local plyMeta = FindMetaTable( "Player" )
function plyMeta:isSaddam()
if not IsValid(self) then return false end
local Team = self:Team()
if Team == Team_SADDAM then return true
else return false end
end
function GAMEMODE:OnNPCKilled(victim, ent, weapon)
-- If something killed the npc
if not ent then return end
if ent:IsVehicle() and ent:GetDriver():IsPlayer() then ent = ent:GetDriver() end
-- If it wasn't a player directly, find out who owns the prop that did the killing
if not ent:IsPlayer() then
ent = Player(tonumber(ent.SID) or 0)
end
-- If we know by now who killed the NPC, pay them if they are Saddam.
if IsValid(ent) and isSaddam(ply) then <------ PROBLEM IS HERE
ent:addMoney("25")
end
end
It's ply:isSaddam not isSaddam(ply)
[QUOTE=Jarva;45581114]It's ply:isSaddam not isSaddam(ply)[/QUOTE]
That just gives me tried to index 'ply' a nil value lol :P
[QUOTE=AdamW95;45581417]That just gives me tried to index 'ply' a nil value lol :P[/QUOTE]
Then the "ply" you were using as an argument doesn't exist in the first place. You need to use ent:IsSaddam()
No errors at least but it doesn't seem to be working all the time. It only works sometimes which is strange..
Add print statements throughout the code to debug it.
Okay so the isSaddam() returns true fine but for some reason the game doesn't get inside of the code
if IsValid(ent) and ent:isSaddam() then
ent:addMoney("25")
end
I have even tried it without the IsValid(ent) part so for some reason even though ent:isSaddam() is returning true the condition doesn't seem to be met :tinfoil:
Are you sure it's Team_SADDAM and not TEAM_SADDAM
[QUOTE=crazyscouter;45582648]Are you sure it's Team_SADDAM and not TEAM_SADDAM[/QUOTE]
It is TEAM, i changed it earlier and forgot to post it here, thanks. Still same problem though
Post your most updated code please.
[CODE]local plyMeta = FindMetaTable( "Player" )
function plyMeta:isSaddam()
if not IsValid(self) then return false end
local Team = self:Team()
if Team == TEAM_SADDAM then return true and Msg("TRUE")
else return false and Msg("FALSE") end
end
function GAMEMODE:OnNPCKilled(victim, ent, weapon)
-- If something killed the npc
if not ent then return end
if ent:IsVehicle() and ent:GetDriver():IsPlayer() then ent = ent:GetDriver() end
-- If it wasn't a player directly, find out who owns the prop that did the killing
if not ent:IsPlayer() then
ent = Player(tonumber(ent.SID) or 0)
end
-- If we know by now who killed the NPC, pay them if they are Saddam.
if ent:isSaddam() then
Msg("ADDMONEY")
ent:addMoney("25")
end
end[/CODE]
With code tags.
edited to use code tags.
also when the player is not saddam it doesnt seem to return true or false.
You're returning the Msg, not true / false. The return true and return false should be the last thing in your if statement.
[editline]5th August 2014[/editline]
Example:
[lua]
function plyMeta:isSaddam()
return self:IsPlayer() && self:Team() == TEAM_SADDAM || false
end
[/lua]
Problem solved, thanks everyone for your help much appreciated :)
Sorry, you need to Log In to post a reply to this thread.