Jump to content

Help me out please


mint3d

Recommended Posts

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

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
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

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
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

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

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...