Code for checking if player is surfing a DYNAMIC Object
#1

Ok I've updated my code and I'm currently testing it. It seems to be working pretty well actually! If any one has any suggestions for this code or see's anything not working please let me know.

pawn Код:
new SurfObject[MAX_PLAYERS];
new Float:FirstPosX[MAX_PLAYERS],Float:FirstPosY[MAX_PLAYERS],Float:FirstPosZ[MAX_PLAYERS];
new Float:FirstOPosX[MAX_PLAYERS],Float:FirstOPosY[MAX_PLAYERS],Float:FirstOPosZ[MAX_PLAYERS];
new Float:FirstDistance[MAX_PLAYERS];
new Float:SecondPosX[MAX_PLAYERS],Float:SecondPosY[MAX_PLAYERS],Float:SecondPosZ[MAX_PLAYERS];
new Float:SecondOPosX[MAX_PLAYERS],Float:SecondOPosY[MAX_PLAYERS],Float:SecondOPosZ[MAX_PLAYERS];
new Float:SecondDistance[MAX_PLAYERS];
new SurfDetect[MAX_PLAYERS];
new SurfDetect2[MAX_PLAYERS];
new SurfDetectActive[MAX_PLAYERS];
pawn Код:
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
    if(SurfDetectActive[playerid] == 0)
    {
        SurfObject[playerid] = ObjectInfo[objectid][oObject];
        SurfDetect[playerid] = SetTimerEx("FirstSurfCheck", 1000, false, "i", playerid);
        SurfDetectActive[playerid] = 1;
    }
    if(!IsValidDynamicObject(objectid)) return 0;
    MoveDynamicObject(objectid, x, y, z, 10.0, rx, ry, rz);
    if(response == EDIT_RESPONSE_FINAL)
    {
        for(new i; i < sizeof(ObjectInfo); i++)
        {
            if(ObjectInfo[i][oCreated] == 0 && EditingObject[playerid] == -1)
            {
                new string[128];
                ObjectInfo[i][oVW] = GetPlayerVirtualWorld(playerid);
                ObjectInfo[i][oINT] = GetPlayerInterior(playerid);
                ObjectInfo[i][oX] = x;
                ObjectInfo[i][oY] = y;
                ObjectInfo[i][oZ] = z;
                ObjectInfo[i][oRX] = rx;
                ObjectInfo[i][oRY] = ry;
                ObjectInfo[i][oRZ] = rz;
                ObjectInfo[i][oCreated] = 1;
                SaveObjects();
                format(string, sizeof(string), "[OBJECT CREATE] ID %d | Name %s | SAVED", i, ObjectInfo[i][oName]);
                SendClientMessage(playerid, COLOR_ORANGE, string);
                DestroyDynamicObject(ObjectInfo[i][oObject]);
                ObjectInfo[i][oObject] = AddDynamicObject(ObjectInfo[i][oModel],ObjectInfo[i][oX],ObjectInfo[i][oY],ObjectInfo[i][oZ],ObjectInfo[i][oRX],ObjectInfo[i][oRY],ObjectInfo[i][oRZ],ObjectInfo[i][oVW],ObjectInfo[i][oINT], -1, 200.0);
                if(ObjectInfo[i][oChair] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $400 for the chair");
                    GivePlayerCash(playerid, -400);
                }
                if(ObjectInfo[i][oBed] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $450 for the bed");
                    GivePlayerCash(playerid, -450);
                }
                if(ObjectInfo[i][oTable] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $150 for the table");
                    GivePlayerCash(playerid, -150);
                }
                if(ObjectInfo[i][oElectronic] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $500 for the electronics");
                    GivePlayerCash(playerid, -500);
                }
                if(ObjectInfo[i][oCabinet] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $250 for the cabinet");
                    GivePlayerCash(playerid, -250);
                }
                if(ObjectInfo[i][oKitchen] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $300 for the kitchen furniture");
                    GivePlayerCash(playerid, -300);
                }
                if(ObjectInfo[i][oPicture] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $80 for the picture");
                    GivePlayerCash(playerid, -80);
                }
                if(ObjectInfo[i][oDoor] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $200 for the door");
                    GivePlayerCash(playerid, -200);
                }
                if(ObjectInfo[i][oSafe] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $2000 for the safe");
                    GivePlayerCash(playerid, -2000);
                }
                if(ObjectInfo[i][oBath] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $250 for the bathroom furniture");
                    GivePlayerCash(playerid, -250);
                }
                EditMode[playerid] = 0;
                SurfObject[playerid] = 0;
                SurfDetectActive[playerid] = 0;
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                return 1;
            }
            if(ObjectInfo[i][oCreated] == 1 && EditingObject[playerid] == i)
            {
                new string[128];
                ObjectInfo[i][oVW] = GetPlayerVirtualWorld(playerid);
                ObjectInfo[i][oINT] = GetPlayerInterior(playerid);
                ObjectInfo[i][oX] = x;
                ObjectInfo[i][oY] = y;
                ObjectInfo[i][oZ] = z;
                ObjectInfo[i][oRX] = rx;
                ObjectInfo[i][oRY] = ry;
                ObjectInfo[i][oRZ] = rz;
                ObjectInfo[i][oCreated] = 1;
                SaveObjects();
                format(string, sizeof(string), "[OBJECT EDIT] ID %d | Name %s | SAVED", i, ObjectInfo[i][oName]);
                SendClientMessage(playerid, COLOR_ORANGE, string);
                DestroyDynamicObject(ObjectInfo[i][oObject]);
                ObjectInfo[i][oObject] = AddDynamicObject(ObjectInfo[i][oModel],ObjectInfo[i][oX],ObjectInfo[i][oY],ObjectInfo[i][oZ],ObjectInfo[i][oRX],ObjectInfo[i][oRY],ObjectInfo[i][oRZ],ObjectInfo[i][oVW],ObjectInfo[i][oINT], -1, 200.0);
                EditingObject[playerid] = -1;
                EditMode[playerid] = 0;
                SurfObject[playerid] = 0;
                SurfDetectActive[playerid] = 0;
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                return 1;
            }
        }
    }
    if(response == EDIT_RESPONSE_CANCEL)
    {
        for(new i; i < sizeof(ObjectInfo); i++)
        {
            if(ObjectInfo[i][oCreated] == 0 && EditingObject[playerid] == -1)
            {
                DestroyDynamicObject(ObjectInfo[i][oObject]);
                SendClientMessage(playerid, COLOR_ORANGE, "[OBJECT CREATE] - Cancelled");
                ObjectInfo[i][oModel] = 0;
                ObjectInfo[i][oObject] = 0;
                ObjectInfo[i][oChair] = 0;
                ObjectInfo[i][oBed] = 0;
                ObjectInfo[i][oTable] = 0;
                ObjectInfo[i][oElectronic] = 0;
                ObjectInfo[i][oCabinet] = 0;
                ObjectInfo[i][oKitchen] = 0;
                ObjectInfo[i][oPicture] = 0;
                ObjectInfo[i][oDoor] = 0;
                ObjectInfo[i][oSafe] = 0;
                strdel(ObjectInfo[i][oName], 0, 20);
                EditMode[playerid] = 0;
                SurfObject[playerid] = 0;
                SurfDetectActive[playerid] = 0;
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                return 1;
            }
            if(ObjectInfo[i][oCreated] == 1 && EditingObject[playerid] == i)
            {
                DestroyDynamicObject(ObjectInfo[i][oObject]);
                ObjectInfo[i][oObject] = AddDynamicObject(ObjectInfo[i][oModel],ObjectInfo[i][oX],ObjectInfo[i][oY],ObjectInfo[i][oZ],ObjectInfo[i][oRX],ObjectInfo[i][oRY],ObjectInfo[i][oRZ],ObjectInfo[i][oVW],ObjectInfo[i][oINT], -1, 200.0);
                SendClientMessage(playerid, COLOR_ORANGE, "[OBJECT EDIT] - Cancelled");
                EditingObject[playerid] = -1;
                EditMode[playerid] = 0;
                SurfObject[playerid] = 0;
                SurfDetectActive[playerid] = 0;
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                return 1;
            }
        }
    }
    return true;
}
pawn Код:
forward FirstSurfCheck(playerid);
public FirstSurfCheck(playerid)
{
    GetPlayerPos(playerid, FirstPosX[playerid], FirstPosY[playerid], FirstPosZ[playerid]);
    GetDynamicObjectPos(SurfObject[playerid], FirstOPosX[playerid], FirstOPosY[playerid], FirstOPosZ[playerid]);
    FirstDistance[playerid] = GetPlayerDistanceFromPoint(playerid, FirstOPosX[playerid], FirstOPosY[playerid], FirstOPosZ[playerid]);
    SurfDetect2[playerid] = SetTimerEx("SecondSurfCheck", 1000, false, "i", playerid);
}

forward SecondSurfCheck(playerid);
public SecondSurfCheck(playerid)
{
    GetPlayerPos(playerid, SecondPosX[playerid], SecondPosY[playerid], SecondPosZ[playerid]);
    GetDynamicObjectPos(SurfObject[playerid], SecondOPosX[playerid], SecondOPosY[playerid], SecondOPosZ[playerid]);
    SecondDistance[playerid] = GetPlayerDistanceFromPoint(playerid, SecondOPosX[playerid], SecondOPosY[playerid], SecondOPosZ[playerid]);
    if(SecondDistance[playerid] == FirstDistance[playerid] && SecondPosX[playerid] != FirstPosX[playerid] || SecondPosY[playerid] != FirstPosY[playerid] || SecondPosZ[playerid] != FirstPosZ[playerid] && SecondOPosX[playerid] != FirstOPosX[playerid] || SecondOPosY[playerid] != FirstOPosY[playerid] || SecondOPosZ[playerid] != FirstOPosZ[playerid])
    {
        GameTextForPlayer(playerid, "~r~OBJECT SURFING DETECTED", 3000, 5);
        for(new i = 0; i < sizeof(HouseInfo); i++)
        {
            if(GetPlayerVirtualWorld(playerid) == HouseInfo[i][EnterWorld] && GetPlayerInterior(playerid) == HouseInfo[i][EnterInterior])
            {
                SetPlayerPos(playerid, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]);
                SetTimerEx("CancelEditForPlayer", 1000, false, "i", playerid);
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
            }
        }
    }
    if(SecondDistance[playerid] != FirstDistance[playerid])
    {
        FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
        FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
        FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
        FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
        FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
        FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
        FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
        SurfDetect[playerid] = SetTimerEx("FirstSurfCheck", 1000, false, "i", playerid);
    }
}

forward CancelEditForPlayer(playerid);
public CancelEditForPlayer(playerid)
{
    CancelEdit(playerid);
}
I hope this helped some of you!
Reply
#2

-Updated code
Reply
#3

Ok I have a slight problem. It isn't activating the first timer again when object surfing isn't detected. It just activates timer 1 and then timer 2 and gets stuck. Why is that?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)