Jump to content

onElementModelChange


Recommended Posts

Hello guys, i need a little help.

I started to make a "Skin Protect" script.

Here is the script.

Debug Error: Bad argument @ 'getElementType' [Expected element at argument 1 got number '0']

What is the problem?

addEventHandler("onElementModelChange",root,function(source)
    if (getElementType(source) == "player") then
        if getElementModel(source) == 0 or 40 or 50 then
		    setElementModel(source,303)
			outputChatBox("You cant use that skin!",source)
		end	
    end
end)

 

Edited by TheMOG
Link to comment
addEventHandler("onElementModelChange",root,function( oldModel ) -- the first partmer not player or element 
    if (getElementType(source) == "player") then
        if getElementModel(source) == 0 or 40 or 50 then
		    setElementModel(source,303)
			outputChatBox("You cant use that skin!",source)
		end	
    end
end)
 

 

Link to comment
addEventHandler("onElementModelChange",root,function( oldModel ) -- the first partmer not player or element 
    if (getElementType(source) == "player") then
        if getElementModel(source) == 0 or getElementModel(source) == 40 or getElementModel(source) == 50 then
		    setElementModel(source,303)
			outputChatBox("You cant use that skin!",source)
		end	
    end
end)
 
  • Like 1
Link to comment

Now works, but the problem is when i add the skin, its not changing my skin to 303

 

I was wrong...

I want to enable skins only for some accountId. How can i make that? I tried like this:

local enableSkinForAccount = 
{
--AccountID, skinID
{1,303},
{4,50},
  
 
}
addEventHandler("onElementModelChange",root,function( oldModel ) -- the first partmer not player or element 
    if (getElementType(source) == "player") then
       
        skinID = getElementModel(source)
        accountID = getElementData(source,"acc.accID")
        
        if not enableSkinForAccount[accountID] and enableSkinForAccount[skinID] then
            setElementModel(source,1)
        else
            setElementModel(source,enableSkinForAccount[skinID])
        end    

    end
end)

 

 

I was wrong...

I want to enable skins only for some accountId. How can i make that? I tried like this:

 

 

local enableSkinForAccount = 
{
--AccountID, skinID
{1,303},
{4,50},


}
addEventHandler("onElementModelChange",root,function( oldModel ) -- the first partmer not player or element 
    if (getElementType(source) == "player") then
       
        skinID = getElementModel(source)
        accountID = getElementData(source,"acc.accID")
        
        if not enableSkinForAccount[accountID] and enableSkinForAccount[skinID] then
            setElementModel(source,getElementModel(source))
outputChatBox("You cant use this skin.",source)
else
setElementModel(source,enableSkinForAccount[skinID])
        end    

    end
end)
Link to comment
local enableSkinForAccount = {[1] = {303}, [4] = {50}}

addEventHandler("onElementModelChange", root, function(oldModel)
if (getElementType(source) == "player") then
local accountID = getElementData(source, "acc.accID")
if accountID and enableSkinForAccount[accountID] then
local newModel = enableSkinForAccount[accountID]
if tonumber(newModel) then
setElementModel(source, newModel[1])
end
else
setElementModel(source, oldModel)
end
end
end)


If accountID exists and found in the enableSkinForAccount table, then it'll set his new model (when element model change event is triggered) to the one set from the table. If accountID doesn't exist and isn't found in the table, it'll return his previous model.

Link to comment

try this , not tested

rotectSkins = { 
[299] = {5},
}
addEventHandler("onElementModelChange", root,
function (oldModel)
    if getElementType(source) == "player" then
        setTimer ( function ( player, model ) 
            if ( ProtectSkins[getElementModel ( player )] and not ProtectSkins[getElementModel ( player )][getElementData(player,"acc.accID")] ) then
                setElementModel ( player, model )
                outputChatBox ( 'Model is protected', player)
            end
        end, 500, 1, source, oldModel)
    end
end)

 

Edited by 'SimpleArtS . .
Link to comment
  • Moderators
local enableSkinForAccount = 
{
	[1] = true,
	[4] = true
}

addEventHandler( "onElementModelChange", root,
	function( oldModel )
		if (getElementType(source) == "player") then
	
			if enableSkinForAccount[ tonumber(getElementData(source,"acc.accID")) ] ~= true then
				setElementModel( source, oldModel )
			end
		end
	end
)

Try it.

 

EDIT:

The code above will allow the player to use only one skin. If you just want to block some skins, try this:

local enableSkinForAccount = 
{
	[1] = true, [4] = true
}
local disallowedSkins = { [303] = true, [50] = true }

addEventHandler( "onElementModelChange", root,
	function( oldModel )
		if (getElementType(source) == "player") then
	
			if disallowedSkins[ getElementModel(source) ]
				and enableSkinForAccount[ tonumber(getElementData(source,"acc.accID")) ] ~= true then
				
				setElementModel( source, oldModel )
			end
		end
	end
)

 

Edited by DNL291
Link to comment

@DNL291 Example:

Your AccountID is 2.

I want to enable the 303 - skin id only for your accountID! So nobody can have 303 skin id only you.

Something like this:

Table for AccountID and skinID..

 

  1. local enableSkinForAccount = 
    {
    --AccountID, skinID
    {1,303},
    {4,50},
    
    
    }
    addEventHandler("onElementModelChange",root,function( oldModel ) -- the first partmer not player or element 
        if (getElementType(source) == "player") then
           
            skinID = getElementModel(source)
            accountID = getElementData(source,"acc.accID")
            
            if not enableSkinForAccount[accountID] and enableSkinForAccount[skinID] then
                setElementModel(source,getElementModel(source))
    outputChatBox("You cant use this skin.",source)
    else
    setElementModel(source,enableSkinForAccount[skinID])
            end    
    
        end
    end)
Edited by TheMOG
Link to comment
14 hours ago, TheMOG said:

Not working, no debug error.

That means element data "acc.accID" data doesn't exist. Please make sure you're giving us the right data name.

Try this:
 

local enableSkinForAccount = {[1] = {303}, [4] = {50}}

addEventHandler("onElementModelChange", root, function(oldModel)
if (getElementType(source) == "player") then
local accountID = getElementData(source, "acc.accID")
if accountID and enableSkinForAccount[accountID] then
local newModel = enableSkinForAccount[accountID]
if newModel and tonumber(newModel[1]) then
setElementModel(source, newModel[1])
end
else
setElementModel(source, 0)
end
else
setElementModel(source, oldModel)
end
end)


If your model is changed to '0', then that's because "acc.accID" is returning nil.

@TheMOG

Edited by Infinity#
Link to comment

@Infinity# i gave a right data name. 

But still not working. Tried to run in runcode this:

executed command: outputChatBox(getElementData(me, "acc.accID"))
1
Command results: true [boolean]

 i got my acc id which is 1.

No debug error..

 

In the table the first is the AccountID, second is the skinID.

local enableSkinForAccount = {
[HERE IS The AccountID] = {Here is the skinID} 
}

addEventHandler("onElementModelChange", root, function(oldModel)
    if (getElementType(source) == "player") then
    local accountID = getElementData(source, "acc.accID")
        if accountID and enableSkinForAccount[accountID] then
        local newModel = enableSkinForAccount[accountID]
            if newModel and tonumber(newModel[1]) then
                setElementModel(source, newModel[1])
            end
        else
            setElementModel(source, 0)
        end
    else
        setElementModel(source, oldModel)
    end
end)

 

Edited by TheMOG
Link to comment

So, now i tested again, i dont really know whats the problem..

My accountID is 1, 

In the table the 303 - skin is enabled only for my account. But, when i set my skin to 303, its not changing my model, so i thing something is conversely.

The 50 - SkinID is enabled to accountID 4 , which is not me, and i can have that skin.

When i change my model to 303  i dont get anything in the chat, but when i change the skin to 50, then i get all the messages from the script..

local enableSkinForAccount = {
[1] = {303},
[4] = {50}
}

addEventHandler("onElementModelChange", root, function(oldModel)
    if (getElementType(source) == "player") then
    outputChatBox("1")
    local accountID = getElementData(source, "acc.accID")
        if accountID and enableSkinForAccount[accountID] then
        outputChatBox("2")
        local newModel = enableSkinForAccount[accountID]
            if newModel and tonumber(newModel[1]) then
                outputChatBox("3")
                setElementModel(source, newModel[1])
            end
        else
            outputChatBox("4")
            setElementModel(source, 0)
        end
    else
        outputChatBox("5")
        setElementModel(source, oldModel)
    end
end)

 

I thing this is not that hard just for me.. What i want is very simple.. I store the accountID in "data". And i want to enable skins only for accountId.

Like: your accountID is 1, your custom skin id is 303. I want to make thath, nobody can have that model only you. 

Edited by TheMOG
Link to comment
  • Moderators

Just show the results man, since the results can tell you why it isn't working. You are talking too much, keep it short and neat.

 

Try this and show the results of both accounts:

 

-- I am not sure why you use tables inside tables while there is only one item per accountID
local enableSkinForAccount = {
	[1] = {303},
	[4] = {50}
}
--[[ it can be like this:
local enableSkinForAccount = {
	[1] = 303,
	[4] = 50
}
]]



addEventHandler("onElementModelChange", root, function(oldModel)
    if (getElementType(source) == "player") then
		iprint("element is a player")
		
		local accountID = getElementData(source, "acc.accID")
		iprint("accountID:", accountID, ", it's type is:", type(accountID))
		
		accountID = tonumber(accountID) -- convert it to a number just incase it is a string
        if accountID and enableSkinForAccount[accountID] then
		
			iprint("accountID has been found in enableSkinForAccount")
			local newModel = enableSkinForAccount[accountID]
			if newModel and newModel[1] then
			
				iprint("newModel data has been found:", newModel, ", it's type is:", type(newModel))
				
				iprint("first item in newModel is:", newModel[1], ", it's type is:", type(newModel[1]))
				local model = tonumber(newModel[1])
				
				
				if model then
				
					iprint("model has been found, now apply the model to the player")
					if not setElementModel(source, model) then
						iprint("the model has been failed to set")
					end
				end
			end
		else
			iprint("accountID isn't found in enableSkinForAccount")
			setElementModel(source, 0)
		end
    else
        iprint("element isn't a player")
        setElementModel(source, oldModel)
    end
end)

 

Link to comment

When i change my model to 303 which is enabled to my accountID(1), i dont get the skin, and i dont get anything in debug. But when i try the 50 skinId which is enabled to AccountID 2 i got these:

skin50.png

another account: (accountID: 2)

image.png

Another account:

303.png

 

Edited by TheMOG
Link to comment
  • Moderators

Maybe you want something like this:


local enableSkinForAccount = {
	[1] = {
		[303] = true,
		-- can add more
	},
	[4] = {
		[50] = true
	}
}



addEventHandler("onElementModelChange", root, function(oldModel)
    if (getElementType(source) == "player") then
		iprint("element is a player")
		
		local accountID = getElementData(source, "acc.accID")
		iprint("accountID:", accountID, ", it's type is:", type(accountID))
		
		accountID = tonumber(accountID) -- convert it to a number just incase it is a string
		local currentModel = getElementModel(source)
        if not (accountID and enableSkinForAccount[accountID] and enableSkinForAccount[accountID][currentModel]) then
			iprint("accountID isn't found in enableSkinForAccount")
			setElementModel(source, 0)
		end
    else
        iprint("element isn't a player")
        setElementModel(source, oldModel)
    end
end)

 

Link to comment
  • Moderators
11 hours ago, TheMOG said:

stil not working

super ultra f. useless reply ever.

  • You should debug your account data as well.
  • Check if you can change the player his skin after the event has been called.
  • Making sure that no other resources are in the way. (like roleplay security)
  • The debug says that the skin set failed. Which is most likely because the player already has the same skin.
  • Put the debug messages in order of time and do not stack up if they shouldn't be put together. Only one part of the code can run at the same time, so stacking up like that should be impossible if it is done by time.
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...