Bom questionamento, porém acredito eu que não. Pois no if eu estou comparando a "data" da marker hitada, com a "data" salva na tabela.
Quando o gaimo salva a marker na tabela acredito eu que seja algo mais ou menos assim:
markers = { -- a tabela nomeada
userdata = { -- uma segunda tabela(sub-tabela), que seria a userdata ([thePlayer])
["StartData"] = markerData -- e por fim ele salva a "data" do marker.
},
};
Seguindo a lógica acima, o que me importa é a markerData, então quando eu faço assim:
if marker == markers[source]["StartMarker"] then
Eu to querendo dizer:
SE a data da marker hitada é equivalente a data que esta dentro da sub-tabela(source, que no caso é a userdata) com index de ["StartMarker"] então faça:
Abaixo o código, testado:
veh = {};
markers = {};
for i=1,6 do
veh[createVehicle(459, 1700.75781 + 3*i, -1806.09680, 13.54688, 0,0,0)] = true;
createBlip(1700.75781, -1806.09680, 13.54688);
end
addEventHandler ( "onVehicleEnter", getRootElement(),
function(thePlayer, seat)
if not markers[thePlayer] then
markers[thePlayer] = {};
end
if veh[getPedOccupiedVehicle(thePlayer)] then
markers[thePlayer]["StartMarker"] = createMarker(1683.57776, -1811.70239, 13.54688 - 0.8, "cylinder", 3, 255, 0, 0, 255, thePlayer);
createMarker(1683.57776, -1811.70239 + 5, 13.54688 - 0.8, "cylinder", 3, 0, 255, 0, 255, thePlayer);
createBlipAttachedTo(markers[thePlayer]["StartMarker"]);
outputChatBox("marker table: "..tostring(markers[thePlayer]), thePlayer, 255, 255, 0); -- debug
outputChatBox("marker data: "..tostring(markers[thePlayer]["StartMarker"]), thePlayer, 255, 255, 0); -- debug
end
end)
addEventHandler("onPlayerMarkerHit", getRootElement(),
function(marker, dim)
if dim then
outputChatBox("onHit: "..tostring(marker), source, 0, 255, 0); -- debug
if marker ~= markers[source]["StartMarker"] then -- se for diferente
outputChatBox("o marker é diferente", source, 255, 0, 0);
else -- se for igual
outputChatBox("o marker é igual", source, 0, 255, 0);
end
end
end)
addCommandHandler("teste",
function(player)
for index, value in pairs(markers) do -- se fizer com ipairs não irá funcionar, por causa do "StartMarker"
outputChatBox(" #ff0000indexado: #ffffff"..tostring(index).." #ff0000tabela: #ffffff"..tostring(value).." #ff0000valorReal: #ffffff"..tostring(value["StartMarker"]),player, 255, 0, 255, true);
end
end
)
Abaixo mais uma "prova" dessa explicação, agora com tudo declarado:
test = { -- tabela nomeada
test2 = { -- "sub-tabela"
["value"] = 10, -- index contendo o valor desejado.
},
};
for i, v in pairs(test) do
outputChatBox(tostring(v["value"]));
end
OBS (muito importante): Eu tenho absoluta certeza do que estou falando?
R: Nem um pouco, provavelmente posso estar falando groselha, e se estiver quem souber melhor por favor comente xD. Porém os códigos acima foram testados e funcionou!
@Angelo Pereira