Jump to content

[HELP] String to Element


steadyfi

Recommended Posts

Hello all.

I've got a little problem with a script. Im trying to make a command to set a player as Premium.

I'm using setAccountData but when I try it tells me that it expected ELEMENT but it got a STRING

Is there any way i can get a Element and not a string ?

Code (Server-Side):

--[[ 
## Set Premium 
]]-- 
function setPremium(playerSource, cmd, target, kit) 
    if target and kit then 
        local targetAccount = getPlayerAccount(target) 
        if targetAccount and not isGuestAccount(targetAccount) then 
            setAccountData(targetAccount, "premium_kit", kit) 
            outputChatBox("Player "..target.." has been added as Premium with kit: "..kit.." !", playerSource) 
        end 
    else 
        outputChatBox("Player not found or error accrued" ,playerSource, 255, 0, 0) 
    end 
end 
addCommandHandler("premium", setPremium) 

Error:

WARNING: basics\modules\utils_server.lua:84: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got string 'Steady'] 

Thanks :D

Edited by Guest
Link to comment

addCommandHandler parameters :-

arg1, arg2, ...: Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain nil. You can deal with a variable number of arguments using the vararg expression, as shown in Server Example 2 below. 

so target is a string that contain "nil" , defined it as a player i guess ?

Link to comment
addCommandHandler parameters :-
arg1, arg2, ...: Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain nil. You can deal with a variable number of arguments using the vararg expression, as shown in Server Example 2 below. 

so target is a string that contain "nil" , defined it as a player i guess ?

Yes, the variable target is the player element. But it doesn't return nil, it is returning as a string and I need a element

Link to comment
--[[ 
## Set Premium 
]]-- 
function setPremium(playerSource, cmd, target, kit) 
    if getPlayerFromName(target) and kit then 
        local targetAccount = getPlayerAccount(getPlayerFromName(target)) 
        if targetAccount and not isGuestAccount(targetAccount) then 
            setAccountData(targetAccount, "premium_kit", kit) 
            outputChatBox("Player "..target.." has been added as Premium with kit: "..kit.." !", playerSource) 
        end 
    else 
        outputChatBox("Player not found or error accrued" ,playerSource, 255, 0, 0) 
    end 
end 
addCommandHandler("premium", setPremium) 

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