Slothman Posted September 23, 2011 Share Posted September 23, 2011 for those of you running rpg gamemodes, i thought I might show you something. since it is now possible to see world elements with mta, you can now interact with them pretty easily. this is a quick example of how you can make a player sit on a chair or lay on a bed without having to place mta objects or map out the location of mta world items. This example binds the "b" button to check if a player is looking at a chair or bed (not all chairs are supported, sorry) then puts the player in that chair. This is a crude example because it doesnt test if there is anyone already in the chair, but it shows you what's possible. I'm not releasing this script because its crude and incomplete, and could probably be made more efficient using tables or something, but It might help someone get started. client script: function checkforobject() local x, y, z, lx, ly, lz, roll, fov = getCameraMatrix() local fromX, fromY, fromZ = getElementPosition(getLocalPlayer()) local toX = fromX + (lx - x)*3 local toY = fromY + (ly - y)*3 local toZ = fromZ + (lz - z)*3 local hit, hitX, hitY, hitZ, hitlineElement, normalX, normalY, normalZ, material, lighting, piece, wmid, wmx, wmy, wmz, wmrx, wmry, wmrz = processLineOfSight(fromX, fromY, fromZ+1, toX, toY, toZ, true, false, false, true, false, false, false, true, getLocalPlayer(), true) if hit then if hitlineElement then ix, iy, iz = getElementPosition(hitlineElement) rx, ry, rz = getElementRotation(hitlineElement) elid = getElementModel(hitlineElement) triggerServerEvent ("onworldItemUsed", getLocalPlayer(), elid, ix, iy, iz, rx, ry, rz ) elseif wmid ~= false then triggerServerEvent ("onworldItemUsed", getLocalPlayer(), wmid, wmx, wmy, wmz, wmrx, wmry, wmrz ) end end end bindKey ( "b", "down", checkforobject ) server script: addEvent( "onworldItemUsed", true ) function usetheitem(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz ) if (wmid) then outputChatBox(wmid) end local useditem = getElementData(source, "itembeingused") if isElement(useditem) then setPedAnimation ( source ) setElementData(source, "itembeingused", nil) setElementPosition (source, getElementData(source, "returnx"), getElementData(source, "returny"), getElementData(source, "returnz")) destroyElement(useditem) else local px, py, pz = getElementPosition(source) if wmid == 2291 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, .1, -2.2, 1) --offset will have to be configured for each item setElementRotation(source, 0,0, wmrz-170) -- rotation will have to be configured for each item setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "TATTOOS", "TAT_Sit_Loop_P", -1, false, false, false, true)-- animation will have to be configured for each item elseif wmid == 2343 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, 2, -.7, .5) setElementRotation(source, 0,0, wmrz-90) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "TATTOOS", "TAT_Sit_Loop_P", -1, false, false, false, true) elseif wmid == 2723 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, 0, .5, 1) setElementRotation(source, 0,0, wmrz) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 2724 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, 0, -.5, .6) setElementRotation(source, 0,0, wmrz-180) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 2356 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, 0, .7, 1.1) setElementRotation(source, 0,0, wmrz) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 1761 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, .5, -.7, 1.1) setElementRotation(source, 0,0, wmrz-180) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 1762 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, .5, -.7, 1.1) setElementRotation(source, 0,0, wmrz-180) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 2290 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, .5, -.7, 1.1) setElementRotation(source, 0,0, wmrz-180) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 2124 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, -.5, 0, .3) setElementRotation(source, 0,0, wmrz-270) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 1708 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, .5, -.7, 1.1) setElementRotation(source, 0,0, wmrz-180) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 1713 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, .5, -.7, 1.1) setElementRotation(source, 0,0, wmrz-180) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 1739 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, -.5, 0, .3) setElementRotation(source, 0,0, wmrz-270) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "ped", "SEAT_idle", -1, false, false, false, true) elseif wmid == 2090 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, 2, 2, 1) setElementRotation(source, 0,0, wmrz+90) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "INT_HOUSE", "BED_In_R", -1, false, false, false, true) elseif wmid == 2298 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, 2, 2, 1) setElementRotation(source, 0,0, wmrz+90) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "INT_HOUSE", "BED_In_R", -1, false, false, false, true) elseif wmid == 1798 then setElementData(source, "returnx", px, false) setElementData(source, "returny", py, false) setElementData(source, "returnz", pz, false) local useditemdummy = createObject(wmid, wmx, wmy, wmz, wmrx, wmry, wmrz) setElementData(source, "itembeingused", useditemdummy, false) attachElements(source, useditemdummy, 2, 2, 1) setElementRotation(source, 0,0, wmrz+90) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 0) setPedAnimation ( source, "INT_HOUSE", "BED_In_R", -1, false, false, false, true) end end end addEventHandler ( "onworldItemUsed", getRootElement(), usetheitem ) Link to comment
Benevolence Posted September 23, 2011 Share Posted September 23, 2011 Oh thanks, I will test this but how would I make it so instead of pressing 'b', it would be so people right click on the chair then left click to sit on it? Link to comment
Slothman Posted September 23, 2011 Author Share Posted September 23, 2011 i suppose you could create a gui item that pops up when you rightclick on the item, then make clicking the gui item trigger the server event. not a bad idea, but youd want the gui to dissapear after a few seconds, since aiming is usually right cllick, and it could be annoying to have a gui keep popping up. Link to comment
Benevolence Posted September 23, 2011 Share Posted September 23, 2011 Well GUI isn't needed. On Valhalla RP they have the feature I'm talking about. So obviously it's been possible. Link to comment
Slothman Posted September 23, 2011 Author Share Posted September 23, 2011 yeah, there are other ways, that was just a suggestion. does valhalla's script work with placed objects only? hate to think i posted this for no reason. Link to comment
Benevolence Posted September 23, 2011 Share Posted September 23, 2011 yeah, there are other ways, that was just a suggestion. does valhalla's script work with placed objects only? hate to think i posted this for no reason. No idea =P. But they have the feature on one type of chair only, and you can't sit on ALL of them I've noticed. Link to comment
Slothman Posted September 23, 2011 Author Share Posted September 23, 2011 some chairs and world objects are part of a bigger objects like a building or interior. this wouldnt work for that type, but thankfully most chairs are independent objects. Link to comment
Benevolence Posted September 24, 2011 Share Posted September 24, 2011 some chairs and world objects are part of a bigger objects like a building or interior. this wouldnt work for that type, but thankfully most chairs are independent objects. That makes sense. I could never figure out why it was like that... Link to comment
Slothman Posted September 24, 2011 Author Share Posted September 24, 2011 rockstar cutting corners. there are ways around this, by keeping a list of coords of different map objects. but that's the whole point of this new feature, if you want to make a vending machine script , you no longer need to know where all the vending machines are Link to comment
dragonofdark Posted September 27, 2011 Share Posted September 27, 2011 Hum.. I tested your script and I have a Bad Argument @ 'bindKey' I didn't change anything in it... Link to comment
Slothman Posted September 30, 2011 Author Share Posted September 30, 2011 did you make sure you put the client part as a client script in the meta? Link to comment
dragonofdark Posted September 30, 2011 Share Posted September 30, 2011 Ah shit.. What a bitch I am... Link to comment
Plantjen Posted January 25, 2012 Share Posted January 25, 2012 Thanks a lot, this has been very useful to me, now I can make my peds sit and interact with objects. Link to comment
Plantjen Posted January 25, 2012 Share Posted January 25, 2012 (edited) I can't quite get it to work though This script should create a ped in the Las Venturas Planning Department that sits in the chair at the front desk. When I run this code, the ped spawns and sits down, but then continuously rotates 180 degrees back and forth. A strange detail is that it only rotates when I move my mouse or press the keyboard, as long as i don't touch both mouse and keyboard, the ped performs its normal animation. Sidenote: In my code I'm using a timer, because it doesn't seem to work to set a ped's animation right after creating it. If there's a better way without timer, it would be great if anybody could tell me. My server code: townhallWorker = createPed ( 17, 359.72, 173.544, 1008.39, 270 ) setElementInterior(townhallWorker, 3) setElementDimension (townhallWorker, 2) setTimer ( function() local useditemdummy = createObject(1714, 359.051, 173.585, 1007.38, 0, 0, 90.719604) setElementInterior(useditemdummy, 3) setElementDimension (useditemdummy, 2) setElementData(townhallWorker, "itembeingused", useditemdummy, false) attachElements(townhallWorker, useditemdummy, -0.5, 0, .3) setElementRotation(townhallWorker, 0,0, 270) setElementCollisionsEnabled(useditemdummy, false) setElementAlpha(useditemdummy, 150) setElementFrozen ( townhallWorker, true ) setPedAnimation(townhallWorker, "INT_OFFICE", "OFF_Sit_Idle_Loop", -1, false, false, false, true) end , 1000, 0 ) Any help would be greatly appreciated! Edited January 26, 2012 by Guest Link to comment
DutchCaffeine Posted January 25, 2012 Share Posted January 25, 2012 i suppose you could create a gui item that pops up when you rightclick on the item, then make clicking the gui item trigger the server event. not a bad idea, but youd want the gui to dissapear after a few seconds, since aiming is usually right cllick, and it could be annoying to have a gui keep popping up. Well I made something small in addition to your script, my little addition just detects a interactable object and shows a little message on top wich disappears after 5 seconds. The detection script: http://pastebin.com/j9QaKKWt The ui script: http://pastebin.com/Q7C7UN2e 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