Perfect Posted April 30, 2014 Share Posted April 30, 2014 Hello, Just a few days ago, I download download an community resource named 'Animals'. You can find it here :- https://community.multitheftauto.com/in ... ls&id=6904 But soon after playing for a while with my friends, i found a bug. Which is, When we change into an animal and then another player change into animal, We Automatically change back to human. Noting that the script is bit old and is less likely to seen by the Author (I still post a bug report there). In Meanwhile I tried to fixed it myself (As Denny199 suggested in Comments box) but no Success (As I am in Practice-Mode For Tables). Here is the Full Script:- local Cows = {} local Fishes = {} local Jellyfishes = {} local Dolphins = {} local Sharks = {} local Turtles = {} local Chickens = {} local Humans = {} local Saddles = {} function makeCow(player) local x, y, z = getElementPosition(Humans[player]) local rx, ry, rz = getElementRotation(Humans[player]) Cows[player] = createObject( 16442, x, y, z, rx, ry, rz, false) -- Saddles[player] = createVehicle(441, x, y, z, rx, ry, rz) setObjectScale(Cows[player], 0.4) attachElements(Cows[player], Humans[player], 0, 0, -0.1, 0, 0, 90) -- attachElements(Caddles[player], Cows[player], 0, 0, 0.4, 0, 0, 90) cam = setCameraMatrix(Humans[player], x, y, z + 3 ) attachElements(cam, Cows[player]) setElementAlpha(Humans[player], 0) setElementAlpha(Saddles[player], 0) outputChatBox("You are now a Cow!", Humans[player], 0, 255, 0) destroyElement(Chickens[player]) destroyElement(Dolphins[player]) destroyElement(Turtles[player]) destroyElement(Fishes[player]) destroyElement(Sharks[player]) destroyElement(Jellyfishes[player]) setCameraTarget(Humans[player], Humans[player]) setTimer(function() Humans[player] = nil end,5000,1) Chickens[player] = nil Dolphins[player] = nil Turtles[player] = nil Fishes[player] = nil Sharks[player] = nil Jellyfishes[player] = nil end addCommandHandler("cow", makeCow) function makeFish(player) local x, y, z = getElementPosition(Humans[player]) local rx, ry, rz = getElementRotation(Humans[player]) Fishes[player] = createObject( 1606, x, y, z, rx, ry, rz ) attachElements(Fishes[player], Humans[player]) setElementAlpha(Humans[player], 0) outputChatBox("You are now a Fish!", Humans[player], 0, 255, 0) setCameraTarget( Humans[player], Fishes[player] ) destroyElement(Saddles[player]) destroyElement(Cows[player]) destroyElement(Chickens[player]) destroyElement(Dolphins[player]) destroyElement(Turtles[player]) destroyElement(Sharks[player]) destroyElement(Jellyfishes[player]) setCameraTarget(Humans[player], Humans[player]) setTimer(function() Humans[player] = nil end,1000,1) Chickens[player] = nil Dolphins[player] = nil Turtles[player] = nil Fishes[player] = nil Sharks[player] = nil Jellyfishes[player] = nil Saddles[player] = nil end addCommandHandler("fish", makeFish) function makeJellyfish(player) local x, y, z = getElementPosition(Humans[player]) local rx, ry, rz = getElementRotation(Humans[player]) Jellyfishes[player] = createObject( 1602, x, y, z, rx, ry, rz ) attachElements(Jellyfishes[player], Humans[player]) setElementAlpha(Humans[player], 0) outputChatBox("You are now a Jellyfish!", Humans[player], 0, 255, 0) setCameraTarget( Humans[player], Jellyfishes[player]) destroyElement(Cows[player]) destroyElement(Saddles[player]) destroyElement(Chickens[player]) destroyElement(Dolphins[player]) destroyElement(Turtles[player]) destroyElement(Sharks[player]) destroyElement(Fishes[player]) setCameraTarget(Humans[player], Humans[player]) setTimer(function() Humans[player] = nil end,1000,1) Chickens[player] = nil Dolphins[player] = nil Turtles[player] = nil Fishes[player] = nil Sharks[player] = nil Jellyfishes[player] = nil Saddles[player] = nil end addCommandHandler("jellyfish", makeJellyfish) function makeDolphin (player) local x, y, z = getElementPosition(Humans[player]) local rx, ry, rz = getElementRotation(Humans[player]) Dolphins[player] = createObject( 1607, x, y, z, rx, ry, rz ) attachElements(Dolphins[player], Humans[player]) setElementAlpha(Humans[player], 0) outputChatBox("You are now a Dolphin!", Humans[player], 0, 255, 0) setCameraTarget( Humans[player], Dolphins[player] ) destroyElement(Cows[player]) destroyElement(Chickens[player]) destroyElement(Saddles[player]) destroyElement(Fishes[player]) destroyElement(Turtles[player]) destroyElement(Sharks[player]) destroyElement(Jellyfishes[player]) setCameraTarget(Humans[player], Humans[player]) setTimer(function() Humans[player] = nil end,1000,1) Chickens[player] = nil Dolphins[player] = nil Turtles[player] = nil Fishes[player] = nil Sharks[player] = nil Jellyfishes[player] = nil Saddles[player] = nil end addCommandHandler("dolphins[player]", makeDolphin) function makeShark (player) local x, y, z = getElementPosition(Humans[player]) local rx, ry, rz = getElementRotation(Humans[player]) Sharks[player] = createObject( 1608, x, y, z, rx, ry, rz ) attachElements(Sharks[player], Humans[player]) setElementAlpha(Humans[player], 0) outputChatBox("You are now a Shark!", Humans[player], 0, 255, 0) setCameraTarget( Humans[player], Sharks[player]) destroyElement(Saddles[player]) destroyElement(Cows[player]) destroyElement(Chickens[player]) destroyElement(Dolphins[player]) destroyElement(Turtles[player]) destroyElement(Fishes[player]) destroyElement(Jellyfishes[player]) setCameraTarget(Humans[player], Humans[player]) setTimer(function() Humans[player] = nil end,1000,1) Chickens[player] = nil Dolphins[player] = nil Turtles[player] = nil Fishes[player] = nil Sharks[player] = nil Jellyfishes[player] = nil Saddles[player] = nil end addCommandHandler("shark", makeShark) function makeTurtle (player) local x, y, z = getElementPosition(Humans[player]) local rx, ry, rz = getElementRotation(Humans[player]) Turtles[player] = createObject( 1609, x, y, z, rx, ry, rz ) attachElements(Turtles[player], Humans[player]) setElementAlpha(Humans[player], 0) outputChatBox("You are now a Turtle!", Humans[player], 0, 255, 0) setCameraTarget( player, Turtles[player] ) destroyElement(Cows[player]) destroyElement(Saddles[player]) destroyElement(Chickens[player]) destroyElement(Dolphins[player]) destroyElement(Fishes[player]) destroyElement(Sharks[player]) destroyElement(Jellyfishes[player]) setCameraTarget(Humans[player], Humans[player]) setTimer(function() Humans[player] = nil end,1000,1) Chickens[player] = nil Dolphins[player] = nil Turtles[player] = nil Fishes[player] = nil Sharks[player] = nil Jellyfishes[player] = nil Saddles[player] = nil end addCommandHandler("turtle", makeTurtle) function makeChicken (player) local x, y, z = getElementPosition(Humans[player]) local rx, ry, rz = getElementRotation(Humans[player]) Chickens[player] = createObject( 16776, x, y, z, rx, ry, rz ) setObjectScale(Chickens[player], 0.19) attachElements(Chickens[player], Humans[player], 0, -1.4, -1.6, 0, 0, 180) setElementAlpha(Humans[player], 0) destroyElement(Cows[player]) destroyElement(Saddles[player]) destroyElement(Dolphins[player]) destroyElement(Turtles[player]) destroyElement(Fishes[player]) destroyElement(Sharks[player]) destroyElement(Jellyfishes[player]) setCameraTarget(Humans[player], Humans[player]) outputChatBox("You are now a Chicken!", Humans[player], 0, 255, 0) setTimer(function() Humans[player] = nil end,1000,1) Chickens[player] = nil Dolphins[player] = nil Turtles[player] = nil Fishes[player] = nil Sharks[player] = nil Jellyfishes[player] = nil Saddles[player] = nil end addCommandHandler("chicken", makeChicken) function makeHuman (player) setElementAlpha(Humans[player], -1) destroyElement(Cows[player]) destroyElement(Chickens[player]) destroyElement(Saddles[player]) destroyElement(Dolphins[player]) destroyElement(Turtles[player]) destroyElement(Fishes[player]) destroyElement(Sharks[player]) destroyElement(Jellyfishes[player]) setCameraTarget(Humans[player], Humans[player]) outputChatBox("You are now a Human!", Humans[player], 0, 255, 0) setTimer(function() Humans[player] = nil end,1000,1) Chickens[player] = nil Dolphins[player] = nil Turtles[player] = nil Fishes[player] = nil Sharks[player] = nil Jellyfishes[player] = nil Saddles[player] = nil end addCommandHandler("human", makeHuman) Can You Guys Please Help Me ? Link to comment
Moderators IIYAMA Posted May 1, 2014 Moderators Share Posted May 1, 2014 Use 1 table. This structure: local animalTable = {[player]=object} local animalTable = {} local animalObjectFinder = {["cow"]=16442,["fish"]=1606} function changeInAnimal (player,cmd) local lastObject = animalTable[player] if lastObject then if isElement(lastObject) then destroyElement(lastObject) end animalTable[player]= nil end local objectID = animalObjectFinder[cmd] if objectID then local x, y, z = getElementPosition(player) local rx, ry, rz = getElementRotation(player) local newObject = createObject( objectID, x, y, z, rx, ry, rz ) if newObject then animalTable[player]= newObject setElementAlpha(player, 0) attachElements(newObject, player) outputChatBox("You are now a" .. cmd .. "!", player, 0, 255, 0) end end end addCommandHandler("cow", changeInAnimal) addCommandHandler("fish", changeInAnimal) addEventHandler("onPlayerQuit",root, function() local lastObject = animalTable[source] if lastObject then if isElement(lastObject) then destroyElement(lastObject) end animalTable[source]= nil end end) If you want to add more animals.(animal names much be match with the animalObjectFinder(table). addCommandHandler("", changeInAnimal) -- the command local animalObjectFinder = {["cow"]=16442,["fish"]=1606,[""]=1606 } -- ,[""]=1606 -- animal name and object id. Link to comment
Perfect Posted May 1, 2014 Author Share Posted May 1, 2014 Thank You Very Much, I really appreciate your help but I think you didn't notice that there is a Saddle Which is attached to 'cow' Object (Is it really necessary ?). Another thing is, I want it to output 'Cow' in chatbox and command will be 'cow'. And there is also a command which will turn you too human being. I should add that too in tables ? Well, The table you made for me is too complicated for me. Can You Please Make It Less Complicated ? Link to comment
Moderators IIYAMA Posted May 1, 2014 Moderators Share Posted May 1, 2014 Well, The table you made for me is too complicated for me.Can You Please Make It Less Complicated ? No it can't be less complicated else it doesn't work. This will turn you back to a human: addCommandHandler("human", function(player) local lastObject = animalTable[player] -- request object if lastObject then -- check if there is something is inside. if isElement(lastObject) then -- check if the userdata is still an element. destroyElement(lastObject) -- destroy it. end animalTable[player]= nil -- remove it from the table. end setElementAlpha(player, 255) end) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now