John Smith Posted August 23, 2014 Posted August 23, 2014 hi i just wanted to try out this function but i dont know what im doing wrong function createColField(thePlayer) local x,y,z = getElementPosition(thePlayer) createColSphere(x,y,z,20) outputChatBox(tonumber(x)..tonumber(y)..tonumber(z),thePlayer) end addCommandHandler("col_field",createColField) i set development mode with crun command and i used showcol command and in debugscript 3 no errors it outputs x,y,z but i dont see any collision thingy please help
John Smith Posted August 23, 2014 Author Posted August 23, 2014 how do i do that?im new to this col function idk sry edit: not sure if this can be a way to do it but i tried this colshape = createColSphere(x,y,z,2) outputChatBox(tostring(colshape)) it outputted userdata: 000000000000CE31
lcd12321 Posted August 23, 2014 Posted August 23, 2014 if returned userdata it's mean that colsphere created. So maybe u setdevmode after command showcol. Write what console is writing after command showcol 1
ma2med Posted August 23, 2014 Posted August 23, 2014 It's work for me, did you put "setDevelopmentMode" in client ?
John Smith Posted August 23, 2014 Author Posted August 23, 2014 here are exact steps how i did this Executing client-side command: setDevelopmentMode(true) Command results: true [boolean] restart: Resource restarting... showcol is now set to 0 showcol is now set to 1 -- command for colshape has been used in here -- output after command using: 1960.6787109375-2016.725585937513.3828125 (my coordinates) userdata: 0000000000013385 (colshape element created) however still not working
John Smith Posted August 23, 2014 Author Posted August 23, 2014 i cant see those green-red things at all, i said it already, i cant see them, thats the problem and reason why i made this topic
Anubhav Posted August 23, 2014 Posted August 23, 2014 Try changing the size to '5000' And see if the green boxes appear.
John Smith Posted August 23, 2014 Author Posted August 23, 2014 i have restarted whole server and set size to 5 and now it works, but its something weird it makes sphere on my position(big one) and attaches smaller one behind me(football ball size) edit: also, is there a way how can i make that when specific element hits the col sphere, that it creates the collision and element can't pass through or gets damage?
Anubhav Posted August 23, 2014 Posted August 23, 2014 (edited) addEventHandler("onColShapeHit", colshape, function(hit) local occupied = getPedOccupiedVehicle(hit) if hit then outputChatBox("You car will be destroyed within 5 secs! This area doesn't accept vehicles!", hit) setTimer(destroyVeh, 5000, 1, occupied) end setElementData(hit, "no-damage", true) end ) addEventHandler("onColShapeLeave", colshape, function(hit) removeElementData(hit, "no-damage") end ) addEventHandler("onPlayerDamage", root, function() if getElementData(hit, "no-damage") then cancelEvent() end end ) Edited August 23, 2014 by Guest
John Smith Posted August 23, 2014 Author Posted August 23, 2014 thanks but i meant the opposite if player hits colshape or a vehicle, then it cant go through is it possible to make it that way? also for line 2,7 it outputs that 2nd argument is nil
Anubhav Posted August 23, 2014 Posted August 23, 2014 See my edited post. And replace 'colshape' with your colshape variable.
John Smith Posted August 23, 2014 Author Posted August 23, 2014 i renamed variable to 'ddd' and now at line 2 and 12 it says argument 2 element is nil because that function doesnt recognize 'ddd' variable, and if i place 'ddd' outisde of first function, it wont work at all also i doubt your destroyVeh function at setTimer would do anything as i don't see it anywhere defined
Anubhav Posted August 23, 2014 Posted August 23, 2014 Replace it with resourceRoot it will work fine then. And change destroyVeh to destroyVehicle typo.
John Smith Posted August 23, 2014 Author Posted August 23, 2014 bad argument 1 setTimer expected function at argument 1, got nil and it says "your vehicle will be destroyed..." as soon as resource starts, and not when vehicle gets into colshape
Bonsai Posted August 23, 2014 Posted August 23, 2014 To both of you, the wiki is a powerful tool. That script doesn't check for the element type. It doesn't check if "occupied" is false or actually a car. Also I don't get the need of this "no-damage" thing. addEventHandler("onColShapeHit", colshape, function(hitElement) if not hitElement then return end if getElementType(hitElement) == "player" then hitElement = getPedOccupiedVehicle(hitElement) elseif getElementType(hitElement) ~= "vehicle" then return end end setElementVelocity(hitElement, 0, 0, 0) --maybe? Not sure what you want, try it out. Not sure if working with peds either. end ) Not tested.
John Smith Posted August 23, 2014 Author Posted August 23, 2014 argument 2 is still nil addEventHandler("onColShapeHit", colshape,
Bonsai Posted August 23, 2014 Posted August 23, 2014 Oh well yeah, the colshape that you are creating gotta have that name. Else you could also use root and check if source == your colshape in that function.
John Smith Posted August 23, 2014 Author Posted August 23, 2014 yeah i could do all that magic, but theres still one problem and im trying to tell everyone 23101290 times about it that colshape variable is not defined in full script if i put it outside of every function(on top of script) not a single function will load it,idk why and if i put it in some function,only that function will be able to load it how do i define variable for whole script? (in this case 'ddd' variable which is that colshape element) ?
Bonsai Posted August 23, 2014 Posted August 23, 2014 Visible for whole resource: ddd = true Visible for script file only: local ddd = true (unless its inside of a function, if statement etc.) Basically, "local" makes a variable be only visible and therefore existing within the scope it was defined in.
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