Sziasztok! Lua-t tanulok, nem rég kezdtem. De már is egy kis gondba ütköztem! Vázolom. Van egy drift score mérő script ami méri a Best Score-t ez egy client oldali lua fájl. De amikor kilépek és be, ugye ez le nullázódik, és ezt szeretném kiküszöbölni! Az tudom, hogy ezt a négy utasítást kellene használni, a getElementData, getAccountData, setElementData, és setAccountData. Ezt a négyet. Sikerült is ezekből egy olyan scriptet írnom ami az alap pénzt menti kilépéskor belépéskor pedig betölti. Ez már nem megy a drift score elmentésével, több napja próbálkozom de nem megy. Itt a client oldali drift mérő lua fájl:
--ez az alap file
local iDriftScore = 0;
local iMaxScore = 0;
local iScore = 0;
local iMyCombo = 1;
local fCustomFontScale = 2;
local bJustFinished = false;
addEventHandler( \"onClientMapStarting\", root,
function( tMapInfo )
iMaxScore = 0;
iDriftScore = 0;
iMyCombo = 0;
txtBestScore: text( \"Best Score: 0\" );
for i, v in pairs( tMapInfo ) do
outputDebugString( tostring( i ) .. \" : \" .. tostring( v ) );
end
end
);
addEventHandler( \"onClientResourceStart\", resourceRoot,
function( )
dxSetTestMode( \"none\" );
txtCombo = dxText: create( \"x2\", screenSize[ 1 ] - 100, screenSize[ 2 ] / 2 , false, \"default-bold\", 5 );
txtCombo: type( \"shadow\", 4 );
txtCombo: visible( false );
txtComboTitle = dxText: create( \"COMBO\", screenSize[ 1 ] * 0.9, screenSize[ 2 ] / 2 - 60, false, \"default-bold\", 3 );
txtComboTitle: type( \"shadow\", 3 );
txtComboTitle: visible( false );
txtScoreTitle = dxText: create( \"DRIFT\", screenSize[ 1 ] / 2, screenSize[ 2 ] / 5.6, false, \"default-bold\", 3 );
txtScoreTitle: type( \"shadow\", 3 );
txtScoreTitle: visible( false );
txtScore = dxText: create( \"\", screenSize[ 1 ] / 2, screenSize[ 2 ] / 4, false, \"default-bold\", 3 );
txtScore: visible( false );
txtScore: type( \"shadow\", 3 );
txtBestScore = dxText: create( \"Best Score: 0\", screenSize[ 1 ] * 0.8, 20, false, \"arial\", 2 );
txtBestScore: type( \"shadow\", 2 );
ftDigitalism = dxCreateFont( \"digitalism.ttf\", 20, true );
if ftDigitalism then
txtCombo: font( ftDigitalism );
txtCombo: scale( fCustomFontScale );
txtComboTitle: font( ftDigitalism );
txtComboTitle: scale( fCustomFontScale*.7 );
txtScore: font( ftDigitalism );
txtScore: scale( fCustomFontScale );
txtScoreTitle: font( ftDigitalism );
txtScoreTitle: scale( fCustomFontScale );
txtBestScore: font( ftDigitalism );
txtBestScore: scale( fCustomFontScale/2 );
end
end
)
addEventHandler( \"onClientVehicleStartDrift\", root,
function( )
addEventHandler( \"onClientVehicleDrift\", root, drift );
if not bJustFinished then
txtScore: text( \"0\" );
txtScore: visible( true );
txtScoreTitle: visible( true );
local r,g,b,a = txtScore: color( );
txtScore: color( r, g, b, 255 );
end
end
)
addEventHandler( \"onClientVehicleEndDrift\", root,
function( )
removeEventHandler( \"onClientVehicleDrift\", root, drift );
iLastScore = iDriftScore * iMyCombo;
txtCombo: visible( false );
txtComboTitle: visible( false );
txtScore: text( tostring( iLastScore ) );
Animation.createAndPlay( txtScore,
Animation.presets.dxTextMove(
screenSize[ 1 ] / 2,
screenSize[ 2 ] / 4,
100, false,
screenSize[ 1 ] * .3,
screenSize[ 2 ] / 4
)
);
--Animation.createAndPlay( txtScore, Animation.presets.dxTextFadeIn( 100 ) );
Animation.createAndPlay( txtScoreTitle,
Animation.presets.dxTextMove(
screenSize[ 1 ] / 2,
screenSize[ 2 ] / 5.6,
100, false,
screenSize[ 1 ] * .7,
screenSize[ 2 ] / 5.6
)
);
--Animation.createAndPlay( txtScoreTitle, Animation.presets.dxTextFadeIn( 300 ) );
if iLastScore > iMaxScore then
txtBestScore: text( \"Pénz(drift score): \" .. tostring( iLastScore ) );
iMaxScore = iLastScore;
end
bJustFinished = true;
setTimer( changeFinishedState, 2000, 1 );
setTimer( centreScore, 100, 1 );
iDriftScore = 0;
iMyCombo = 1;
end
)
addEventHandler( \"onClientVehicleDriftCombo\", root,
function( iCombo )
txtCombo: text( \"x\"..tostring( iCombo ) );
txtCombo: visible( true );
txtComboTitle: visible( true );
playSoundFrontEnd( 43 );
Animation.createAndPlay( txtCombo, Animation.presets.dxTextMoveResize(
screenSize[ 1 ] * 0.9,
screenSize[ 2 ] / 2 - 10,
ftDigitalism and fCustomFontScale*.75 or 5,
300, false, -- time, loop,
screenSize[ 1 ] * 0.9,
screenSize[ 2 ] / 2 - 10,
ftDigitalism and fCustomFontScale*3 or 15 ) );
Animation.createAndPlay( txtCombo, Animation.presets.dxTextFadeIn( 300 ) );
iMyCombo = iCombo;
end
);
function drift( fAngle, fSpeed, sSide, iDriftTime )
local iNewScore = math.ceil( iDriftScore + (fAngle/25) * (fSpeed/15) );
if not bJustFinished then
txtScore: text( tostring( iNewScore ) );
txtScore: visible( true );
txtScoreTitle: visible( true );
local r,g,b = txtScore: color( );
txtScore: color( r, g, b, 255 );
end
iDriftScore = iNewScore;
end
function centreScore( )
txtScore: position( screenSize[ 1 ] / 2, screenSize[ 2 ] / 4, false )
txtScoreTitle: position( screenSize[ 1 ] / 2, screenSize[ 2 ] / 5.6, false );
end
function changeFinishedState( )
bJustFinished = false;
if iDriftScore == 0 then
txtScore: visible( false );
txtScoreTitle: visible( false );
else
txtScore: text( tostring( iDriftScore ) );
end
end
Ez pedig a saját kódóm arra, hogy elmentsem. Lehet több sebből is vérzik, de ez a legutóbbi próbálkozásom a sok közül:
function onPlayerQuit( )
local playeraccount = getPlayerAccount(source)
local ertek = iMaxScore --getPlayerMoney ( source )
setAccountData(playeraccount, \"driftscore\", ertek)
end
function onPlayerLogin(_, playeraccount)
local ertek = getAccountData(playeraccount, \"driftscore\")
--setPlayerMoney(source, ertek )
setElementData ( source, iMaxScore, \"driftscore\")
end
addEventHandler(\"onPlayerLogin\",getRootElement(),onPlayerLogin)
addEventHandler(\"onPlayerQuit\",getRootElement(),onPlayerQuit)
Annak is örülök ha valaki átírja nekem, és elmagyarázza, hogy ez miért így vagy. De annak is örülnék ha valaki elmondaná, az elvet hogyan kellene, és hogy ez a 4 utasítás a paraméterei-vel együtt mit csinál?! Bármilyen segítséget elfogadok akár TS-en is Team Viewer-el is meg tudjuk beszélni ha dobsz egy pü.-t! Előre is köszönöm szépen! :)
Értem nagyjából. Valahogy így kellene? De így nem történik semmi :S Se hibaüzenet, se más :S
Így változtattam meg a dolgokat:
local iDriftScore = 0;
local iMaxScore = 0;
local iScore = 0;
local iMyCombo = 1;
local fCustomFontScale = 2;
local bJustFinished = false;
function onPlayerLogin()
iMaxScore = getAccountData ( source, \"driftscore\" )
end
addEventHandler(\"onPlayerLogin\",getRootElement(),onPlayerLogin)
addEventHandler( \"onClientMapStarting\", root,
function( tMapInfo )
iMaxScore = 0;
iDriftScore = 0;
iMyCombo = 0;
txtBestScore: text( \"Pénz(drift score): 0\" );
for i, v in pairs( tMapInfo ) do
outputDebugString( tostring( i ) .. \" : \" .. tostring( v ) );
end
end
);
addEventHandler( \"onClientResourceStart\", resourceRoot,
function( )
dxSetTestMode( \"none\" );
txtCombo = dxText: create( \"x2\", screenSize[ 1 ] - 100, screenSize[ 2 ] / 2 , false, \"default-bold\", 5 );
txtCombo: type( \"shadow\", 4 );
txtCombo: visible( false );
txtComboTitle = dxText: create( \"COMBO\", screenSize[ 1 ] * 0.9, screenSize[ 2 ] / 2 - 60, false, \"default-bold\", 3 );
txtComboTitle: type( \"shadow\", 3 );
txtComboTitle: visible( false );
txtScoreTitle = dxText: create( \"DRIFT\", screenSize[ 1 ] / 2, screenSize[ 2 ] / 5.6, false, \"default-bold\", 3 );
txtScoreTitle: type( \"shadow\", 3 );
txtScoreTitle: visible( false );
txtScore = dxText: create( \"\", screenSize[ 1 ] / 2, screenSize[ 2 ] / 4, false, \"default-bold\", 3 );
txtScore: visible( false );
txtScore: type( \"shadow\", 3 );
txtBestScore = dxText: create( \"Pénz(drift score): 0\", screenSize[ 1 ] * 0.8, 20, false, \"arial\", 2 );
txtBestScore: type( \"shadow\", 2 );
ftDigitalism = dxCreateFont( \"digitalism.ttf\", 20, true );
if ftDigitalism then
txtCombo: font( ftDigitalism );
txtCombo: scale( fCustomFontScale );
txtComboTitle: font( ftDigitalism );
txtComboTitle: scale( fCustomFontScale*.7 );
txtScore: font( ftDigitalism );
txtScore: scale( fCustomFontScale );
txtScoreTitle: font( ftDigitalism );
txtScoreTitle: scale( fCustomFontScale );
txtBestScore: font( ftDigitalism );
txtBestScore: scale( fCustomFontScale/2 );
end
end
)
addEventHandler( \"onClientVehicleStartDrift\", root,
function( )
addEventHandler( \"onClientVehicleDrift\", root, drift );
if not bJustFinished then
txtScore: text( \"0\" );
txtScore: visible( true );
txtScoreTitle: visible( true );
local r,g,b,a = txtScore: color( );
txtScore: color( r, g, b, 255 );
end
end
)
addEventHandler( \"onClientVehicleEndDrift\", root,
function( )
removeEventHandler( \"onClientVehicleDrift\", root, drift );
iLastScore = iDriftScore * iMyCombo;
txtCombo: visible( false );
txtComboTitle: visible( false );
txtScore: text( tostring( iLastScore ) );
Animation.createAndPlay( txtScore,
Animation.presets.dxTextMove(
screenSize[ 1 ] / 2,
screenSize[ 2 ] / 4,
100, false,
screenSize[ 1 ] * .3,
screenSize[ 2 ] / 4
)
);
--Animation.createAndPlay( txtScore, Animation.presets.dxTextFadeIn( 100 ) );
Animation.createAndPlay( txtScoreTitle,
Animation.presets.dxTextMove(
screenSize[ 1 ] / 2,
screenSize[ 2 ] / 5.6,
100, false,
screenSize[ 1 ] * .7,
screenSize[ 2 ] / 5.6
)
);
--Animation.createAndPlay( txtScoreTitle, Animation.presets.dxTextFadeIn( 300 ) );
if iLastScore > iMaxScore then
txtBestScore: text( \"Pénz(drift score): \" .. tostring( iLastScore ) );
iMaxScore = iLastScore;
end
bJustFinished = true;
setTimer( changeFinishedState, 2000, 1 );
setTimer( centreScore, 100, 1 );
iDriftScore = 0;
iMyCombo = 1;
setElementData (source, \"driftscore\", iMaxScore)
end
)
addEventHandler( \"onClientVehicleDriftCombo\", root,
function( iCombo )
txtCombo: text( \"x\"..tostring( iCombo ) );
txtCombo: visible( true );
txtComboTitle: visible( true );
playSoundFrontEnd( 43 );
Animation.createAndPlay( txtCombo, Animation.presets.dxTextMoveResize(
screenSize[ 1 ] * 0.9,
screenSize[ 2 ] / 2 - 10,
ftDigitalism and fCustomFontScale*.75 or 5,
300, false, -- time, loop,
screenSize[ 1 ] * 0.9,
screenSize[ 2 ] / 2 - 10,
ftDigitalism and fCustomFontScale*3 or 15 ) );
Animation.createAndPlay( txtCombo, Animation.presets.dxTextFadeIn( 300 ) );
iMyCombo = iCombo;
end
);
function drift( fAngle, fSpeed, sSide, iDriftTime )
local iNewScore = math.ceil( iDriftScore + (fAngle/25) * (fSpeed/15) );
if not bJustFinished then
txtScore: text( tostring( iNewScore ) );
txtScore: visible( true );
txtScoreTitle: visible( true );
local r,g,b = txtScore: color( );
txtScore: color( r, g, b, 255 );
end
iDriftScore = iNewScore;
end
function centreScore( )
txtScore: position( screenSize[ 1 ] / 2, screenSize[ 2 ] / 4, false )
txtScoreTitle: position( screenSize[ 1 ] / 2, screenSize[ 2 ] / 5.6, false );
end
function changeFinishedState( )
bJustFinished = false;
if iDriftScore == 0 then
txtScore: visible( false );
txtScoreTitle: visible( false );
else
txtScore: text( tostring( iDriftScore ) );
end
end
A másik fájl:
function onPlayerQuit( )
local playeraccount = getPlayerAccount(source)
local ertek = iMaxScore --getPlayerMoney ( source )
setAccountData(playeraccount, \"driftscore\", ertek)
end
function onPlayerLogin(_, playeraccount)
local ertek = getAccountData(playeraccount, \"driftscore\")
--setPlayerMoney(source, ertek )
getElementData(source,\"driftscore\")
setElementData ( source, \"driftscore\", iMaxScore)
end
addEventHandler(\"onPlayerLogin\",getRootElement(),onPlayerLogin)
addEventHandler(\"onPlayerQuit\",getRootElement(),onPlayerQuit)
Dupla hozzászólás automatikusan összefûzve. ( 2015. december 15. - 19:39:45 )
Amúgy megtennéd, hogy elmagyarázod h a 4 utasítás közül melyik mire jó és a paramétereiket? :S Mert azokkal se vagyok teljesen tisztában, hiába bújom wiki-t! :S