View Issue Details

IDProjectCategoryView StatusLast Update
0002507Multi Theft Auto : San AndreasScriptingpublic2007-09-14 13:41
ReporterjbetaAssigned ToJax 
PrioritylowSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformAMD Athlon(tm) 64 X2 ~2.2GHzOSWindows XP Professional x64 SP1OS Version5.2, Build 3790
Product Versionblue_sa.r2.a12 
Target VersionFixed in Versionmtasadm_v1.0-dp1 
Summary0002507: Cancelling onPlayerChat doesn't have effect if the cancelEvent() call isn't on the last added handler
Description

Self explanatory.

Steps To Reproduce

/start runcode
/run addEventHandler( "onPlayerChat", getRootElement(), function() outputChatBox "Chat cancelled [1]." cancelEvent() end )

Send a message, it will be cancelled.

/run addEventHandler( "onPlayerChat", getRootElement(), function() outputChatBox "This handler doesn't cancel the chat." end )

Now it won't...

/run addEventHandler( "onPlayerChat", getRootElement(), function() outputChatBox "Chat cancelled [2]." cancelEvent() end )

And not it will be cancelled again.

Additional Information

This didn't happen with other events such as onVehicleStartEnter, still haven't tried all of them.

TagsNo tags attached.

Activities

jbeta

2007-09-14 11:38

updater   ~~0005713

Last edited: 2007-09-14 11:43

Use test resources onplayerchat1, onplayerchat2: one blocks the original message while the other one doesn't.

[ONPLAYERCHAT1]
local chatRadius = 20 --units

-- define a handler that will distribute the message to all nearby players
function sendMessageToNearbyPlayers( message, messageType )
-- we will only send normal chat messages, action and team types will be ignored
if messageType == 0 then
-- get the chatting player's position
local posX, posY, posZ = getElementPosition( source )

    -- create a sphere of the specified radius in that position
    local chatSphere = createColSphere( posX, posY, posZ, chatRadius )
    -- get a table all player elements inside it
    local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" )
    -- and destroy the sphere, since we're done with it
    destroyElement( chatSphere )

    -- deliver the message to each player in that table
    for index, nearbyPlayer in ipairs( nearbyPlayers ) do
        outputChatBox( message, nearbyPlayer )
    end
end

end
-- attach our new chat handler to onPlayerChat
addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers )

-- define another handler function that cancels the event so that the message won't be delivered through the
function blockChatMessage()
cancelEvent()
end
-- attach it as a handler to onPlayerChat
addEventHandler( "onPlayerChat", getRootElement(), blockChatMessage )

[ONPLAYERCHAT2]
-- define another handler function that cancels the event so that the message won't be delivered through the
function blockChatMessage()
cancelEvent()
end
-- attach it as a handler to onPlayerChat
addEventHandler( "onPlayerChat", getRootElement(), blockChatMessage )

local chatRadius = 20 --units

-- define a handler that will distribute the message to all nearby players
function sendMessageToNearbyPlayers( message, messageType )
-- we will only send normal chat messages, action and team types will be ignored
if messageType == 0 then
-- get the chatting player's position
local posX, posY, posZ = getElementPosition( source )

    -- create a sphere of the specified radius in that position
    local chatSphere = createColSphere( posX, posY, posZ, chatRadius )
    -- get a table all player elements inside it
    local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" )
    -- and destroy the sphere, since we're done with it
    destroyElement( chatSphere )

    -- deliver the message to each player in that table
    for index, nearbyPlayer in ipairs( nearbyPlayers ) do
        outputChatBox( message, nearbyPlayer )
    end
end

end
-- attach our new chat handler to onPlayerChat
addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers )

Jax

2007-09-14 13:41

administrator   ~~0005715

Caused by an event getting called inside another

Issue History

Date Modified Username Field Change