Siemka, mam problem z funkcj? setPlayerWantedLevel.
Chce aby gracz, kt?ry ma ponad 50000$ mia? jedn? gwiazdk? i im wi?cej hajsu tym wi?cej gwiazdek, co wida? w kodzie. Lecz tak jak mam to mi nie dzia?a. Wie kto? w czym le?y problem? Kod jest po stronie serwera.
thePlayer w tym przypadku to tylko nadanie innej nazwy niezdefiniowanemu argumentowi funkcji, kt?rego tak naprawd? nigdzie nie wywo?ujesz, bo event onResourceStart, opr?cz uruchamianego zasobu, nie przyjmuje ?adnych innych parametr?w, kt?re m?g?by? "na czysto" wykorzysta? w kodzie. Musisz wi?c najpierw okre?li? gracza. Polecam skorzysta? z tego:
W razie gdyby? mia? problemy, zamieszczam nieprzetestowany kod:
function setWantedLevel(dataName, oldValue, newValue)
if getElementType(source) == "player" and client == source then
if (dataName == "player:money") then
if (newValue ~= oldValue and newValue > 50000) then
setPlayerWantedLevel(source, 1)
elseif (newValue ~= oldValue and newValue > 100000) then
setPlayerWantedLevel(source, 2)
elseif (newValue ~= oldValue and newValue > 200000) then
setPlayerWantedLevel(source, 3)
end
end
end
end
addEventHandler("onElementDataChange", getRootElement(), setWantedLevel)
Powy?szy kod ma ma?y b??d: sprawdzasz w nim stan 'client', co jest predefiniowane tylko po stronie klienta (event po serwerze).
client: The client global variable is set to the client that called setElementData, or nil if it was called on the server.
Jest to zale?ne od strony, na kt?rej nadana zosta?a element data. Je?li mia?oby to miejsce po stronie clienta, warunek mia?by jak najbardziej sens. Jednak skoro kod jest po stronie serwera, powinienem przyj??, ?e autor ma zamiar nada? element dat? r?wnie? po tej samej stronie, wi?c fakt, warunek zb?dny.
function setWantedLevel(dataName, oldValue, newValue)
if getElementType(source) == "player" then
if (dataName == "player:money") then
if (newValue > 50000) then
setPlayerWantedLevel(source, 1)
elseif (newValue > 100000) then
setPlayerWantedLevel(source, 2)
elseif (newValue > 200000) then
setPlayerWantedLevel(source, 3)
end
end
end
end
addEventHandler("onElementDataChange", getRootElement(), setWantedLevel)
Gorn5, kod niestety nie zbyt dzia?a.
Poka? kod, w kt?rym nadajesz wymaganemu elementowi element date.
Nie możesz pisać nowych tematów Nie możesz odpowiadać w tematach Nie możesz zmieniać swoich postów Nie możesz usuwać swoich postów Nie możesz głosować w ankietach