Jump to content

[HELP] Tube Collision


Recommended Posts

Hi, i need help with collisions.Here is what i want to acheive,

when a player joins, a tubular collision is made around the person and attached to him, once other players enters that collision , it gives a warning to the original player, when the other players kills the original player, those players in the collision get money. How will i do this?? Please help.

Link to comment
createColTube 
attachElements 
givePlayerMoney 

K, i got that part, now how do i give money to players in the collision object??

  
c_root = getRootElement() 
function createZone () 
playerZone = createColTube ( 0, 0, 0, 10.0, 100.0 ) 
attachElements ( playerZone, source, 0, 0, 0 ) 
end 
addCommandHandler ( "cz_cz", createZone ) 
  
function zoneEnter () 
outputChatBox("A Player is in Your Zone!", c_root) 
end 
addEventHandler ( "onColShapeHit", playerZone, zoneEnter ) 
  
function giveMoney() 
  
end 
addEventHandler ("onPlayerWasted", c_root, giveMoney ) 
  

Link to comment
for index, player in ipairs ( getElementsWithinColShape ( theColshape, "player" ) ) do 
     -- Your code here. 
end 

Thanks, but one more thing, how can i make it do this process for every player? So it attaches the collision object to every player and when every player dies it does this?

Link to comment
Just attach it when a player joins, also when the resource starts, loop players and create them as well.

sorry, but what do you mean by "also when the resource starts, loop players and create them as well.", i dont understand, can you please teach me?

Here is what I have so far, haven't tested it though.

  
c_root = getRootElement() 
function createZone () 
playerZone = createColTube ( 0, 0, 0, 10.0, 100.0 ) 
attachElements ( playerZone, c_root, 0, 0, 0 ) 
outputChatBox ( "created", source ) 
end 
addEventHandler ( "onPlayerJoin", c_root, createZone ) 
addEventHandler ( "onResourceStart", c_root, createZone ) 
  
function zoneEnter () 
outputChatBox("A Player is in Your Zone!", c_root) 
end 
addEventHandler ( "onColShapeHit", playerZone, zoneEnter ) 
  
function giveMoney() 
for index, player in ipairs ( getElementsWithinColShape ( playerZone, "player" ) ) do 
     givePlayerMoney( player, 5000 ) 
end 
end 
addEventHandler ("onPlayerWasted", c_root, giveMoney ) 
  

Edited by Guest
Link to comment
local playerZones = { } 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            playerZones [ player ] = createColTube ( 0, 0, 0, 10.0, 100.0 ) 
            attachElements ( playerZones [ player ], player, 0, 0, 0 ) 
            setElementData ( playerZones [ player ], "zoneOwner", player ) 
            addEventHandler ( "onColShapeHit", playerZones [ player ], zoneEnter ) 
        end 
    end 
) 
  
function createZone ( ) 
    playerZones [ source ] = createColTube ( 0, 0, 0, 10.0, 100.0 ) 
    attachElements ( playerZones [ source ], source, 0, 0, 0 ) 
    setElementData ( playerZones [ source ], "zoneOwner", source ) 
    addEventHandler ( "onColShapeHit", playerZones [ source ], zoneEnter ) 
end 
addEventHandler ( "onPlayerJoin", root, createZone ) 
  
function destroyZone ( ) 
    if ( isElement ( playerZones [ source ] ) ) then 
        destroyElement ( playerZones [ source ] ) 
    end 
end 
addEventHandler ( "onPlayerQuit", root, destroyZone ) 
  
function zoneEnter ( ) 
    local zoneOwner = getElementData ( source, "zoneOwner" ) 
    if ( zoneOwner ) then 
        outputChatBox ( "A Player is in Your Zone!", zoneOwner ) 
    end 
end 
  
function giveMoney ( ) 
    for index, player in ipairs ( getElementsWithinColShape ( playerZone, "player" ) ) do 
        givePlayerMoney ( player, 5000 ) 
    end 
end 
addEventHandler ( "onPlayerWasted", root, giveMoney ) 

Only thing I didn't understood was the giveMoney function.

Link to comment
local playerZones = { } 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            playerZones [ player ] = createColTube ( 0, 0, 0, 10.0, 100.0 ) 
            attachElements ( playerZones [ player ], player, 0, 0, 0 ) 
            setElementData ( playerZones [ player ], "zoneOwner", player ) 
            addEventHandler ( "onColShapeHit", playerZones [ player ], zoneEnter ) 
        end 
    end 
) 
  
function createZone ( ) 
    playerZones [ source ] = createColTube ( 0, 0, 0, 10.0, 100.0 ) 
    attachElements ( playerZones [ source ], source, 0, 0, 0 ) 
    setElementData ( playerZones [ source ], "zoneOwner", source ) 
    addEventHandler ( "onColShapeHit", playerZones [ source ], zoneEnter ) 
end 
addEventHandler ( "onPlayerJoin", root, createZone ) 
  
function destroyZone ( ) 
    if ( isElement ( playerZones [ source ] ) ) then 
        destroyElement ( playerZones [ source ] ) 
    end 
end 
addEventHandler ( "onPlayerQuit", root, destroyZone ) 
  
function zoneEnter ( ) 
    local zoneOwner = getElementData ( source, "zoneOwner" ) 
    if ( zoneOwner ) then 
        outputChatBox ( "A Player is in Your Zone!", zoneOwner ) 
    end 
end 
  
function giveMoney ( ) 
    for index, player in ipairs ( getElementsWithinColShape ( playerZone, "player" ) ) do 
        givePlayerMoney ( player, 5000 ) 
    end 
end 
addEventHandler ( "onPlayerWasted", root, giveMoney ) 

Only thing I didn't understood was the giveMoney function.

Ok, the givemoney function is there to give money to the players who are in the collision when the source player dies.

also, when i start it in the server, it says, server.lua :13 @bad argument addEventHandler, expected element at argument 2

Link to comment
There's no event handler on that line.

what do you mean>? it is there

  
c_root = getRootElement() 
function createZone () 
playerZone = createColTube ( 0, 0, 0, 10.0, 100.0 ) 
attachElements ( playerZone, c_root, 0, 0, 0 ) 
outputChatBox ( "created", source ) 
end 
addEventHandler ( "onPlayerJoin", c_root, createZone ) 
addEventHandler ( "onResourceStart", c_root, createZone ) 
  
function zoneEnter () 
outputChatBox("A Player is in Your Zone!", c_root) 
end 
addEventHandler ( "onColShapeHit", playerZone, zoneEnter ) --Here is the event handler 
  
function giveMoney() 
for index, player in ipairs ( getElementsWithinColShape ( playerZone, "player" ) ) do 
     givePlayerMoney( player, 5000 ) 
end 
end 
addEventHandler ("onPlayerWasted", c_root, giveMoney ) 
  

and i Cant really test it out unless i have two mta copies running, which is not possible without a vm. :/ Im trying to make a simple cop script so all cops in that area get paid.

Edited by Guest
Link to comment
May I ask, what are you doing here if you're not using the help I gave you? why aren't you using the script I posted?

My bad, i didnt realize that you posted a code, sorry :oops: stupid me.

OMG THANK YOU, IT WORKED :shock: you are truely amazing!!

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