Jump to content

MTA SnakeGame Help


Recommended Posts

Posted

Hi. I hope you guys dont mind that I make a new topic every day.. Lol! :lol:

Spending a lot of time with Lua these days, so I got a lot of questions. I try to find an answer for most of them myself, but I really need you guys on this one ;-)

I am trying to make a Snake game in MTA, where CJ collects markers. When he hits a marker, a new CJ is added behind the player. I can add the first one without any problems, but when I want to add more peds to the new ped, thats where the problems start to happen.

All the new peds are spawned on eachother, even if I add a little offset to the new spawn.

I am sure the problem is how I call my peds, but I am not 100% sure how the correct way of doing this is.

Hope you guys can guide me in the right direction.

Here is my script:

local snakeAppels = { 
    {-720,961,11}, 
    {-705,968,11}, 
    {-698,954,11}, 
    {-711,960,11}, 
    {-722,950,11}, 
    {-720,977,11}, 
    {-687,965,11}, 
    {-678,949,11}, 
    {-664,951,11}, 
    {-711,942,11} 
} 
  
-- cjSnake Marker & ColShape controller (Should only fire ONCE) -- 
function cjFirstSnake (thePlayer, command) 
    local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
    theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
    theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
    appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
    addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) 
end 
  
-- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- 
function cjSnake (thePlayer, command) 
    local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
    theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
    theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
    appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
    addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) 
end 
addCommandHandler("cj-snake", cjFirstSnake) 
  
addEvent ( "loopCjSnake", true ) 
  
-- Should only fire ONCE! -- 
function appelFirstHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    local pX, pY, pZ = getElementPosition( thePlayer ) 
    local prX, prY, prZ = getElementRotation( thePlayer ) 
    newPed1 = createPed ( 0, pX + 1, pY, pZ, prZ ) 
    if(detection) then 
        outputChatBox( "You found the APPLE and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        attachElements ( newPed1, thePlayer, 0, -0.2, 0) 
        triggerEvent ( "loopCjSnake", getRootElement(), "" ) 
    end 
end 
  
-- Should fire after the first PED is attached to CJ(thePlayer) -- 
function appelHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    newPed = createPed ( 0, 0, 0, 0, 0 ) 
    local npX, npY, npZ = getElementPosition (newPed) 
    if(detection) then 
--      outputChatBox( "You found the apple and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        setElementPosition ( newPed, npX, npY + 0.1, npZ ) 
        attachElements ( newPed, newPed1, npX, npY + 0.1, npZ) 
        triggerEvent ( "loopCjSnake", getRootElement(), "" ) 
            if(newPed) then 
                outputChatBox ( "The new PED was created!") 
            else 
                outputChatBox ( "Failed to create the new PED!") 
            end  
        end 
end 
addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) 

  • Replies 58
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted (edited)
triggerEvent ( "loopCjSnake", getRootElement(), "" ) 

It should be a player element.

triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) 

Edited by Guest
Posted

You can use this function to get the players back position

function getPlayerBackPos(player) 
    local rotz = getPedRotation(player) 
    local x, y, z = getElementPosition(player) 
    x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 2) -- you can increase 2 to increase the space 
    y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 2) --  here too 
    return x, y, z 
end 

Posted

@JR10 - My real question is. Is it possible to spawn the next "joint/link" of the "Cj-snake" the way that I do it?

I keep calling newPed, but will the engine know to look for the latest Ped, or doest it look for all newPed ?

Posted

Make a table with them?

local snakeAppels = { 
    {-720,961,11}, 
    {-705,968,11}, 
    {-698,954,11}, 
    {-711,960,11}, 
    {-722,950,11}, 
    {-720,977,11}, 
    {-687,965,11}, 
    {-678,949,11}, 
    {-664,951,11}, 
    {-711,942,11} 
} 
  
peds = {} 
  
-- cjSnake Marker & ColShape controller (Should only fire ONCE) -- 
function cjFirstSnake (thePlayer, command) 
    local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
    theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
    theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
    appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
    addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) 
end 
  
-- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- 
function cjSnake (thePlayer, command) 
    local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
    theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
    theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
    appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
    addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) 
end 
addCommandHandler("cj-snake", cjFirstSnake) 
  
addEvent ( "loopCjSnake", true ) 
  
-- Should only fire ONCE! -- 
function appelFirstHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    local pX, pY, pZ = getElementPosition( thePlayer ) 
    local prX, prY, prZ = getElementRotation( thePlayer ) 
    newPed1 = createPed ( 0, pX + 1, pY, pZ, prZ ) 
    if(detection) then 
        outputChatBox( "You found the APPLE and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        attachElements ( newPed1, thePlayer, 0, -0.2, 0) 
        triggerEvent ( "loopCjSnake", getRootElement(), "" ) 
    end 
end 
  
-- Should fire after the first PED is attached to CJ(thePlayer) -- 
function appelHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    peds[#peds + 1] = createPed ( 0, 0, 0, 0, 0 ) 
    local npX, npY, npZ = getElementPosition (peds[#peds + 1]) 
    if(detection) then 
--      outputChatBox( "You found the apple and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        setElementPosition ( peds[#peds + 1], npX, npY + 0.1, npZ ) 
        attachElements ( peds[#peds + 1], newPed1, npX, npY + 0.1, npZ) 
        triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) 
            if(peds[#peds + 1]) then 
                outputChatBox ( "The new PED was created!") 
            else 
                outputChatBox ( "Failed to create the new PED!") 
            end  
        end 
end 
addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) 

Not tested.

Posted (edited)

on The apple first hit you create a ped and store it in newPed1 and then in appleHit you create a ped and attach it to newPed1

so it get attached to the first ped "newPed1" and you want it to get attached to the last created ped before it right?

You can create a table and do this

local newPed = {} 
function appelHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    local newPedCounter = #newPed + 1 
    newPed[newPedCounter] = createPed ( 0, 0, 0, 0, 0 ) 
    local npX, npY, npZ = getElementPosition (newPed) 
    if(detection) then 
--      outputChatBox( "You found the apple and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        setElementPosition ( newPed[newPedCounter], npX, npY + 0.1, npZ ) 
        attachElements ( newPed[newPedCounter], newPed[#newPed - 1], npX, npY + 0.1, npZ) 
        triggerEvent ( "loopCjSnake", getRootElement(), "" ) 
            if(newPed) then 
                outputChatBox ( "The new PED was created!") 
            else 
                outputChatBox ( "Failed to create the new PED!") 
            end  
        end 
end 

I think this will work.

Edited by Guest
Posted
Make a table with them?
local snakeAppels = { 
    {-720,961,11}, 
    {-705,968,11}, 
    {-698,954,11}, 
    {-711,960,11}, 
    {-722,950,11}, 
    {-720,977,11}, 
    {-687,965,11}, 
    {-678,949,11}, 
    {-664,951,11}, 
    {-711,942,11} 
} 
  
peds = {} 
  
-- cjSnake Marker & ColShape controller (Should only fire ONCE) -- 
function cjFirstSnake (thePlayer, command) 
    local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
    theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
    theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
    appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
    addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) 
end 
  
-- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- 
function cjSnake (thePlayer, command) 
    local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
    theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
    theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
    appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
    addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) 
end 
addCommandHandler("cj-snake", cjFirstSnake) 
  
addEvent ( "loopCjSnake", true ) 
  
-- Should only fire ONCE! -- 
function appelFirstHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    local pX, pY, pZ = getElementPosition( thePlayer ) 
    local prX, prY, prZ = getElementRotation( thePlayer ) 
    newPed1 = createPed ( 0, pX + 1, pY, pZ, prZ ) 
    if(detection) then 
        outputChatBox( "You found the APPLE and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        attachElements ( newPed1, thePlayer, 0, -0.2, 0) 
        triggerEvent ( "loopCjSnake", getRootElement(), "" ) 
    end 
end 
  
-- Should fire after the first PED is attached to CJ(thePlayer) -- 
function appelHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    peds[#peds + 1] = createPed ( 0, 0, 0, 0, 0 ) 
    local npX, npY, npZ = getElementPosition (peds[#peds + 1]) 
    if(detection) then 
--      outputChatBox( "You found the apple and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        setElementPosition ( peds[#peds + 1], npX, npY + 0.1, npZ ) 
        attachElements ( peds[#peds + 1], newPed1, npX, npY + 0.1, npZ) 
        triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) 
            if(peds[#peds + 1]) then 
                outputChatBox ( "The new PED was created!") 
            else 
                outputChatBox ( "Failed to create the new PED!") 
            end  
        end 
end 
addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) 

Not tested.

it dont work :lol: errors

Posted

You are really pathetic,

How the hell did you test it so fast?

I bet you didn't even test it, get the f*ck off castillo.

If you really tested it post the errors ;)

Posted

I just tried the script that you posted, and Peacemaker is right, there are some errors in the :P

I have to deliver a phone to someone now, but I will be back in abour half an hour for further testing :D

Thanks for helping me JR :)

Posted
I haven't tested it, so maybe there are errors indeed, but Peacemaker doesn't even know what he's talking about.

Also he posted that 5 minutes later how did he test it in 5 minutes that's without taking in consideration the time he took to see the post so obviously he is just trying to piss you off. -_-

Posted

Finally back.

I just tested the script again JR10, and for some reason it fails to create the new Peds. ( peds[#peds + 1] )

Does the script even know that it should store the new Peds in the table we created?

Posted
that way it's already storing them ,hmm, it should work.

Weird.. I am new to Lua and all, but I just cant see what the problem is.

I will just have to look harder I guess :lol:

Posted

Hmm.. Here is the script as it looks like to me now:

    local snakeAppels = { 
        {-720,961,11}, 
        {-705,968,11}, 
        {-698,954,11}, 
        {-711,960,11}, 
        {-722,950,11}, 
        {-720,977,11}, 
        {-687,965,11}, 
        {-678,949,11}, 
        {-664,951,11}, 
        {-711,942,11} 
    } 
      
    peds = {} 
      
    -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- 
    function cjFirstSnake (thePlayer, command) 
        local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
        theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
        theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
        appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
        addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) 
    end 
      
    -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- 
    function cjSnake (thePlayer, command) 
        local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
        theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
        theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
        appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
        addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) 
    end 
    addCommandHandler("cj-snake", cjFirstSnake) 
      
    addEvent ( "loopCjSnake", true ) 
      
    -- Should only fire ONCE! -- 
    function appelFirstHit ( thePlayer ) 
        local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
        local randomMoney = math.random(50,500) 
        local pX, pY, pZ = getElementPosition( thePlayer ) 
        local prX, prY, prZ = getElementRotation( thePlayer ) 
        newPed1 = createPed ( 0, pX + 1, pY, pZ, prZ ) 
        if(detection) then 
            outputChatBox( "You found the APPLE and got $" ..randomMoney ) 
            givePlayerMoney ( thePlayer, randomMoney ) 
            destroyElement ( theAppleMarkerCol ) 
            destroyElement ( theAppleMarker ) 
            destroyElement ( appleBlip ) 
            attachElements ( newPed1, thePlayer, 0, -0.2, 0) 
            triggerEvent ( "loopCjSnake", getRootElement(), "" ) 
        end 
    end 
      
    -- Should fire after the first PED is attached to CJ(thePlayer) -- 
    function appelHit ( thePlayer ) 
        local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
        local randomMoney = math.random(50,500) 
        peds[#peds + 1] = createPed ( 0, 0, 0, 0, 0 ) 
        local npX, npY, npZ = getElementPosition (peds[#peds + 1]) 
        if(detection) then 
    --      outputChatBox( "You found the apple and got $" ..randomMoney ) 
            givePlayerMoney ( thePlayer, randomMoney ) 
            destroyElement ( theAppleMarkerCol ) 
            destroyElement ( theAppleMarker ) 
            destroyElement ( appleBlip ) 
            setElementPosition ( peds[#peds + 1], npX, npY, npZ ) 
            attachElements ( peds[#peds + 1], newPed1, npX, npY, npZ) 
            triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) 
                if(peds[#peds + 1]) then 
                    outputChatBox ( "The new PED was created!!") 
                else 
                    outputChatBox ( "Failed to create the new PED!") 
                end 
            end 
    end 
    addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) 

When I upgrade the server I don't get any errors, but when I try to enter a marker after the first ped has been attached, I get these errors:

WARNING: blahblah\cjSnake.lua:60: Bad argument @ getElementPosition

WARNING: blahblah\cjSnake.lua:67: Bad argument @ setElementPosition

WARNING: blahblah\cjSnake.lua:68: Bad argument @ attachElements

Posted

Here (tested).

local snakeAppels = { 
    {-720,961,11}, 
    {-705,968,11}, 
    {-698,954,11}, 
    {-711,960,11}, 
    {-722,950,11}, 
    {-720,977,11}, 
    {-687,965,11}, 
    {-678,949,11}, 
    {-664,951,11}, 
    {-711,942,11} 
} 
  
peds = {} 
  
-- cjSnake Marker & ColShape controller (Should only fire ONCE) -- 
function cjFirstSnake (thePlayer, command) 
    local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
    theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
    theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
    appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
    addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) 
end 
  
-- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- 
function cjSnake (thePlayer, command) 
    local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) 
    theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) 
    theAppleMarkerCol = createColCircle ( rX, rY, 3.0) 
    appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) 
    addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) 
end 
addCommandHandler("cj-snake", cjFirstSnake) 
   
-- Should only fire ONCE! -- 
function appelFirstHit ( thePlayer ) 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    local pX, pY, pZ = getElementPosition( thePlayer ) 
    local prX, prY, prZ = getElementRotation( thePlayer ) 
    newPed1 = createPed ( 0, pX + 1, pY, pZ, prZ ) 
    if(detection) then 
        outputChatBox( "You found the APPLE and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        attachElements ( newPed1, thePlayer, 0, -0.2, 0) 
        triggerEvent ( "loopCjSnake", getRootElement(), "" ) 
    end 
end 
  
-- Should fire after the first PED is attached to CJ(thePlayer) -- 
function appelHit ( thePlayer ) 
if getElementType(thePlayer) ~= "player" then return end 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    local newPed = #peds +1 
    peds[newPed] = createPed ( 0, 0, 0, 0, 0 ) 
    local npX, npY, npZ = getElementPosition (peds[newPed]) 
    if(detection) then 
--      outputChatBox( "You found the apple and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        setElementPosition ( peds[newPed], npX, npY + 0.1, npZ ) 
        attachElements ( peds[newPed], newPed1, npX, npY + 0.1, npZ) 
        triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) 
            if(peds[newPed]) then 
                outputChatBox ( "The new PED was created!") 
            else 
                outputChatBox ( "Failed to create the new PED!") 
            end 
        end 
end 
addEvent ( "loopCjSnake", true ) 
addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) 

This creates one CJ ped every time I hit one of these 'apple' marker.

Posted

Thank you both. - Now that we have them stored in the table, how would I be able to have each newPed spawn behind the latest? Right now, they still spawn ontop of eachother, which is wrong. What I am looking for is to create a "Cj tail" behind the player, as any snakegame does :-)

I have tried a few things myself, but when I add some offset to the newPed, its the same offset for all the newPeds created.

Posted (edited)
local lastPed = #peds - 1 
attachElements ( peds[newPed], peds[lastPed], npX, npY + 0.1, npZ) 

Try this :roll:

or try this:

function appelHit ( thePlayer ) 
if getElementType(thePlayer) ~= "player" then return end 
    local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) 
    local randomMoney = math.random(50,500) 
    local lastPed = #peds 
    local newPed = #peds +1 
    peds[newPed] = createPed ( 0, 0, 0, 0, 0 ) 
    local npX, npY, npZ = getElementPosition (peds[newPed]) 
    if(detection) then 
--      outputChatBox( "You found the apple and got $" ..randomMoney ) 
        givePlayerMoney ( thePlayer, randomMoney ) 
        destroyElement ( theAppleMarkerCol ) 
        destroyElement ( theAppleMarker ) 
        destroyElement ( appleBlip ) 
        setElementPosition ( peds[newPed], npX, npY + 0.1, npZ ) 
        attachElements ( peds[newPed], newPed1, npX, npY + 0.1, npZ) 
        triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) 
            if(peds[newPed]) then 
                outputChatBox ( "The new PED was created!") 
            else 
                outputChatBox ( "Failed to create the new PED!") 
            end 
        end 
end 

Edited by Guest
Posted (edited)

If we use:

    attachElements ( peds[newPed], peds[#peds - 1], npX, npY + 0.1, npZ) 

There is really no way for the peds[newPed] to know that it should be attached to newPed1 is there?

Also tested:

    local lastPed = #peds - 1 
    attachElements ( peds[newPed], peds[lastPed], npX, npY + 0.1, npZ)  

But I still get the bad argument. Think thats the same problem as I asked above.

Edited by Guest

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