Losing vehicles upon changing name
#1

Hello,

I'm working on a RP script and I'm using AVS (Advanced Vehicle System) by MadeMan as a dealership system, the problem is that this FS works on the way that upon using /trackcar (to figure out your cars), it loops trough all vehicles in-game and checks for your name, but if I change my name it doesnt search for it.

How can I add to the /changename command that it'll check for all my vehicles, and change "Owner" to my new name?
Reply
#2

this in the AVS script
pawn Код:
forward OnPlayerNameChange(oldname[], newname[]);//by MadeMan
public OnPlayerNameChange(oldname[], newname[])
{
    for(new i=1; i < MAX_DVEHICLES; i++)
    {
        if(VehicleCreated[i] == VEHICLE_PLAYER && strcmp(VehicleOwner[i], oldname) == 0)
        {
            strmid(VehicleOwner[i], newname, 0, MAX_PLAYER_NAME);
        }
    }
}
This in your GM under the name change thing
pawn Код:
CallRemoteFunction("OnPlayerNameChange", "ss", GetPlayerNameEx(Target), newname);
Reply
#3

Thank you.

Just one problem, if I use it by chaning my name the server crashes, probably because a file/folder is missing.
Reply
#4

Hmm, how did you use it?
Can you show me the changename command?
Reply
#5

pawn Код:
command(changename, playerid, params[])
{
    new id, NewName[MAX_PLAYER_NAME];
    if(sscanf(params, "uz", id, NewName))
    {
        if(Player[playerid][AdminLevel] >= 4)
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /changename [playerid] [new name]");
        }
    }
    else
    {
        new NameStr[40], CurrentName[MAX_PLAYER_NAME], string[128];
       
        if(Player[playerid][AdminLevel] >= 4)
        {
            if(Player[id][AdminLevel] >= 1 && Player[playerid][AdminLevel] < 5)
            {
                SendClientMessage(playerid, WHITE, "You cannot adjust the name of another Administrator unless being Head Admin.");
            }
            else
            {
                if(Player[playerid][AdminLevel] >= Player[id][AdminLevel])
                {
                    if(strlen(NewName) >= 3 && strlen(NewName) < MAX_PLAYER_NAME)
                    {
                        GetPlayerName(id, CurrentName, sizeof(CurrentName));
                        //format(string, sizeof(string), "scriptfiles/Accounts/%s.ini", CurrentName);
                        format(NameStr, sizeof(NameStr), "Accounts/%s.ini", NewName);

                        if(fexist(NameStr))
                        {
                            SendClientMessage(playerid, WHITE, "That account name is already registered.");
                        }
                        else
                        {
                            format(Player[id][NormalName], MAX_PLAYER_NAME, "%s", NewName);

                            //file_delete(string);
                            fremove(NameStr);
                           
                            CallRemoteFunction("OnPlayerNameChange", "ss", GetPlayerName(id), NewName);

                            SetPlayerName(id, NewName);

                            SavePlayerData(id);

                            format(string, sizeof(string), "WARNING: Server Admin %s has renamed %s to %s.", GetName(playerid), CurrentName, NewName);
                            AdminActionsLog(string);
                            NamechangeLog(string);
                            SendToAdmins(ADMINORANGE, string, 1);

                            if(Player[id][Business] >= 1 || Player[id][House] >= 1)
                            {
                                if(strcmp(Businesses[Player[id][Business]][bOwner], CurrentName, true) == 0)
                                {
                                    format(Businesses[Player[id][Business]][bOwner], MAX_PLAYER_NAME, "%s", NewName);
                                }

                                if(strcmp(Houses[Player[id][House]][hOwner], CurrentName, true) == 0)
                                {
                                    format(Houses[Player[id][House]][hOwner], 255, "%s", NewName);
                                }
                            }

                            format(string, sizeof(string), "Your name has been changed from %s to %s, by %s.", CurrentName, NewName, Player[playerid][AdminName]);
                            SendClientMessage(id, WHITE, string);

                            SendClientMessage(id, GREY, "Don't worry about re-connecting, just don't forget to change your name in the connection client!");

                        }

                    }
                    else
                    {
                        format(string, sizeof(string), "Names must be 3 - %d characters in length.", MAX_PLAYER_NAME);
                        SendClientMessage(playerid, WHITE, string);
                    }
                }
            }
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)