Jump to content

createColSphere easy problem


John Smith

Recommended Posts

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

Link to comment

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

Link to comment

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?

Link to comment
  
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
Link to comment

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

Link to comment

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.

Link to comment

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

Link to comment

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.

Link to comment

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...