itHyperoX Posted July 26, 2017 Share Posted July 26, 2017 (edited) 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 July 26, 2017 by TheMOG Link to comment
iMr.WiFi..! Posted July 26, 2017 Share Posted July 26, 2017 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
itHyperoX Posted July 26, 2017 Author Share Posted July 26, 2017 Now when i change my skin, i get "You cant use that skin!" on all skin.. Link to comment
iMr.WiFi..! Posted July 26, 2017 Share Posted July 26, 2017 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) 1 Link to comment
itHyperoX Posted July 26, 2017 Author Share Posted July 26, 2017 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
Infinity# Posted July 27, 2017 Share Posted July 27, 2017 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
itHyperoX Posted July 27, 2017 Author Share Posted July 27, 2017 Not working, no debug error. Link to comment
Simple. Posted July 27, 2017 Share Posted July 27, 2017 (edited) 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 July 27, 2017 by 'SimpleArtS . . Link to comment
DNL291 Posted July 27, 2017 Share Posted July 27, 2017 (edited) 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 July 27, 2017 by DNL291 Link to comment
itHyperoX Posted July 27, 2017 Author Share Posted July 27, 2017 (edited) @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.. 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 July 27, 2017 by TheMOG Link to comment
Infinity# Posted July 28, 2017 Share Posted July 28, 2017 (edited) 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 July 28, 2017 by Infinity# Link to comment
itHyperoX Posted July 28, 2017 Author Share Posted July 28, 2017 (edited) @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 July 28, 2017 by TheMOG Link to comment
Moderators IIYAMA Posted July 28, 2017 Moderators Share Posted July 28, 2017 (edited) if newModel and newModel[1] then local model = tonumber(newModel[1]) if model then setElementModel(source, model) end end not sure what your code problem is... pls debug your code more manually. Edited July 28, 2017 by IIYAMA Link to comment
itHyperoX Posted July 28, 2017 Author Share Posted July 28, 2017 @IIYAMA "no debug error" Link to comment
Moderators IIYAMA Posted July 28, 2017 Moderators Share Posted July 28, 2017 Just now, TheMOG said: @IIYAMA "no debug error" Read my tutorial, then you would know what to do. Link to comment
itHyperoX Posted July 29, 2017 Author Share Posted July 29, 2017 (edited) 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 July 29, 2017 by TheMOG Link to comment
Moderators IIYAMA Posted July 29, 2017 Moderators Share Posted July 29, 2017 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
coNolel Posted July 29, 2017 Share Posted July 29, 2017 use a loop trough the accoynts table and check if the id is on the table then change the model. else print u cant use this skin Link to comment
itHyperoX Posted July 29, 2017 Author Share Posted July 29, 2017 (edited) 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: another account: (accountID: 2) Another account: Edited July 29, 2017 by TheMOG Link to comment
Moderators IIYAMA Posted July 29, 2017 Moderators Share Posted July 29, 2017 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 IIYAMA Posted July 30, 2017 Moderators Share Posted July 30, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now