Imposter Posted July 6, 2012 Posted July 6, 2012 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.
Imposter Posted July 6, 2012 Author Posted July 6, 2012 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 )
Castillo Posted July 6, 2012 Posted July 6, 2012 for index, player in ipairs ( getElementsWithinColShape ( theColshape, "player" ) ) do -- Your code here. end
Imposter Posted July 6, 2012 Author Posted July 6, 2012 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?
Castillo Posted July 6, 2012 Posted July 6, 2012 Just attach it when a player joins, also when the resource starts, loop players and create them as well.
Imposter Posted July 6, 2012 Author Posted July 6, 2012 (edited) 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 July 6, 2012 by Guest
Castillo Posted July 6, 2012 Posted July 6, 2012 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.
Imposter Posted July 6, 2012 Author Posted July 6, 2012 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
Castillo Posted July 6, 2012 Posted July 6, 2012 If the colshape is sucessfully created, then I don't see why it's causing that error.
Imposter Posted July 6, 2012 Author Posted July 6, 2012 If the colshape is sucessfully created, then I don't see why it's causing that error. here is a screen shot of the console...http://delta.gamerush.si6.us/mtasa/Untitled.png
Imposter Posted July 6, 2012 Author Posted July 6, 2012 (edited) 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 July 6, 2012 by Guest
Castillo Posted July 6, 2012 Posted July 6, 2012 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?
Imposter Posted July 6, 2012 Author Posted July 6, 2012 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 stupid me. OMG THANK YOU, IT WORKED you are truely amazing!!
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