unknooooown
Members-
Posts
259 -
Joined
-
Last visited
Everything posted by unknooooown
-
Hmm. Think I give the script a break for now and return to it at some other time, so see if I can figure out whats wrong. Thank you so much for helping me all day with the script. I really appreciate it a lot! I hope it didnt ruin your entire day! LOL
-
Same warning. Don't you think it has something to do with line 39 and 59 being the same and not local?
-
Now the new peds are lined up on a row just the way I want (With more space than needed, but I know how to change that), but they are still not attached to the player. WARNING: blahblah\cjSnake.lua:46: Bad argument @ 'attachElements'
-
When I hit the first marker a new ped is created, but not attached to the player. When I hit the second marker, another ped is created behind the first ped, but still not connected to the the player. I get these errors: WARNING: blahblah\cjSnake.lua:46: Bad argument @ 'attachElements' ERROR: blahblah\cjSnake.lua:66: attempt to index global 'peds' (a nil value)
-
Think this is too complicated for me at this point. Think I have to make some less advanced scripts before I understand any of this.
-
@JR10 - I am soooo confused! When I look at the new added part of the script, I don't see it linked to my other functions in any way at all, other than it being in the same script. When I run it I get Warnings on line 82 & 83, and an error on line 84. I understand what the new part of the script does, I just dont have any idea how to make it work with the exsisting script.
-
@JR10 - Hehe. That part I understand ^^ I just dont see how I can impliment it into my exsisting script. I mean, where should I add it and where/what should I call it for? I am very very very confused about all this.
-
Thank you. I will have a look at the script above later tonight. At first glance it doesn't make any sense to me what so ever, but I will do my best to figure out how to add it to my script. Thanks.
-
I feel so bad about having you try so many things for me! LOL! Hope its OK. I just want to learn and gain skills I have tested the script above, and I don't get any errors with it, but they still spawn ontop of eachother 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 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 addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake )
-
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.
-
Bad argument on Line 68. I am getting more and more confused at this point.
-
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.
-
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:
-
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
-
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?
-
I just tried the script that you posted, and Peacemaker is right, there are some errors in the I have to deliver a phone to someone now, but I will be back in abour half an hour for further testing Thanks for helping me JR
-
@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 ?
-
@JR10 - Ty, but that doesnt really change anything.
-
Hi. I hope you guys dont mind that I make a new topic every day.. 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 )
-
That was all I needed to hear. Thank you
-
I didnt double post did I? Yeah, I know what randDrugMarker and randMoney does I was just wondering why randDrugMarker can be outside the function where it is used, when randMoney is inside the function where it is used.
-
Btw... How come that randDrugMarker is outside the function, when randMoney is inside the function?
-
I salute you!
