SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 05/09/2019, 08:14 AM   #1
pedrotvr
Huge Clucker
 
Join Date: Nov 2013
Posts: 403
Reputation: 7
Default Drop an object a little in front

How to drop an object a little in front?

I found this funcion on forum:
Code:
stock GetXYFront(&Float:x, &Float:y, Float:a, Float:distance)
{
    x += distance * floatsin(-a, degrees);
    y += distance * floatcos(-a, degrees);
}
But idk how to use...

I need to if enter on this condition:
Code:
    if(onHands == true) {
        GetXYFront(CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseR], 1.0)
        CadaverObject[cid] = CreateObject(2907, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ]-1, CadaverInfo[cid][corpseR], 0.0, 0.0);;
    }
drop the object some in front (create the object a little in front)
instead of if enter on else, that create the object on plalyer position...


Code:
PlayerDropACadaver(playerid, cid, bool:onHands = false) {
    DestroyObject(CadaverObject[cid]);
    GetPlayerPos(playerid, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ] );
    GetPlayerFacingAngle(playerid, CadaverInfo[cid][corpseR]);
    // [2907]Torso [2908]Head [2906]Arm [2905]Leg
    if(onHands == true) {
        GetXYFront(CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseR], 1.0)
        CadaverObject[cid] = CreateObject(2907, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ]-1, CadaverInfo[cid][corpseR], 0.0, 0.0);;
    }
    else {
        CadaverObject[cid] = CreateObject(2907, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ]-1, CadaverInfo[cid][corpseR], 0.0, 0.0);
    }
    CadaverInfo[cid][corpseStatus] = 0;
    PlayerCadaverInHands[playerid] = 0;
    CadaverInfo[cid][hoursToDestroy] = 3;
}
pedrotvr is offline   Reply With Quote
Old 06/09/2019, 06:04 AM   #2
pedrotvr
Huge Clucker
 
Join Date: Nov 2013
Posts: 403
Reputation: 7
Default Re: Drop an object a little in front

bump
pedrotvr is offline   Reply With Quote
Old 06/09/2019, 11:17 AM   #3
YouShootIDodge
Big Clucker
 
Join Date: May 2019
Posts: 65
Reputation: 14
Default Re: Drop an object a little in front

You will use the GetXY function like this:

Code:
new Float: x, Float: y, Float: a;

GetPlayerFacingAngle (playerid, a);
GetXYFront (x, y, a, 3.0);

// Now the position is stored in the variables x and y. Create that object at the x, y coordinates.
YouShootIDodge is offline   Reply With Quote
Old 08/09/2019, 01:00 AM   #4
pedrotvr
Huge Clucker
 
Join Date: Nov 2013
Posts: 403
Reputation: 7
Default Re: Drop an object a little in front

I tried this:
Code:
    DestroyObject(CadaverObject[cid]);
    GetPlayerPos(playerid, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ] );
    GetPlayerFacingAngle(playerid, CadaverInfo[cid][corpseR]);
    // [2907]Torso [2908]Head [2906]Arm [2905]Leg
    if(onHands == true) {
        GetXYFront(CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseR], 3.0);
    }
    CadaverObject[cid] = CreateObject(2907, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ]-1, CadaverInfo[cid][corpseR], 0.0, 0.0);
    CadaverInfo[cid][corpseStatus] = 0;
    PlayerCadaverInHands[playerid] = 0;
    CadaverInfo[cid][hoursToDestroy] = 3;
But it wont work, the object disaperry when enter on this condition:
Code:
if(onHands == true) {
pedrotvr is offline   Reply With Quote
Old 09/09/2019, 08:39 PM   #5
pedrotvr
Huge Clucker
 
Join Date: Nov 2013
Posts: 403
Reputation: 7
Default Re: Drop an object a little in front

bump
pedrotvr is offline   Reply With Quote
Old 12/09/2019, 06:30 AM   #6
pedrotvr
Huge Clucker
 
Join Date: Nov 2013
Posts: 403
Reputation: 7
Default Re: Drop an object a little in front

bump
pedrotvr is offline   Reply With Quote
Old 12/09/2019, 09:54 AM   #7
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,177
Reputation: 73
Default Re: Drop an object a little in front

where is that object is created?
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Old 13/09/2019, 08:22 AM   #8
pedrotvr
Huge Clucker
 
Join Date: Nov 2013
Posts: 403
Reputation: 7
Default Re: Drop an object a little in front

my bad, i found the problem

getinfront is not working, it is always drop the object on the same player position (it was dropping 2 on the same position)

Code:
stock GetXYFront(&Float:x, &Float:y, Float:a, Float:distance)
{
    x += distance * floatsin(-a, degrees);
    y += distance * floatcos(-a, degrees);
}
Code:
PlayerDropACadaver(playerid, cid, bool:onHands = false) {
    DestroyObject(CadaverObject[cid]);
    GetPlayerPos(playerid, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ] );
    GetPlayerFacingAngle(playerid, CadaverInfo[cid][corpseR]);
    if(onHands == true) {
        new Float: x, Float: y, Float: a;
        GetPlayerFacingAngle(playerid, a);
        GetXYFront(x, y, a, 5.0);
        CadaverInfo[cid][corpseX] = x;
        CadaverInfo[cid][corpseY] = y;
    }
    CadaverObject[cid] = CreateObject(2907, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ]-1, CadaverInfo[cid][corpseR], 0.0, 0.0);
    CadaverInfo[cid][corpseStatus] = 0;
    PlayerCadaverInHands[playerid] = 0;
    CadaverInfo[cid][hoursToDestroy] = 3;
    SetPlayerSpecialAction(playerid, 0);
    itemOnHANDS[playerid] = 0;
}
The function is not working or i'm doing something wrong?
pedrotvr is offline   Reply With Quote
Old 13/09/2019, 11:36 AM   #9
Jonny
Huge Clucker
 
Jonny's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 280
Reputation: 38
Default Re: Drop an object a little in front

Use GetPlayerPos to get x,y before GetXYFront, you're using it on corpse vars but not for x,y

Code:
PlayerDropACadaver(playerid, cid, bool:onHands = false) {
    if(IsValidObject(CadaverObject[cid])) DestroyObject(CadaverObject[cid]);
    new Float: x, Float: y, Float: a;
    GetPlayerPos(playerid,x,y,z);
    GetPlayerFacingAngle(playerid, a);
    if(onHands) GetXYFront(x, y, a, 5.0);
    CadaverInfo[cid][corpseX] = x;
    CadaverInfo[cid][corpseY] = y;
    CadaverInfo[cid][corpseZ] = z;
    CadaverInfo[cid][corpseR] = a;
    CadaverObject[cid] = CreateObject(2907, CadaverInfo[cid][corpseX], CadaverInfo[cid][corpseY], CadaverInfo[cid][corpseZ]-1,         
    CadaverInfo[cid][corpseR], 0.0, 0.0);
    CadaverInfo[cid][corpseStatus] = 0;
    PlayerCadaverInHands[playerid] = 0;
    CadaverInfo[cid][hoursToDestroy] = 3;
    SetPlayerSpecialAction(playerid, 0);
    itemOnHANDS[playerid] = 0;
}
__________________
Jonny is offline   Reply With Quote
Old 16/09/2019, 02:25 PM   #10
Smacky
Big Clucker
 
Smacky's Avatar
 
Join Date: Jan 2011
Posts: 124
Reputation: 9
Default Re: Drop an object a little in front

Just use
Code:
new px,py,pz
GetPlayerPosition(px,py,pz)
CreateDynamicObject(objectid, px,py,pz-0,5, 0,0,0)
Smacky is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get XYZ in front of object? zaibaslr2 Scripting Help 2 30/11/2015 06:15 PM
Is Object in front of player? Hantex. Scripting Help 10 29/06/2014 07:58 AM
Getting XY in front of an object. kadaradam Scripting Help 3 23/01/2014 10:36 AM
How to....Object in front of player iFiras Scripting Help 11 08/12/2013 05:14 PM
Is player in front of an object? Programie Scripting Help 1 17/05/2012 04:59 PM


All times are GMT. The time now is 11:14 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.