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



OnPlayerEditObject - Ananisiki - 12.03.2014

pawn Код:
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
    if(!IsValidObject(objectid)) return 0;
    MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
    new car = GetPVarInt(playerid, "AttachingTo");
    if(car != 0)
    {
        if(response == EDIT_RESPONSE_FINAL)
    {
    new carslot = FindFreeObjectSlotInCar(car);
    if(carslot == -1)
    {
        SendClientMessage(playerid, COLOR_RED, "You Cannot Add More Objects On This Vehicle.");
        DestroyObject(AttachingObjects[playerid]);
        DeletePVar(playerid, "AttachingTo");
        return 1;
    }
    new Float:ofx, Float:ofy, Float:ofz, Float:ofaz;
    new Float:finalx, Float:finaly;
    new Float:px, Float:py, Float:pz, Float:roz;
    new string[128];
    GetVehiclePos(car, px, py, pz);
    GetVehicleZAngle(car, roz);
    ofx = fX-px;
    ofy = fY-py;
    ofz = fZ-pz;
    ofaz = fRotZ-roz;
    finalx = ofx*floatcos(roz, degrees)+ofy*floatsin(roz, degrees);
    finaly = -ofx*floatsin(roz, degrees)+ofy*floatcos(roz, degrees);
    AttachObjectToVehicle(AttachingObjects[playerid], car, finalx, finaly, ofz, fRotX, fRotY, ofaz);
    AttachedObjects[car][carslot] = AttachingObjects[playerid];
    format(string, sizeof(string), "You Have Attached An Object In Array Slot %d Of Vehicle ID %d.", carslot, car);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
    DeletePVar(playerid, "AttachingTo");
    return 1;
    }
        if(response == EDIT_RESPONSE_CANCEL)
    {
    DestroyObject(AttachingObjects[playerid]);
    DeletePVar(playerid, "AttachingTo");

    new Float:oldX, Float:oldY, Float:oldZ,
            Float:oldRotX, Float:oldRotY, Float:oldRotZ;
    GetObjectPos(objectid, oldX, oldY, oldZ);
    GetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
    if(!playerobject) // If this is a global object, move it for other players
    {
        if(!IsValidObject(objectid)) return;
        MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
    }

    if(response == EDIT_RESPONSE_FINAL)
    {
            // The player clicked on the save icon
            // Do anything here to save the updated object position (and rotation)
    }

    if(response == EDIT_RESPONSE_CANCEL)
    {
            //The player cancelled, so put the object back to it's old position
            if(!playerobject) //Object is not a playerobject
            {
                    SetObjectPos(objectid, oldX, oldY, oldZ);
                    SetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
            }
            else
            {
                    SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ);
                    SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ);
            }
    }
    return 1;
}
        }
    return 0;
}
pawn Код:
(2876) : warning 209: function "Streamer_OnPlayerEditObject" should return a value
(2900) : error 078: function uses both "return" and "return <value>"
(2903) : error 078: function uses both "return" and "return <value>"

//lines

//2876

        if(!IsValidObject(objectid)) return;

//2900

    return 1;

//2903

    return 0;



Re: OnPlayerEditObject - Ananisiki - 12.03.2014

Really need help with this


Re: OnPlayerEditObject - Matess - 12.03.2014

pawn Код:
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
    if(!IsValidObject(objectid)) return 0;
    MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
    new car = GetPVarInt(playerid, "AttachingTo");
    if(car != 0)
    {
        if(response == EDIT_RESPONSE_FINAL)
    {
    new carslot = FindFreeObjectSlotInCar(car);
    if(carslot == -1)
    {
        SendClientMessage(playerid, COLOR_RED, "You Cannot Add More Objects On This Vehicle.");
        DestroyObject(AttachingObjects[playerid]);
        DeletePVar(playerid, "AttachingTo");
        return 1;
    }
    new Float:ofx, Float:ofy, Float:ofz, Float:ofaz;
    new Float:finalx, Float:finaly;
    new Float:px, Float:py, Float:pz, Float:roz;
    new string[128];
    GetVehiclePos(car, px, py, pz);
    GetVehicleZAngle(car, roz);
    ofx = fX-px;
    ofy = fY-py;
    ofz = fZ-pz;
    ofaz = fRotZ-roz;
    finalx = ofx*floatcos(roz, degrees)+ofy*floatsin(roz, degrees);
    finaly = -ofx*floatsin(roz, degrees)+ofy*floatcos(roz, degrees);
    AttachObjectToVehicle(AttachingObjects[playerid], car, finalx, finaly, ofz, fRotX, fRotY, ofaz);
    AttachedObjects[car][carslot] = AttachingObjects[playerid];
    format(string, sizeof(string), "You Have Attached An Object In Array Slot %d Of Vehicle ID %d.", carslot, car);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
    DeletePVar(playerid, "AttachingTo");
    return 1;
    }
        if(response == EDIT_RESPONSE_CANCEL)
    {
    DestroyObject(AttachingObjects[playerid]);
    DeletePVar(playerid, "AttachingTo");

    new Float:oldX, Float:oldY, Float:oldZ,
            Float:oldRotX, Float:oldRotY, Float:oldRotZ;
    GetObjectPos(objectid, oldX, oldY, oldZ);
    GetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
    if(!playerobject) // If this is a global object, move it for other players
    {
        if(!IsValidObject(objectid)) return;
        MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
    }

    if(response == EDIT_RESPONSE_FINAL)
    {
            // The player clicked on the save icon
            // Do anything here to save the updated object position (and rotation)
    }

    if(response == EDIT_RESPONSE_CANCEL)
    {
            //The player cancelled, so put the object back to it's old position
            if(!playerobject) //Object is not a playerobject
            {
                    SetObjectPos(objectid, oldX, oldY, oldZ);
                    SetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
            }
            else
            {
                    SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ);
                    SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ);
            }
    }
}
What now?


Re: OnPlayerEditObject - Ananisiki - 12.03.2014

Got alot of more errors now


Re: OnPlayerEditObject - Matess - 12.03.2014

then add one more } at the end


Re: OnPlayerEditObject - newbienoob - 12.03.2014

Now you see why indentation is important.


Re: OnPlayerEditObject - Ananisiki - 12.03.2014

Quote:
Originally Posted by Matess
Посмотреть сообщение
then add one more } at the end
I have already tried this, it says that i need to return a value.


Re: OnPlayerEditObject - Matess - 12.03.2014

and why is there only return?

pawn Код:
if(!IsValidObject(objectid)) return; //change it to return 0; or 1 IDK



Re: OnPlayerEditObject - Ananisiki - 12.03.2014

If i compile this as a filterscript, only this with nothing else, it compiles without errors..

So i guess there is nothing wrong with that line


Re: OnPlayerEditObject - Pottus - 12.03.2014

MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ); That is a silly idea to even try.