mint3d Posted November 9, 2013 Share Posted November 9, 2013 I need help is there any way to make a command that does this setElementData(getPlayerFromName("Name"),"Object",1) Link to comment
tosfera Posted November 9, 2013 Share Posted November 9, 2013 there is; addCommandHandler ( "object", function ( thePlayer, theCommand, victim ) setElementData ( getPlayerFromName ( victim ), "Object", 1 ); end ); Link to comment
mint3d Posted November 9, 2013 Author Share Posted November 9, 2013 function giveplayeritem ( player, command ) setElementData(getPlayerFromName("Jordan"),"Engine",1) end addCommandHandler ( "Jordan", giveplayeritem ) Done this and it works but thanks for the help and question say i wanted to give item like using setElementData(getPlayerFromName("Jordan"),"Object",1) us there a way to like /giveitem Jordan and then the item Link to comment
tosfera Posted November 9, 2013 Share Posted November 9, 2013 If you want to give item's to play you could either use a database ( mysql or sqlite ) or you can use the setAccountData / getAccountData. The elementData will be deleted whenever a player reconnects. Try this; addCommandHandler ( "giveItem", function ( thePlayer, theCommand, happyPlayer, itemId ) if ( thePlayer == ") then -- just for safety local account = getPlayerAccount ( happyPlayer ); if ( account ) then -- if he is logged in setAccountData ( account, "item1", itemId ); else outputChatBox ( "This player is not logged in.", thePlayer ); end end end ); note that this will only allow you to give 1 item each person. You'll have to create a table value or loop through all his data to find out if you can give a new item or add new values to it etc. Link to comment
mint3d Posted November 9, 2013 Author Share Posted November 9, 2013 Ok your script i am using the dayz so i was only looking for the setElementData(getPlayerFromName("Jordan"),"Object",1) as they have to keep it when they login and stuff and reconnect so is that possible? Link to comment
tosfera Posted November 9, 2013 Share Posted November 9, 2013 Ehmm well you can just change the "item1" to "object" and "itemId" to 1. That would fix it. Link to comment
mint3d Posted November 9, 2013 Author Share Posted November 9, 2013 addCommandHandler ( "giveItem", function ( thePlayer, theCommand, happyPlayer, 1 ) if ( thePlayer == "Jordan" ) then -- just for safety local account = getPlayerAccount ( happyPlayer ); if ( account ) then -- if he is logged in setAccountData ( account, "object", 1 ); else outputChatBox ( "This player is not logged in.", thePlayer ); end end end ); [2013-11-09 19:43:38] ERROR: Loading script failed: gates\gates.lua:2: or '...' expected near '1' Link to comment
tosfera Posted November 9, 2013 Share Posted November 9, 2013 change function ( thePlayer, theCommand, happyPlayer, 1 ) to function ( thePlayer, theCommand, happyPlayer ) Link to comment
mint3d Posted November 9, 2013 Author Share Posted November 9, 2013 Didn't work like i wanted it to i want to do somthing like /giveitem Jordan Engine which would make this setElementData(getPlayerFromName("Name"),"Object",1) look like this setElementData(getPlayerFromName("Jordan"),"Engine",1) and it would give him the object Link to comment
tosfera Posted November 9, 2013 Share Posted November 9, 2013 addCommandHandler ( "giveItem", function ( thePlayer, theCommand, happyPlayer, item ) if ( thePlayer == "Jordan" ) then -- just for safety local account = getPlayerAccount ( happyPlayer ); if ( account ) then -- if he is logged in setAccountData ( account, tostring ( item ), 1 ); else outputChatBox ( "This player is not logged in. Their items will be lost when he or she reconnects", thePlayer ); end setElementData ( happyPlayer, tostring ( item ), 1 ); end end ); usage; /giveItem Jordan Engine Link to comment
mint3d Posted November 9, 2013 Author Share Posted November 9, 2013 I dont want it to go away tho i want it to stay and that doesnt work at all Link to comment
tosfera Posted November 9, 2013 Share Posted November 9, 2013 setAccountData adds the item to the account of the player. As long as the player is logged in and you're using the command, it will stay. IF he ins't logged in, it will dissapear. So just make sure your players are logged in. To add the data back when they login; addEventHandler ( "onPlayerLogin", root, function ( thePlayer ) local account = getPlayerAccount ( thePlayer ); local engine = getAccountData ( account, "Engine" ); if ( engine ) then setElementData ( thePlayer, "Engine", 1 ); end end ); Link to comment
mint3d Posted November 9, 2013 Author Share Posted November 9, 2013 Im done your stuff is not working at all for me sorry someone please help a bit more experienced please Link to comment
tosfera Posted November 9, 2013 Share Posted November 9, 2013 Im done your stuff is not working at all for me sorry someone please help a bit more experienced please Aye, you made my day. Link to comment
TAPL Posted November 9, 2013 Share Posted November 9, 2013 addEventHandler("onPlayerLogin", root, function(_, account) local engine = getAccountData(account, "Engine") if (engine) then setElementData(source, "Engine", 1) end end) 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