SA-MP Forums Archive
A question regarding saving vehicle damage - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: A question regarding saving vehicle damage (/showthread.php?tid=522228)



A question regarding saving vehicle damage - WingedFrostWolf - 26.06.2014

Hello, I'd like to know if it is possible to make a system which saves the damage of cars (visible and /dl damage) to a file which can then be loaded after a server restart, without using MySQL. I tried searching the forum, but I couldn't find any information regarding this topic. Any feedback would be greatly appreciated, thanks.


Re: A question regarding saving vehicle damage - BroZeus - 26.06.2014

ofc it is
use
https://sampwiki.blast.hk/wiki/SetVehicleHealth
https://sampwiki.blast.hk/wiki/UpdateVehicleDamageStatus


Re: A question regarding saving vehicle damage - WingedFrostWolf - 26.06.2014

I tried making a script that would use the function, but I can't get it to save the value. It always stay at zero. Any ideas?

Код:
#include <a_samp>
#include <YSI\y_ini>

new

    CarDamage[ MAX_VEHICLES ]
;

stock user_ini_file(playerid)
{
    new
        string[ 128 ],
        user_name[ MAX_VEHICLES ]
    ;

    GetPlayerName( playerid, user_name, MAX_VEHICLES );
    format( string, sizeof ( string ), "%s.ini", user_name );
    return
        string;
}

forward @load_user_position( vehicleid, name[], value[] );

@load_user_position( vehicleid, name[], value[] )
{
    INI_Int( "Vehicle", CarDamage[ vehicleid ] );
    return 1;
}


public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    new panels, doors, lights, tires;
    GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
    new INI:File = INI_Open(user_ini_file( playerid ) );
    INI_SetTag( File, "damage" );
    INI_WriteInt( File, "VehDamage", CarDamage[ playerid ] );
    //SendClientMessage(playerid,0xAA3333AA,"Written file"); - Debbuging purposes

    INI_Close( File );
    return 1;
}


public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat)
{
    CarDamage[ vehicleid ] = 0;
    new panels = 0, doors = 0, lights = 0, tires = 0;
    INI_ParseFile( user_ini_file( playerid ), "load_user__%s", .bExtra = true, .extra = playerid );
    UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    //SendClientMessage(playerid,0xAA3333AA,"Updated unnocupied vehicle"); -Debugging aswell

    return 1;
}



Re: A question regarding saving vehicle damage - RedFusion - 26.06.2014

It would be way better if you saved the vehicle's damage and params only when the server shuts down. Also it seems like you're trying to save vehicle damage to playerfiles?


Re: A question regarding saving vehicle damage - WingedFrostWolf - 26.06.2014

I used a tutorial as help for the script, which saves the player's info, but I'm starting to get the idea that it doesn't work the same with vehicles. Also, how should I make it so that is saves on server shutdown?


Re: A question regarding saving vehicle damage - RedFusion - 26.06.2014

put the file-saving part inside OnGameModeExit()
https://sampwiki.blast.hk/wiki/OnGameModeExit


Re: A question regarding saving vehicle damage - WingedFrostWolf - 26.06.2014

I put the saving part under OnGameModeExit, but it still saves the car value as 0. I guess I'm not saving it right, but I have no idea how I should save vehicle info.