Register for your free account! | Forgot your password?

You last visited: Today at 12:42

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Ideal code for csv modify

Discussion on Ideal code for csv modify within the Shaiya PServer Development forum part of the Shaiya Private Server category.

Reply
 
Old   #1
 
[DEV]_Yűko's Avatar
 
elite*gold: 105
Join Date: Jun 2015
Posts: 135
Received Thanks: 74
Ideal code for csv modify

@ off
setlocal EnableDelayedExpansion

:: === Configuration ===
set "FILE=NpcQuest.csv"
set "TEMP=temp.csv"

:: === Descriptions ===
set "desc[0]=Unique ID"
set "desc[1]=Quest Title"
set "desc[2]=Active (1 = yes, 0 = no)"
set "desc[3]=Special option"
set "desc[4]=Unknown parameter 1"
set "desc[5]=Unknown parameter 2"
:: up to desc[116] if needed...

:: === MAIN MENU ===
:MENU
cls
echo ============================
echo === CSV LINE EDITOR MENU DEV YUKO ===
echo ============================
echo 1. Edit a line
echo 2. Add one or multiple lines (118 columns)
echo 3. Delete a line
echo 4. Restore backup
echo Q. Quit
echo.

set /p CHOICE="Your choice: "
if /I "%CHOICE%"=="1" goto START
if /I "%CHOICE%"=="2" goto ADD_LINE
if /I "%CHOICE%"=="3" goto DELETE_LINE
if /I "%CHOICE%"=="4" goto RESTORE_BACKUP
if /I "%CHOICE%"=="Q" goto END
goto MENU

:: === EDIT A LINE ===
:START
cls
set /p ID="Enter the ID of the line to edit (or Q to quit): "
if /I "%ID%"=="Q" goto MENU

set "lineNum=0"
set "targetLine="
set "targetIndex=0"

for /f "usebackq tokens=*" %%a in ("%FILE%") do (
set /a lineNum+=1
set "line=%%a"
echo !line! | findstr /b "%ID%," >nul
if !errorlevel! == 0 (
set "targetLine=%%a"
set "targetIndex=!lineNum!"
)
)

if not defined targetLine (
echo Line with ID %ID% not found.
pause
goto MENU
)

:: Backup
copy /Y "%FILE%" "NpcQuest_backup_%DATE:/=_%_%TIME::=_%.csv" >nul

set "newLine=!targetLine!"
for /l %%i in (0,1,117) do set "val[%%i]="

set "restLine=!newLine!"
set /a idx=0
:extract_fields
for /f "tokens=1* delims=," %%A in ("!restLine!") do (
set "val[!idx!]=%%A"
set /a idx+=1
set "restLine=%%B"
)
if defined restLine goto extract_fields

:MODIFY_LOOP
cls
echo === Current line ===
echo !newLine!
echo.

echo === Editable columns ===
set /a i=0
:show_desc
if !i! geq 118 goto show_desc_end
call set "desc_val=%%desc[%i%]%%"
if not "!desc_val!"=="" (
call set "value=%%val[%i%]%%"
echo Index !i! : !value! - !desc_val!
)
set /a i+=1
goto show_desc

:show_desc_end
echo.
set /p MODIFY_INDEX="Column index to edit (or Q to save): "
if /I "%MODIFY_INDEX%"=="Q" goto SAVE

for /f "delims=0123456789" %%c in ("%MODIFY_INDEX%") do (
echo Please enter a valid number!
pause
goto MODIFY_LOOP
)
if %MODIFY_INDEX% lss 0 goto MODIFY_LOOP
if %MODIFY_INDEX% geq 118 goto MODIFY_LOOP

call set "old_val=%%val[%MODIFY_INDEX%]%%"
set /p NEW_VAL="New value: "
set "val[%MODIFY_INDEX%]=!NEW_VAL!"

:: Rebuild the line
set "newLine="
for /l %%x in (0,1,117) do (
call set "col_value=%%val[%%x]%%"
if not defined col_value set "col_value=0"
set "newLine=!newLine!!col_value!,"
)

goto MODIFY_LOOP

:SAVE
set i=0
> "%TEMP%" (
for /f "usebackq tokens=*" %%a in ("%FILE%") do (
set /a i+=1
if !i! equ !targetIndex! (
echo !newLine!
) else (
echo %%a
)
)
)
move /y "%TEMP%" "%FILE%" >nul
echo ✅ Line saved: !newLine!
pause
goto MENU

:: === ADD LINES ===
:ADD_LINE
cls
set /p NUM="How many lines do you want to add? "
for /f "delims=0123456789" %%x in ("%NUM%") do (
echo ❌ Invalid input.
pause
goto MENU
)

:: Backup
copy /Y "%FILE%" "NpcQuest_backup_%DATE:/=_%_%TIME::=_%.csv" >nul

:: Check max existing ID
set "maxID=0"
for /f "usebackq tokens=1 delims=," %%a in ("%FILE%") do (
set /a id=%%a
if !id! gtr !maxID! set "maxID=!id!"
)

:: Add lines
(for /l %%n in (1,1,%NUM%) do (
set /a nextID=!maxID! + %%n
set "line=!nextID!"
for /l %%i in (1,1,117) do set "line=!line!,0"
echo !line!
)) >> "%FILE%"

echo ✅ %NUM% line(s) added!
pause
goto MENU

:: === DELETE A LINE WITH REINDEXING ===
ELETE_LINE
cls
set /p DELETE_ID="Enter the ID to delete: "

:: Backup
copy /Y "%FILE%" "NpcQuest_backup_%DATE:/=_%_%TIME::=_%.csv" >nul

set "found=0"
set "newIndex=1"
> "%TEMP%" (
for /f "usebackq tokens=*" %%a in ("%FILE%") do (
set "line=%%a"
for /f "tokens=1* delims=," %%b in ("%%a") do (
set "currID=%%b"
set "rest=%%c"
)
if "!currID!"=="%DELETE_ID%" (
set "found=1"
) else (
echo !newIndex!,!rest!
set /a newIndex+=1
)
)
)
if !found!==0 echo ❌ ID %DELETE_ID% not found.
move /y "%TEMP%" "%FILE%" >nul
echo ✅ Line deleted and IDs reindexed.
pause
goto MENU

:: === RESTORE BACKUP ===
:RESTORE_BACKUP
cls
echo === Restore a backup ===
echo.

setlocal EnableDelayedExpansion
set "count=0"
for %%f in (NpcQuest_backup_*.csv) do (
set /a count+=1
echo !count!. %%f
set "file[!count!]=%%f"
)
if !count! EQU 0 (
echo No backups found.
pause
goto MENU
)

echo.
set /p CHOICE="Backup file number to restore (Q to cancel): "
if /I "!CHOICE!"=="Q" goto MENU
for /f "delims=0123456789" %%x in ("!CHOICE!") do (
echo ❌ Invalid input.
pause
goto MENU
)
if !CHOICE! LSS 1 if !CHOICE! GTR !count! (
echo ❌ Invalid number.
pause
goto MENU
)

set "RESTORE_FILE=!file[%CHOICE%]!"
copy /Y "!RESTORE_FILE!" "%FILE%" >nul
echo ✅ File restored from: !RESTORE_FILE!
pause

:: Cleanup: keep last 5 backups only
setlocal EnableDelayedExpansion
set i=0
for /f "delims=" %%b in ('dir /b /o-d NpcQuest_backup_*.csv') do (
set /a i+=1
if !i! gtr 5 del "%%b"
)

goto MENU

:END
echo Program ended.
pause
exit /b




Add to files .bat
[DEV]_Yűko is offline  
Reply


Similar Threads Similar Threads
[Release] Expedition 4.0.3 Monster.csv, Info.csv, Maplist.csv, Warp.csv
09/28/2008 - Dekaron Exploits, Hacks, Bots, Tools & Macros - 23 Replies
Here are a few of the more popular csv files from the Expedition patch. If you don't know what they are, or any way to use them, then don't worry about them. I like to have the current csv files handy because it makes it easier to find the offsets in the pack. There may be more uses...who knows. This maplist does have a zoomhack on it. Other than that I do not believe they have been modified but, I do not guarantee it.
who can give me 2moons expedetion new info.csv and monster.csv
09/07/2008 - Dekaron - 8 Replies
who can give me 2moons expedetion new info.csv and monster.csv files



All times are GMT +1. The time now is 12:45.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.