Jump to content

Ice_Cool

Members
  • Posts

    25
  • Joined

  • Last visited

Details

  • Gang
    Ice_Cool

Ice_Cool's Achievements

Advanced Member

Advanced Member (8/54)

1

Reputation

  1. Dude, it worked so fine. Thank you so much brother!
  2. Thanks The_GTA i am thankful and I am almost there. However, the problem with this for loop I get is that it returns 1 msg if i am alone in the server, and it returns the message twice (in two different colors) if there is one more player in game. I am a beginner scripter, if you instead of suggesting functions help me a bit by editing this code, It will really really be helpful and timesaving. function sendMessageToNearbyPlayers(message, messageType) if messageType == 0 then cancelEvent() senderName = getPlayerName(source) local posX, posY, posZ = getElementPosition(source) local nearbyPlayers = getElementsWithinRange(posX, posY, posZ, 10, "player") for key, item in pairs (nearbyPlayers) do if item == source then outputChatBox ( getPlayerName(source).." says: "..message, source, 255, 255, 255, true ) else outputChatBox ( getPlayerName(source).." says: "..message, nearbyPlayers, 255, 255, 0, true ) end end end end addEventHandler("onPlayerChat", getRootElement(), sendMessageToNearbyPlayers) Thank you once again for your time, hope we can fix it this time.
  3. Hello everyone, 1. I am trying to differentiate the sender's chat color from receiver. The sender should see his text sent in a different color while everyone except him shall see in a different color. I tried to do this by creating two functions one for sender and one for receiver but the problem is the script end up showing double chat. Here is the code function sendMessageToNearbyPlayers(message, messageType) if messageType == 0 then cancelEvent() local senderName = getPlayerName(source) local posX, posY, posZ = getElementPosition(source) local nearbyPlayers = getElementsWithinRange(posX, posY, posZ, 10, "player") if (source) == "nearbyPlayers" and not "senderName" then outputChatBox ( getPlayerName(source).." says: "..message, nearbyPlayers, 255, 255, 0, true ) end end end end addEventHandler("onPlayerChat", getRootElement(), sendMessageToNearbyPlayers) local function playerChat(message, messageType) if messageType == 0 then --Global (main) chat cancelEvent() outputChatBox(getPlayerName(source)..": s says: "..message, root, 255, 200, 200, true ) end end addEventHandler("onPlayerChat", root, playerChat) 2. Please guys also help me "how to define a local player to differentiate him from others" it would help me in my other scripts. Thanking you so much for your positive responses in advance!
  4. Someone please reply? Re-posting above Code (Sorry i mistakenly added above code in snippet) a = createMarker(-705, 963, 13, "cylinder", 2, 255) function getTheBox(player, command) x, y, z = getElementPosition(player) if isElementWithinMarker(player, a) then if exports.bone_attach:isElementAttachedToBone (box) == false then box = createObject(1271, x, y, z) var = exports.bone_attach:attachElementToBone (box, player, 11, -0.15, 0.35, 0.35, 0, 0, 0) anim = setPedAnimation(player,"CARRY","crry_prtial",0,true,true,false,true) == true else outputChatBox('You already got the box') end end end addCommandHandler('buy', getTheBox) function PutBoxDown(player, command) b, c, d = getElementPosition(player) if var == true then exports.bone_attach:detachElementFromBone (box) if anim == true then anim = setPedAnimation(player,"CARRY","put_dwn", 0, true,true,false,true) moveObject(box, 0, b, c+0.6, d-0.6) end else outputChatBox('no') end end addCommandHandler('putdown', PutBoxDown) function PickUpBox(player) if isElement(box) == true then playerA, playerB, playerC = getElementPosition(player) boxA, boxB, boxC = getElementPosition(box) if getDistanceBetweenPoints3D (playerA, playerB, playerC, boxA, boxB, boxC) <= 2 then if var == true then exports.bone_attach:attachElementToBone (box, player, 11, -0.15, 0.35, 0.35, 0, 0, 0) else outputChatBox('You already holding the box.') end else outputChatBox('Nothing Around') end else outputChatBox('Nothing Around') end end addCommandHandler('try', PickUpBox)
  5. Hello everyone. So i am trying to make a script where a player can create boxes (under a marker) that will be attached to his bones and he (player) can put those boxes (object) on ground. Now the problem is, if he creates more than 1 boxes (objects) and drops them on floor, he can only pick the very recent one that he created. I am trying to make the player be able to pick any object with that ID from the ground either he created or not. But in this script he only picks the very recent he created. a = createMarker(-705, 963, 13, "cylinder", 2, 255) function getTheBox(player, command) x, y, z = getElementPosition(player) if isElementWithinMarker(player, a) then if exports.bone_attach:isElementAttachedToBone (box) == false then box = createObject(1271, x, y, z) var = exports.bone_attach:attachElementToBone (box, player, 11, -0.15, 0.35, 0.35, 0, 0, 0) anim = setPedAnimation(player,"CARRY","crry_prtial",0,true,true,false,true) == true else outputChatBox('You already got the box') end end end addCommandHandler('buy', getTheBox) function PutBoxDown(player, command) b, c, d = getElementPosition(player) if var == true then exports.bone_attach:detachElementFromBone (box) if anim == true then anim = setPedAnimation(player,"CARRY","put_dwn", 0, true,true,false,true) moveObject(box, 0, b, c+0.6, d-0.6) end else outputChatBox('no') end end addCommandHandler('putdown', PutBoxDown) function PickUpBox(player) if isElement(box) == true then playerA, playerB, playerC = getElementPosition(player) boxA, boxB, boxC = getElementPosition(box) if getDistanceBetweenPoints3D (playerA, playerB, playerC, boxA, boxB, boxC) <= 2 then if var == true then exports.bone_attach:attachElementToBone (box, player, 11, -0.15, 0.35, 0.35, 0, 0, 0) else outputChatBox('You already holding the box.') end else outputChatBox('Nothing Around') end else outputChatBox('Nothing Around') end end addCommandHandler('try', PickUpBox) I would be highly thankful if someone enlighten me with the best suggestions to fix this bug. Thank you.
  6. Thank you for the reply. But its still not working, only the last marker is teleporting the player to the defined coordinates in setElementPosition function. it still giving me the same error! Any other error or possible way to fix it?
  7. I have the exact same issue and i am unable to understand how to avoid overwriting. i have just started scripting someone please help! Can you please edit the code and make the right changes so i can learn? I'd be highly thankful for the help. t ={ {2450, -1670, 12}, {2455, -1670, 12}, {2460, -1670, 12} } for i, v in pairs(t) do a = createMarker(v[1], v[2], v[3], "cylinder", 2.5, 255, 255, 255) end addEventHandler('onMarkerHit', a, function (player) if source == a and getElementType(player) == "player" then if isPedInVehicle (player) == true then outputChatBox('Vehicles not allowed.', player) else setElementPosition(player, 2400, -1650, 12) outputChatBox("You're spawned.", player) end end end)
  8. Hello, I have just started learning scripting around 2 weeks now after finishing basic Lua. I created few simple resources myself and happy they work. So i decided to create something more complicated (for me) below is the script of moving objects when a player hits colShape. Example: #1 works fine so i decided to create it more efficient way Example: #2 which unfortunately don't work and i am getting it wrong i believe. Example: #1 (working script) local gateObjOne = createObject (988, 1023.599609375, -367.7001953125, 74.099998474121) local gateObjTwo = createObject (988, 1051, -323.599609375, 74.099998474121, 0, 0, 270) local gateObjThree = createObject (988, 1093.2998046875, -355.5, 74.099998474121, 0, 0, 270) local pColShapeOne = createColRectangle (1021, -371.5, 5, 8) local pColShapeTwo = createColRectangle (1049, -326.5, 5, 8) local pColShapeThree = createColRectangle (1090, -358.5, 5, 8) function prisonGate (player) moveObject(gateObjOne, 1000, 1029.3000488281, -367.7001953125, 74.099998474121) end addEventHandler("onColShapeHit", pColShapeOne, prisonGate) addEventHandler("onColShapeLeave", pColShapeOne, function() moveObject(gateObjOne, 1000, 1023.599609375, -367.7001953125, 74.099998474121) end) addEventHandler("onColShapeHit", pColShapeTwo, function() moveObject(gateObjTwo, 1000, 1051, -318.39999389648, 74.099998474121) end) addEventHandler("onColShapeLeave", pColShapeTwo, function() moveObject(gateObjTwo, 1000, 1051, -323.599609375, 74.099998474121) end) addEventHandler("onColShapeHit", pColShapeThree, function() moveObject(gateObjThree, 1000, 1093.3000488281, -350.29998779297, 74.099998474121) end) addEventHandler("onColShapeLeave", pColShapeThree, function() moveObject(gateObjThree, 1000, 1093.2998046875, -355.5, 74.099998474121) end) Example: #2 (Same script, I just decided to create it more efficient way). local prisonGateOpen = -- coordinates of opened gate. { {x = 1023.599609375, y = -367.7001953125, z = 74.099998474121}, {x = 1051, y = -323.599609375, z = 74.099998474121, pX = 0, pY = 0, pZ = 270}, {x = 1093.2998046875,y = -355.5, z = 74.099998474121, pX = 0, pY = 0, pZ = 270} } -- coordinates of gate when closed. local prisonGateClosed = { {cx = 1029.3000488281, cy = -367.7001953125, cz = 74.099998474121}, {cx = 1051, cy = -318.39999389648, cz = 74.099998474121}, {cx = 1093.3000488281,cy = -350.29998779297, cz = 74.099998474121} } -- ColShape coordinates. colShapes = { {colX = 1021,colY = -371.5,colWidth = 5,colHeight = 8}, {colX = 1049,colY = -326.5,colWidth = 5,colHeight = 8}, {colX = 1090,colY = -358.5,colWidth = 5,colHeight = 8} } -- looping to create gates. for _, t in ipairs(prisonGateOpen) do local gates = createObject(988, t.x, t.y, t.z, t.pX, t.pY, t.pZ) end -- looping through to get cols. for _, col in ipairs (colShapes) do local createColShapes = createColRectangle (colShapes[1], colShapes[2], colShapes[3], colShapes[4]) end -- Defining a function to get the gets open when a player hits colShape. function closegate () moveObject(1000, v.cx, v.cy, v.cz) end addEventHandler("onColShapeHit", createColShapes, closegate) In this example 2 however it creates objects and cols but of course it doesn't work when player hits col. My Question: What is the right way to define tables in such situation? And what is the right way to loop through these? I believe i have made things more complicated by running ipairs loop again and again. I truly respect your time, I don't want you to go on and edit the code as i am just learning I just want you guys to explain some good practices (regarding tables and loops in such situation) in best words you can and that's it. Thanking you in advance for your guidance.
  9. Brother maybe you're right but I really didn't get you. I don't want to have an object. I want to add my own interior. Even guess I replace it with any object how am I suppose to wrap to my interior? I am currently trying to have a custom interior for a prison but idk how set my interior that I designed in 3D Max. I thought if I could replace it with existing interiors but they have x, y, z positions and not just model ID.
  10. Hello everyone, hope you're doing well! Guys i am just a beginner to MTA Scripting and i encountered a problem that i tried to solve by self for hours but unfortunately could not. Actually i have created a Prison Model in 3D Max and after export i got .txd, .dff and .col files. What i want to do is add this in my server as an interior. Soon after creating an interior model in 3D Max i stuck between objects and interiors concept, i wonder if i follow this https://forum.multitheftauto.com/topic/35801-tut-adding-custom-objects-in-mta/ topic and try to add my int in server i have to replace it with an 'Object' which is not what i want. I basically want to add my own custom interior but i don't know how i can? i looked around but found nothing, hopefully one of you will resolve my problem and give me an opportunity to learn and enhance. Thanking you in advance for a positive reply. Best regards,
  11. Oh! definitely understood. Thanks for help. Glad to be helped by Hoodsta.
  12. No bro, didn't work as i said that it works fine if i copy codes from wiki https://wiki.multitheftauto.com/wiki/Int ... ng_the_GUI and don't work if i write it.... That Script Made me real confused..
  13. Then why it works if i copy these codes from wiki?
  14. function createLoginWindow() local X = 0.375 local Y = 0.375 local Width = 0.25 local Height = 0.25 wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log in", true) X = 0.0825 Y = 0.2 Width = 0.25 Height = 0.25 guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true wdwLogin) guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.415 Y = 0.7 Width = 0.25 Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log in", true, wdwLogin) guiSetVisible(wdwLogin, false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () createLoginWindow() outputChatBox("Welcome to My MTA:SA Server, please log in.") if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end showCursor(true) guiSetInputEnabled(true) end ) function clientSubmitLogin(button,state) if button == "left" and state == "up" then local username = guiGetText(edtUser) local password = guiGetText(edtPass) if username and password then triggerServerEvent("submitLogin", getRootElement(), username, password) guiSetInputEnabled(false) guiSetVisible(wdwLogin, False) showCursor(false) else outputChatBox("Please enter a username and password.") end end end function loginHandler(username,password) if username == "user" and password == "apple" then if (client) then spawnPlayer(client, 1959.55, -1714.46, 10) fadeCamera(client, true) setCameraTarget(client, client) outputChatBox("Welcome to My server.", client) end else outputChatBox("Invalid username and password. Please re-reconnect and try again.", client) end end addEvent("submitLogin",true) addEventHandler("submitLogin", root, loginHandler) And showCursor i fixed but still having problem
  15. http://www.filedropper.com/client_6 here's The Full Code file, just you have to download.
×
×
  • Create New...