OnPlayerModInfo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server event}}
{{Server event}}
This event is triggered when a player has modified certain files
This event is triggered when a player has modified certain files.
 
{{Note|Any resource using this event should call [[resendPlayerModInfo]] for each player in [[onResourceStart]].}}
==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int category, table ids, table names
string filename, table itemlist
</syntaxhighlight>  
</syntaxhighlight>  


*'''category''': An integer indicating what category of file has been modified. Currently there is only one category:
*'''filename''': a [[string]] with the filename of the modified file.
<div style="border:0px solid grey;margin-bottom:3px;padding-left:25px;">
*'''itemlist''': a [[table]] with the details of each modification within the file. Possible keys for each sub-table are:
<div style="border:1px solid grey;margin-bottom:3px;padding-left:5px;">
**'''id''': GTA model or texture id.
<div style="float:right;padding-right:5px;font-weight:bold;"></div>
**'''name''': GTA name.
*'''1:''' gta3.img
**'''sizeX, sizeY, sizeZ''': the modified model size (if the item is a DFF).
</div>
**'''originalSizeX, originalSizeY, originalSizeZ''': the unmodified model size (if the item is a DFF).
</div>
**'''length''': length in bytes of the item.
*'''ids''': A table with the id's of the parts of the file that have been modified
**'''md5''': md5 of the item bytes.
*'''names''': A table with the names of the parts of the file that have been modified
**'''sha256''': sha256 of the item bytes.
**'''paddedLength''': length in bytes of the item padded to 2048 byte boundary.
**'''paddedMd5''': md5 of the item bytes padded to 2048 byte boundary.
**'''paddedSha256''': sha256 of the item bytes padded to 2048 byte boundary.


==Source==
==Source==
The [[event system#Event source|source]] of this event is the [[player]]
The [[event system#Event source|source]] of this event is the [[player]].


==Example==  
==Example==  
This example asks awkward questions unless the player has only changed the radar graphic
This example prints all modification information into the chatbox.
<syntaxhighlight lang="lua">
 
function handleOnPlayerModInfo ( filename, modList )
    -- Print player name and file name
    outputChatBox( getPlayerName(source) .. " " .. filename )
 
    -- Print details on each modification
    for idx,item in ipairs(modList) do
        outputChatBox( idx .. ") id:" .. item.id .. " name:" .. item.name )
        if item.sizeX then
            outputChatBox( "size:" .. item.sizeX .. "," .. item.sizeY .. "," .. item.sizeZ )
            outputChatBox( "originalSize:" .. item.originalSizeX .. "," .. item.originalSizeY .. "," .. item.originalSizeZ )
        end
        if item.length then
            outputChatBox( "length:" .. item.length .. " md5:" .. item.md5 )
        end
    end
end
addEventHandler ( "onPlayerModInfo", getRootElement(), handleOnPlayerModInfo )
 
-- Ensure no one gets missed when the resource is (re)started
addEventHandler( "onResourceStart", resourceRoot,
    function()
        for _,plr in ipairs( getElementsByType("player") ) do
            resendPlayerModInfo( plr )
        end
    end
)</syntaxhighlight>
 
 
This example checks modified files against a list and prints a warning in the chatbox.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerModInfo ( category, ids, names )
 
if category == 'gta3.img' then
checkModels = { "m4.dff", "ak47.dff" }
for k,v in pairs(names) do
 
if not string.find( v, "radar" ) then
function handleOnPlayerModInfo ( filename, modList )
outputChatBox( getPlayerName(source) .. ", why have you modified " .. v .. "?" )
    for _,item in ipairs(modList) do -- Check each modified item
end
        for _,checkName in ipairs(checkModels) do
end
            if item.name == checkName then -- See if modified item is in our check list
end
                outputChatBox ( "Not allowed to used modified weapons. Please restore " .. filename )
end
            end
addEventHandler ( "onPlayerModInfo", getRootElement(),onPlayerModInfo )
        end
    end
end
addEventHandler ( "onPlayerModInfo", getRootElement(), handleOnPlayerModInfo )
 
-- Ensure no one gets missed when the resource is (re)started
addEventHandler( "onResourceStart", resourceRoot,
    function()
        for _,plr in ipairs( getElementsByType("player") ) do
            resendPlayerModInfo( plr )
        end
    end
)
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Player events}}
{{See also/Server event|Player events}}

Latest revision as of 03:01, 27 September 2018

This event is triggered when a player has modified certain files.

[[{{{image}}}|link=|]] Note: Any resource using this event should call resendPlayerModInfo for each player in onResourceStart.

Parameters

string filename, table itemlist
  • filename: a string with the filename of the modified file.
  • itemlist: a table with the details of each modification within the file. Possible keys for each sub-table are:
    • id: GTA model or texture id.
    • name: GTA name.
    • sizeX, sizeY, sizeZ: the modified model size (if the item is a DFF).
    • originalSizeX, originalSizeY, originalSizeZ: the unmodified model size (if the item is a DFF).
    • length: length in bytes of the item.
    • md5: md5 of the item bytes.
    • sha256: sha256 of the item bytes.
    • paddedLength: length in bytes of the item padded to 2048 byte boundary.
    • paddedMd5: md5 of the item bytes padded to 2048 byte boundary.
    • paddedSha256: sha256 of the item bytes padded to 2048 byte boundary.

Source

The source of this event is the player.

Example

This example prints all modification information into the chatbox.


function handleOnPlayerModInfo ( filename, modList )
    -- Print player name and file name
    outputChatBox( getPlayerName(source) .. " " .. filename )

    -- Print details on each modification
    for idx,item in ipairs(modList) do
        outputChatBox( idx .. ") id:" .. item.id .. " name:" .. item.name )
        if item.sizeX then
            outputChatBox( "size:" .. item.sizeX .. "," .. item.sizeY .. "," .. item.sizeZ )
            outputChatBox( "originalSize:" .. item.originalSizeX .. "," .. item.originalSizeY .. "," .. item.originalSizeZ )
        end
        if item.length then
            outputChatBox( "length:" .. item.length .. " md5:" .. item.md5 )
        end
    end
end
	
addEventHandler ( "onPlayerModInfo", getRootElement(), handleOnPlayerModInfo )

-- Ensure no one gets missed when the resource is (re)started
addEventHandler( "onResourceStart", resourceRoot,
    function()
        for _,plr in ipairs( getElementsByType("player") ) do
            resendPlayerModInfo( plr )
        end
    end
)


This example checks modified files against a list and prints a warning in the chatbox.


checkModels = { "m4.dff", "ak47.dff" }

function handleOnPlayerModInfo ( filename, modList )
    for _,item in ipairs(modList) do			-- Check each modified item
        for _,checkName in ipairs(checkModels) do
            if item.name == checkName then		-- See if modified item is in our check list
                outputChatBox ( "Not allowed to used modified weapons. Please restore " .. filename )
            end
        end
    end
end
	
addEventHandler ( "onPlayerModInfo", getRootElement(), handleOnPlayerModInfo )

-- Ensure no one gets missed when the resource is (re)started
addEventHandler( "onResourceStart", resourceRoot,
    function()
        for _,plr in ipairs( getElementsByType("player") ) do
            resendPlayerModInfo( plr )
        end
    end
)

See Also

Player events


Event functions