Jump to content

createColSphere easy problem


John Smith

Recommended Posts

Posted

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

Posted

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

Posted

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

Posted

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

Posted

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?

Posted (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 by Guest
Posted

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

Posted

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

Posted

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

Posted

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.

Posted

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.

Posted

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) ?

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...