SA-MP Forums Archive
OnVehicleDeath Problem - 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: OnVehicleDeath Problem (/showthread.php?tid=483768)



OnVehicleDeath Problem - zT KiNgKoNg - 27.12.2013

Hey guys when a players owned vehicles is destoryed it should send a message to the owners if he or she is online and playing.

Note: new ownerid = GetPlayerIDFromName(AddUnderScoreToName(VehicleInf o[slot][vOwnerName])); - is working correctly a returns a slot id and the correct slot, so no questions asking if it is working or not.


pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{
    new slot = GetVehicleSlotFromID(vehicleid);
    if(slot > -1)
    {
        new ownerid = GetPlayerIDFromName(AddUnderScoreToName(VehicleInfo[slot][vOwnerName]));
        if(ownerid > -1)
        {
            if(IsPlayerConnected(ownerid))
            {
                if(VehicleInfo[slot][vInsurance] > 0)
                {
                    VehicleInfo[slot][vInsurance] --;
                    VehicleInfo[slot][vDestroyed] ++;
                    VehicleInfo[slot][vImpounded] = 1;

                } else {
                    SendClientMessage(ownerid, 0xFFFFFFFF, "[{33CCFF}INFO{FFFFFF}]: I'm sorry to inform you that you don't have any insurace to cover your vehicles destoruction, and it has been impounded until you can retrive it.");
                }
            }
        }
    }
    return true;
}



Re: OnVehicleDeath Problem - Cypress - 27.12.2013

pawn Код:
if(VehicleInfo[slot][vInsurance] > 0)
                {
                    VehicleInfo[slot][vInsurance] --;
                    VehicleInfo[slot][vDestroyed] ++;
                    VehicleInfo[slot][vImpounded] = 1;

                } else {
                    SendClientMessage(ownerid, 0xFFFFFFFF, "[{33CCFF}INFO{FFFFFF}]: I'm sorry to inform you that you don't have any insurace to cover your vehicles destoruction, and it has been impounded until you can retrive it.");
                }
Would you mind putting some prints around this code? VehicleInfo[slot][vInsurance] > 0, surely not gonna get the message.

Check your code again, this time add some prints.


Re: OnVehicleDeath Problem - zT KiNgKoNg - 27.12.2013

Okay it seems that the problem is after the if(slot > 0)

pawn Код:
stock AddUnderScoreToName(Name[]) { strreplace(Name, ' ', '_'); return Name; }

stock GetPlayerIDFromName(const playername[], partofname=0)
{
    new i;
    new playername1[64];
    for (i=0;i<MAX_PLAYERS;i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i,playername1,sizeof(playername1));
            if (strcmp(playername1,playername,true)==0)
            {
                return i;
            }
        }
    }
    new correctsigns_userid=-1;
    new tmpuname[128];
    new hasmultiple=-1;
    if(partofname)
    {
        for (i=0;i<MAX_PLAYERS;i++)
        {
            if (IsPlayerConnected(i))
            {
                GetPlayerName(i,tmpuname,sizeof(tmpuname));

                if(!strfind(tmpuname,playername1[partofname],true, 0))
                {
                    hasmultiple++;
                    correctsigns_userid=i;
                }
                if (hasmultiple>0)
                {
                    return -2;
                }
            }
        }
    }
    return correctsigns_userid;
}



Re: OnVehicleDeath Problem - Cypress - 27.12.2013

Quote:
Originally Posted by zT KiNgKoNg
Посмотреть сообщение
Okay it seems that the problem is after the if(slot > 0)

pawn Код:
stock AddUnderScoreToName(Name[]) { strreplace(Name, ' ', '_'); return Name; }

stock GetPlayerIDFromName(const playername[], partofname=0)
{
    new i;
    new playername1[64];
    for (i=0;i<MAX_PLAYERS;i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i,playername1,sizeof(playername1));
            if (strcmp(playername1,playername,true)==0)
            {
                return i;
            }
        }
    }
    new correctsigns_userid=-1;
    new tmpuname[128];
    new hasmultiple=-1;
    if(partofname)
    {
        for (i=0;i<MAX_PLAYERS;i++)
        {
            if (IsPlayerConnected(i))
            {
                GetPlayerName(i,tmpuname,sizeof(tmpuname));

                if(!strfind(tmpuname,playername1[partofname],true, 0))
                {
                    hasmultiple++;
                    correctsigns_userid=i;
                }
                if (hasmultiple>0)
                {
                    return -2;
                }
            }
        }
    }
    return correctsigns_userid;
}
This code is not used for the slot value. Check the variables code VehicleInfo[slot][vInsurance] and print it out. The function you gave above is the ownerid, we don't need it as you said it returns a correct value.


Re: OnVehicleDeath Problem - zT KiNgKoNg - 28.12.2013

As i said it is retriving the slot correctly

pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{
    new slot = GetVehicleSlotFromID(vehicleid);
    if(slot > -1)
    {
        print("IN SLOT"); // THIS PRINTS ** Anything after doesn't
        new ownerid = GetPlayerIDFromName(AddUnderScoreToName(VehicleInfo[slot][vOwnerName]));
        if(ownerid > -1)
        {
            print("IN OWNER");
            if(IsPlayerConnected(ownerid))
            {
                print("IN CONNECT");
                if(VehicleInfo[slot][vInsurance] > 0)
                {
                    VehicleInfo[slot][vInsurance] --;
                    VehicleInfo[slot][vDestroyed] ++;
                    VehicleInfo[slot][vImpounded] = 1;
                    print("IN INSURE");

                } else {
                    SendClientMessage(ownerid, 0xFFFFFFFF, "[{33CCFF}INFO{FFFFFF}]: I'm sorry to inform you that you don't have any insurace to cover your vehicles destoruction, and it has been impounded until you can retrive it.");
                    print("IN ELSE");
                }
            }
        }
    }
    return true;
}