Modifying permissions for Pixeltailgame's Media Player
5 replies, posted
That's the best suiting title I could think of. I'm not very creative, but I think it describes my problem well.
Okay on to the issue I am having.
So this addon, I have been using on my darkrp server for a few months now. I have been trying to get it so that the CPPI owner can be a privileged user of his own media player. So for example, they could skip, pause, and delete videos from the queue. Now I have it setup right so that the media player when purchased from the F4 menu will set the owner using CPPISetOwner(). That works fine and dandy, FPP recognizes the player owns the entity and they can move it around and such. Now the actual screen and menu for the media player are a child entity of the mediaplayer. For the life of me I can not get it to check the CPPI owner of the parent entity.
Now normally I can solve my own problems with stuff like this, however everything I try just breaks the media player. Usually saying the "the module CPPIGetOwner has returned a NULL value" Or something along the lines of that. So its clearly I am calling the owner of the wrong thing, because I know the parent does have an owner set properly.
This is the code I am attempting to modify
[CODE]
---
-- Determines if the player has privileges to use media controls (skip, seek,
-- etc.). Override this for custom behavior.
--
function MEDIAPLAYER:IsPlayerPrivileged( ply )
return ply == self:GetOwner() or ply:IsAdmin()
end
[/CODE]
Now the way it is works fine if you are spawn the media player from the Q menu, even if you are not an admin. However if you buy it through the F4 menu then only admins and higher pass the check.
Anyone can add media, and that's fine.
I would be super grateful if you guys could give me a push in the right direction. I dont expect any hand holding, just an extra set of eyes to see where I am going wrong.
Here is the Git hub for the media player as well if it helps!
[url]https://github.com/pixeltailgames/gm-mediaplayer[/url]
Cheers!
Please post your code for adding it to the f4 menu in darkrp
[QUOTE=rtm516;50350890]Please post your code for adding it to the f4 menu in darkrp[/QUOTE]
This is what Im using to set the owner
[CODE]local entTable = { ["mediaplayer_tv"] = true,
["gmt_instrument_piano"] = true,
["circl_printer_amazing_one"] = false,
["3d_boombox"] = true,
}
hook.Add("playerBoughtCustomEntity", "SetOwnerOnEntBuy", function(ply, enttbl, ent, price)
if entTable[ent:GetClass()] then
ent:CPPISetOwner(ply)
end
end)
[/CODE]
And this is just the basic addentity stuff
[CODE]DarkRP.createEntity("Media Player", {
ent = "mediaplayer_tv",
model = "models/gmod_tower/suitetv_large.mdl",
price = 10000,
max = 1,
category = "Entertainment",
cmd = "buytv",
getPrice = function(ply, price) return table.HasValue({"admin", "superadmin", "owner", "Staff Committee", "DonatorPlus", "Event Coordinator"}, ply:GetNWString("usergroup")) and price * 0.75 or price end,
})[/CODE]
Okay so I was think and sorta messing around, and I think I might be on to something here. Trying to go in a different direction. To just get the F4 menu to set the Creator, as that seems to be how the media player determines its owner.
So I did this,
[CODE]local mediap = ents.Create("mediaplayer_tv")
DarkRP.createEntity("Media Player", {
ent = "mediaplayer_tv",
model = "models/gmod_tower/suitetv_large.mdl",
price = 10000,
max = 1,
category = "Entertainment",
cmd = "buytv",
getPrice = function(ply, price) return table.HasValue({"admin", "superadmin", "owner", "Staff Committee", "DonatorPlus", "Event Coordinator"}, ply:GetNWString("usergroup")) and price * 0.75 or price end,
spawn = function(ply, tr, tblEnt) if ( !IsValid( mediap )) then return end mediap:SetCreator(ply) mediap:Spawn() end,
})[/CODE]
Where the spawn = is. It seems to be getting me somewhere, however it throws an error when I open the F4 menu "attempt to call field 'Create' (a nil value)" So I looked that up, and it seems to be that I need to wrap it with a if SERVER. However if I do that, simpler gives an error about not being able to make sense of anything before the , on line 49(line 49 is where the spawn = line is)
Any suggestions?
[QUOTE=MuffinsDerp;50358973]Okay so I was think and sorta messing around, and I think I might be on to something here. Trying to go in a different direction. To just get the F4 menu to set the Creator, as that seems to be how the media player determines its owner.
So I did this,
[CODE]-snip-[/CODE]
Where the spawn = is. It seems to be getting me somewhere, however it throws an error when I open the F4 menu "attempt to call field 'Create' (a nil value)" So I looked that up, and it seems to be that I need to wrap it with a if SERVER. However if I do that, simpler gives an error about not being able to make sense of anything before the , on line 49(line 49 is where the spawn = line is)
Any suggestions?[/QUOTE]
Try this
[LUA]
DarkRP.createEntity("Media Player", {
ent = "mediaplayer_tv",
model = "models/gmod_tower/suitetv_large.mdl",
price = 10000,
max = 1,
category = "Entertainment",
cmd = "buytv",
getPrice = function(ply, price) return table.HasValue({"admin", "superadmin", "owner", "Staff Committee", "DonatorPlus", "Event Coordinator"}, ply:GetNWString("usergroup")) and price * 0.75 or price end,
spawn = function(ply, tr, tblEnt)
local mediap = ents.Create("mediaplayer_tv")
if (!IsValid(mediap)) then return end
mediap:SetCreator(ply)
return mediap
end,
})
[/LUA]
Ill give that a go, thanks!
[editline]20th May 2016[/editline]
You are a true MVP, you fixed the error I was having! I had to add a bit more to it to get it to work, but it works. Players are in the Privileged group! Here's how, in the case that someone on google in the future has the same issue as me!
[CODE]DarkRP.createEntity("Media Player", {
ent = "mediaplayer_tv",
model = "models/gmod_tower/suitetv_large.mdl",
price = 10000,
max = 1,
category = "Entertainment",
cmd = "buytv",
getPrice = function(ply, price) return table.HasValue({"admin", "superadmin", "owner", "Staff Committee", "DonatorPlus", "Event Coordinator"}, ply:GetNWString("usergroup")) and price * 0.75 or price end,
spawn = function(ply, tr, tblEnt)
local mediap = ents.Create( "mediaplayer_tv" )
local trace = ply:GetEyeTrace()
local vector = trace.HitPos
vector.z = vector.z + 20
if (!IsValid(mediap)) then return end
mediap:SetCreator(ply)
mediap:SetPos( vector )
mediap:Spawn()
mediap:Activate()
return mediap
end,
})[/CODE]
Only thing I'm going to change is the SetPos, I decided I don't like it spawning at eyetrace. I'd rather it be relative to the player.
Sorry, you need to Log In to post a reply to this thread.