Jump to content

Ajuda com commandHandler, e função


Recommended Posts

Olá, fiz o seguinte script no lado client, porém, da esse erro de que a função, invés de ser localPlayer ele pega  a string do comando, "colher"
 

dff = engineLoadDFF("grassplant01.dff")
engineReplaceModel(dff, 3409)

addCommandHandler("devmode",
    function()
        setDevelopmentMode(true)
    end
)

plantas = {
    {-1014, -1609.2, 75.36},
    {-1010, -1609.242, 75.367},
    {-1006, -1609.19, 75.36},
    {-1002, -1609.104, 75.36},
    {-998, -1609.082, 75.36},
    {-994, -1609.037, 75.36},
    {-990, -1609.037, 75.36},
    {-1014, -1613, 75.36},
    {-1010, -1613, 75.367},
    {-1006, -1613, 75.36},
    {-1002, -1613, 75.36},
    {-998, -1613, 75.36},
    {-994, -1613, 75.36},
    {-990, -1613, 75.36},
    {-1014, -1617, 75.36},
    {-1010, -1617, 75.367},
    {-1006, -1617, 75.36},
    {-1002, -1617, 75.36},
    {-998, -1617, 75.36},
    {-994, -1617, 75.36},
    {-990, -1617, 75.36},
    {-1014, -1621, 75.36},
    {-1010, -1621, 75.367},
    {-1006, -1621, 75.36},
    {-1002, -1621, 75.36},
    {-998, -1621, 75.36},
    {-994, -1621, 75.36},
    {-990, -1621, 75.36},
}

for i, v in ipairs ( plantas ) do 
    plantas = createObject(3409, v[1],v[2],v[3])
    colP = createColCircle(v[1],v[2],1.5)
end


function fcm1(localPlayer, commandname)
    if isElementWithinColShape(localPlayer, colP) then
        setPedAnimation(localPlayer,"INT_HOUSE","wash_up",10000,false,false,true,false)
        setTimer(function ()
            star = getPlayerWantedLevel()
            setPlayerWantedLevel(localPlayer)
            setPedAnimation(localPlayer)
            givePlayerMoney(math.random(500,1000))
        end,10000,1)
    end
end
addCommandHandler("colher", fcm1)

erro: Bad argument @ 'isElementWithinColShape' [Expected element at argument 1,got string 'colher']

Link to comment

Eu acho que voce nao precisa especificar o localPlayer no paramentro da função

só o ( commandname )

se n o comando vai ler o localPlayer tb exemplo

/colher [localPlayer] [comando]

e nao entendi tb pq o commandname ali se voce nao ta especificando ele em lugar nenhum

testa sem

function fcm1()

nao tenho certeza nunca usei assim em client

 

Edited by Furzy
  • Thanks 1
Link to comment

Fiz algumas mudanças, colocando invés de colCircle, coloquei markers, e por algum motivo não está mais funcionando
 

dff = engineLoadDFF("grassplant01.dff")
engineReplaceModel(dff, 3409)

addCommandHandler("devmode",
    function()
        setDevelopmentMode(true)
    end
)

plantas = {
    {-1014, -1609.2, 75.36},
    {-1010, -1609.242, 75.367},
    {-1006, -1609.19, 75.36},
    {-1002, -1609.104, 75.36},
    {-998, -1609.082, 75.36},
    {-994, -1609.037, 75.36},
    {-990, -1609.037, 75.36},
    {-1014, -1613, 75.36},
    {-1010, -1613, 75.367},
    {-1006, -1613, 75.36},
    {-1002, -1613, 75.36},
    {-998, -1613, 75.36},
    {-994, -1613, 75.36},
    {-990, -1613, 75.36},
    {-1014, -1617, 75.36},
    {-1010, -1617, 75.367},
    {-1006, -1617, 75.36},
    {-1002, -1617, 75.36},
    {-998, -1617, 75.36},
    {-994, -1617, 75.36},
    {-990, -1617, 75.36},
    {-1014, -1621, 75.36},
    {-1010, -1621, 75.367},
    {-1006, -1621, 75.36},
    {-1002, -1621, 75.36},
    {-998, -1621, 75.36},
    {-994, -1621, 75.36},
    {-990, -1621, 75.36},
}

for i, v in ipairs ( plantas ) do 
    plantas = createObject(3409, v[1],v[2],v[3])
    colP = createMarker(v[1],v[2],v[3],"cylinder",2.5,0,0,0,0)
end


function fcm1()
    if isElementWithinMarker(localPlayer, colP) then
        setPedAnimation(localPlayer,"INT_HOUSE","wash_up",10000,true,false,true,false,10)
        setTimer(function ()
            setPedAnimation(localPlayer)
            givePlayerMoney(math.random(500,1000))
        end,10000,1)
    end
end
addCommandHandler("colher", fcm1)

 

edit:Não há nenhum erro no debugscript, e o script está no lado client

Edited by EW1611
Link to comment
  • Other Languages Moderators

Sua lógica de criação do plantas e colP está errada. Você precisa colocá-los em uma table vazia antes de criá-los. Senão a variável sempre será substituída a cada execução do loop. Isso significa que ao final do loop, você criou vários plantas e vários colP, mas somente o último pode ser acessado pelo script, pois são os únicos que estão nas variáveis plantas e colP, os outros ficaram sem variável para serem chamados. Dessa forma, somente 1 planta e 1 colP funcionam.

dff = engineLoadDFF("grassplant01.dff")
engineReplaceModel(dff, 3409)

addCommandHandler("devmode",
    function()
        setDevelopmentMode(true)
    end
)

plantas = {
    {-1014, -1609.2, 75.36},
    {-1010, -1609.242, 75.367},
    {-1006, -1609.19, 75.36},
    {-1002, -1609.104, 75.36},
    {-998, -1609.082, 75.36},
    {-994, -1609.037, 75.36},
    {-990, -1609.037, 75.36},
    {-1014, -1613, 75.36},
    {-1010, -1613, 75.367},
    {-1006, -1613, 75.36},
    {-1002, -1613, 75.36},
    {-998, -1613, 75.36},
    {-994, -1613, 75.36},
    {-990, -1613, 75.36},
    {-1014, -1617, 75.36},
    {-1010, -1617, 75.367},
    {-1006, -1617, 75.36},
    {-1002, -1617, 75.36},
    {-998, -1617, 75.36},
    {-994, -1617, 75.36},
    {-990, -1617, 75.36},
    {-1014, -1621, 75.36},
    {-1010, -1621, 75.367},
    {-1006, -1621, 75.36},
    {-1002, -1621, 75.36},
    {-998, -1621, 75.36},
    {-994, -1621, 75.36},
    {-990, -1621, 75.36},
}
plant = {}
colP = {}

for i, v in ipairs (plantas) do 
    plant[i] = createObject(3409, v[1],v[2],v[3])
    colP[i] = createMarker(v[1],v[2],v[3],"cylinder",2.5,0,0,0,0)
end


function fcm1 ()
    for i, col in ipairs (colP) do
        if isElementWithinMarker (localPlayer, col) then
            setPedAnimation (localPlayer, "INT_HOUSE", "wash_up", 10000, true, false, true, false, 10)
            setTimer(function ()
                setPedAnimation (localPlayer)
                givePlayerMoney (math.random (500, 1000))
				destroyElement (plant[i])
                plant[i] = nil
                destroyElement (colP[i])
                colP[i] = nil
            end, 10000, 1)
            break
        end
    end
end
addCommandHandler ("colher", fcm1)

Outro problema que percebi, é que você estava criando as plantas na mesma variável da table plantas.

  • Thanks 1
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...