Jump to content

Replace for onColShapeHit !


Tekken

Recommended Posts

Hi,

Is there any other avent for check if player is in an coolshape ?

If i am already in a coolshape the event onColShapeHit won't work and also i can't use setTimer fr this

addEventHandler("onColShapeHit", resourceRoot, handlePoly) 

I want to constantly chech if is player in that coolshape how do i do theat ??

Link to comment

For example

local col = createColCircle ( x, y, radius ) 
if ( col ) then 
    for _, player in pairs ( getElementsByType ( "player" ) ) do 
        if ( isElementWithinColShape ( player, col ) ) then 
            -- do something 
        end 
    end 
end 

Link to comment

My script is like that:

function handlePoly(thePlayer) 
    toggleAllControls(thePlayer, false) 
end 
addEventHandler("onColShapeHit", resourceRoot, handlePoly) 
  
function handlePoly2(thePlayer) 
    toggleAllControls(thePlayer, true) 
end 
addEventHandler("onColShapeLeave", resourceRoot, handlePoly2) 

and i have something like this (is more complicated but it does this)

function refusePoly(thePlayer) 
    toggleAllControls(thePlayer, true) 
end 
addCommandHandler("rp", refusePoly) 

How do i check after refusePoly is caled if player is in that colshape ?

Link to comment
function refusePoly(thePlayer) 
    toggleAllControls(thePlayer, true) 
    if ( isElementWithinColShape ( thePlayer, col ) ) then 
            -- do something 
    end 
end 
addCommandHandler("rp", refusePoly) 

Replace 'col' with collision that you've made before.

Link to comment

Look:

In /debugscript 3 i got this error: Aburting; infinit runing script in MyResource

My code:

function funct() 
        --None important other stuff 
        toggleAllControls(theCuffed, true)--This is doing on i uncuff a player and i want to check if the player is in this colshape, and if it is toggleControls false.  
        for i,col in ipairs(getElementsByType("colshape")) do 
            for i,theCuffed in ipairs(getElementsByType("player")) do 
                if isElementWithinAColShape(theCuffed) then 
                    local currentPoly = getElementData(col, "accId") or false 
                    if currentPoly then 
                        local polyAccType = getElementData(col, "accType") 
                        local polyAccRule = getElementData(col, "accRule")            
                        if tonumber(polyAccType) == 4 then 
                            if getElementType(theCuffed) == "player" then 
                                toggleControl (theCuffed, "fire", false) 
                                toggleControl (theCuffed, "next_weapon", false) 
                                toggleControl (theCuffed, "previous_weapon", false) 
                                toggleControl (theCuffed, "aim_weapon", false) 
                                toggleControl (theCuffed, "vehicle_fire", false) 
                                showPlayerHudComponent (theCuffed, "ammo", false) 
                                showPlayerHudComponent (theCuffed, "weapon", false) 
                            end 
                        end 
                    end 
                end 
            end 
        end 
end  
addEvent("OnPlayerUnCuff", true) 
addEventHandler("OnPlayerUnCuff", root, funct)   

Edited by Guest
Link to comment

Are you sure you aren't calling OnPlayerUnCuff from another resource ? And does your error spam something like 'Stack overflow' before aborting the script ?

If so, please remove the last two lines of your current script and run it. It should display an error when the resource that calls it no longer finds it.

Link to comment
Are you sure you aren't calling OnPlayerUnCuff from another resource ? And does your error spam something like 'Stack overflow' before aborting the script ?

If so, please remove the last two lines of your current script and run it. It should display an error when the resource that calls it no longer finds it.

i am working in the same resource and i don't get any Stack overflow i only get ERROR: Aburting; infinit runing script in interaction-system.

Link to comment

If you have a set of colshapes created by a resource and want to constantly check if a player is inside a colshape you can do the following:

  
local colShapes = {} 
  
-- As you create your colshapes, include them in your colShapes array. 
-- Complete this part on your own. 
  
function checkColShapeOnLogin() 
    for i, v in pairs(colShapes) do 
         if isElementWithinColShape(source, v) then 
               setElementData(source, "withinColShape", v) 
         end 
    end 
end 
addEventHandler("onPlayerLogin", root, checkColShapeOnLogin) 
  
function assignColShapeOnEnter(theElement) 
    for i, v in pairs(colShapes) do 
         if isElementWithinColShape(theElement, v) then 
               setElementData(theElement, "withinColShape", source) 
         end 
    end 
end 
addEventHandler("onColShapeHit", root, assignColShapeOnEnter) 
  
function assignColShapeOnExit(theElement) 
    local currentShape = getElementData(theElement, "withinColShape") or nil 
    for i, v in pairs(colShapes) do 
       if v == currentShape then 
           setElementData(theElement, "withinColShape", false) 
       end 
    end 
end 
addEventHandler("onColShapeLeave", root, assignColShapeOnExit) 
  

Edited by Guest
Link to comment

I don't advise using 'isElementWithinAColShape' in the DayZ gamemode, there's a huge number of colshapes in that gamemode, to get an idea just do:

/run #getElementsByType("colshape")

For further reference do:

/crun setDevelopmentMode(true)

/showcols 1

You will see almost everything has a colshape thus making the script a CPU-eating beast.

Edit: De ce ai amestecat resursa cu protectia bazelor cu resursa cu interactiunea ? :shock:

Link to comment
I don't advise using 'isElementWithinAColShape' in the DayZ gamemode, there's a huge number of colshapes in that gamemode, to get an idea just do:

/run #getElementsByType("colshape")

For further reference do:

/crun setDevelopmentMode(true)

/showcols 1

You will see almost everything has a colshape thus making the script a CPU-eating beast.

Edit: De ce ai amestecat resursa cu protectia bazelor cu resursa cu interactiunea ? :shock:

Already did

/crun setDevelopmentMode(true)

/showcols 1

Romanian: Nu am amestecat nimic doar ca daca 2 playerii sunt in protectia de la shop de exemplu si unul din ei il leaga pe celalalt iar cel legat are o arma echipata apoi il dezleaga cel legar si dezlegat va putea folosi armele chiar daca e in protectie. Si amu incerc sa fac cumva sa verifice daca playerul dezlegat este intr-un colshape si propunerea de mai sus nu merge :(

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