[Ajuda] Setar Player no OBJETO
#1

PHP Code:
/*  surfboard.inc
 *
 *  © Copyright 2010, Emilijo "Correlli" Lovrich
 *
 *  Credits: - ****** for foreach & GetXYInFrontOfPlayer functions & ZeeX for zcmd command processor.
*/
#if defined _surfboard_included
    #endinput
#endif
#define _surfboard_included
#if !defined _samp_included
    #error "You'll need to include the a_samp.inc include file before the surfboard.inc file!"
#endif
/* ----- */
#if !defined MAX_SURFBOARDS
    #define MAX_SURFBOARDS (5)
#endif
#if !defined MAX_SURFBOARD_SPEED
    #define MAX_SURFBOARD_SPEED (14.0)
#endif
#if !defined INVALID_SURFBOARD_ID
    #define INVALID_SURFBOARD_ID (-1)
#endif
/* ----- */
static
        
bool:gOPF[3] = false;
/* ----- */
enum dataSurfboard
{
    
modelID,
    
objectID,
    
Float:speed,
    
Float:position[7]
}
new
        
surfboardID INVALID_SURFBOARD_IDsurfboardData[MAX_SURFBOARDS][dataSurfboard],
        
Float:surfboardGoTo[MAX_SURFBOARDS][3], bool:firstSurfboard falsesbTimer;
/* ----- */
stock CreateSurfboard(modelidFloat:xFloat:yFloat:zFloat:rxFloat:ryFloat:rz 0.0)
{
    
surfboardID++;
    if(
surfboardID == MAX_SURFBOARDS)
    {
        
printf("Limit of surfboards exceeded. Open the surfboard.inc and change the \"MAX_SURFBOARDS\" define to bigger value if you want to have more surfboards.\
                \nDon't forget that object limit in the current SA:MP version (0.3b) is 400, so it's a good thing to use an object-streamer if you're having many surfboards on server."
);
        
surfboardID--;
        return 
INVALID_SURFBOARD_ID;
    }
    new
            
toSurfboardID GetFreeSurfboardID();
    if(
toSurfboardID == INVALID_SURFBOARD_ID)
    {
        print(
"Error: There are no surfboard IDs free.");
        
surfboardID--;
        return 
INVALID_SURFBOARD_ID;
    }
    if(
modelid || modelid 3)
    {
        
printf("Invalid model-ID at function \"CreateSurfboard\". Valid model-IDs are 1, 2 and 3.");
        
surfboardID--;
        return 
INVALID_SURFBOARD_ID;
    }
    
surfboardData[toSurfboardID][modelID] = modelid;
    
surfboardData[toSurfboardID][position][0] = x;
    
surfboardData[toSurfboardID][position][1] = y;
    
surfboardData[toSurfboardID][position][2] = z;
    
surfboardData[toSurfboardID][position][3] = rx;
    
surfboardData[toSurfboardID][position][4] = ry;
    
surfboardData[toSurfboardID][position][5] = rz;
    
surfboardData[toSurfboardID][position][6] = rz;
    
surfboardData[toSurfboardID][speed] = 0.0;
    
surfboardData[toSurfboardID][objectID] = CreateObject(2403 modelidxyzrxryrz);
    if(!
firstSurfboard)
    {
        
firstSurfboard true;
        
sbTimer SetTimer("surfboard_Timer"1000true);
    }
    return 
toSurfboardID;
}
stock DestroySurfboard(sbid)
{
    if(
IsSurfboardCreated(sbid))
    {
        
surfboardID--;
        
surfboardData[sbid][modelID] = 0;
        
surfboardData[sbid][position][0] = 0.0;
        
surfboardData[sbid][position][1] = 0.0;
        
surfboardData[sbid][position][2] = 0.0;
        
surfboardData[sbid][position][3] = 0.0;
        
surfboardData[sbid][position][4] = 0.0;
        
surfboardData[sbid][position][5] = 0.0;
        
surfboardData[sbid][position][6] = 0.0;
        
surfboardData[sbid][speed] = 0.0;
        
DestroyObject(surfboardData[sbid][objectID]);
        if(
surfboardID == INVALID_SURFBOARD_ID)
        {
            
firstSurfboard false;
            
KillTimer(sbTimer);
        }
        foreach(
Playeru)
        {
            if((
GetPVarInt(u"surfboardID") - 1) == sbid)
            {
                
SetPVarInt(u"surfboardID"0);
                
ClearAnimations(u);
                
SendClientMessage(u0xFFFFFFFF"Surfing stopped - surfboard was deleted by the script.");
                break;
            }
        }
        return 
true;
    }
    return 
false;
}
stock IsSurfboardCreated(sbid)
{
    if(
surfboardData[sbid][modelID]) return true;
    return 
false;
}
stock GetNumberOfSurfboards() return surfboardID;
stock GetFreeSurfboardID()
{
    new
            
sbid INVALID_SURFBOARD_ID;
    for(new 
0MAX_SURFBOARDSa++)
    {
        if(!
IsSurfboardCreated(a))
        {
            
sbid a;
            break;
        }
    }
    return 
sbid;
}
stock StopSurfboard(sbid)
{
    if(!
IsSurfboardCreated(sbid)) return false;
    
surfboardData[sbid][speed] = 0.0;
    
StopObject(surfboardData[sbid][objectID]);
    return 
true;
}
stock RespawnSurfboard(sbid)
{
    if(!
IsSurfboardCreated(sbid)) return false;
    
DestroyObject(surfboardData[sbid][objectID]);
    
surfboardData[sbid][position][5] = surfboardData[sbid][position][6];
    
surfboardData[sbid][objectID] = CreateObject(2403 surfboardData[sbid][modelID], surfboardData[sbid][position][0], surfboardData[sbid][position][1], surfboardData[sbid][position][2], surfboardData[sbid][position][3], surfboardData[sbid][position][4], surfboardData[sbid][position][5]);
    return 
true;
}
stock SetSurfboardSpeed(sbidFloat:surfspeed MAX_SURFBOARD_SPEED)
{
    if(!
IsSurfboardCreated(sbid)) return false;
    if(
surfspeed MAX_SURFBOARD_SPEEDsurfboardData[sbid][speed] = MAX_SURFBOARD_SPEED;
    else 
surfboardData[sbid][speed] = surfspeed;
    return 
true;
}
stock IsPlayerAtSurfboard(playeridsbid)
{
    new
            
Float:pos[3];
    
GetObjectPos(surfboardData[sbid][objectID], pos[0], pos[1], pos[2]);
    if(
IsPlayerInRangeOfPoint(playerid1.5pos[0], pos[1], pos[2])) return true;
    return 
false;
}
stock IsPlayerAtAnySurfboard(playerid)
{
    new
            
0;
    for(
0MAX_SURFBOARDSa++)
    {
        if(
IsPlayerAtSurfboard(playerida)) return a;
    }
    return 
INVALID_SURFBOARD_ID;
}
stock IsSurfboardOccupied(sbid)
{
    if(!
IsSurfboardCreated(sbid)) return INVALID_PLAYER_ID;
    foreach(
Playeru)
    {
        if((
GetPVarInt(u"surfboardID") - 1) == sbid) return u;
    }
    return 
INVALID_PLAYER_ID;
}
/* ----- */
stock GetXYInFrontOfPlayerOnSB(playerid, &Float:x, &Float:yFloat:distance)
{
    new
            
Float:angle;
    
GetPlayerPos(playeridxyangle);
    
GetPlayerFacingAngle(playeridangle);
    
+= (distance floatsin(-angle 270.0degrees));
    
+= (distance floatcos(-angle 270.0degrees));
}
/* ----- */
forward surfboard_Timer();
public 
surfboard_Timer()
{
    foreach(
Playeru)
    {
        new
                
sbid GetPVarInt(u"surfboardID") - 1;
        if(
sbid != INVALID_SURFBOARD_ID)
        {
            if(!
IsPlayerAtSurfboard(usbid))
            {
                
StopSurfboard(sbid);
                
RespawnSurfboard(sbid);
                
SetPVarInt(u"surfboardID"0);
                
ClearAnimations(u);
                
SendClientMessage(u0xFFFFFFFF"Surfing stopped - surfboard is re-spawned.");
            }
        }
    }
    return 
true;
}
/* ----- */
command(surfplayeridparams[])
{
    new
            
Float:objPos[3];
    if(!
GetPVarInt(playerid"surfboardID"))
    {
        new
                
sbid IsPlayerAtAnySurfboard(playerid); 
        if(
sbid != INVALID_SURFBOARD_ID)
        {
            new
                    
isOccupied IsSurfboardOccupied(sbid);
            if(
isOccupied != INVALID_PLAYER_ID) return SendClientMessage(playerid0xFFFFFFFF"(surfing) Someone is already surfing on this surfboard!");
            
SetPVarInt(playerid"surfboardID"sbid 1);
            
GetObjectPos(surfboardData[sbid][objectID], objPos[0], objPos[1], objPos[2]);
            
SetPlayerPos(playeridobjPos[0], objPos[1], objPos[2] + 1.0);
            
SetPlayerFacingAngle(playeridsurfboardData[sbid][position][5] + 270.0); // seta o player pro angulo
            
ApplyAnimation(playerid"BSKTBALL""BBALL_def_loop"4.010000);
            
SendClientMessage(playerid0xFFFFFFFF"Surfing started. Use \"/surf\" command to stop with the surfing.");
        }
        else 
SendClientMessage(playerid0xFFFFFFFF"You're not near any surfboard or you're not close enough to it.");
    }
    else
    {
        
StopSurfboard(GetPVarInt(playerid"surfboardID") - 1);
        
SetPVarInt(playerid"surfboardID"0);
        
ClearAnimations(playerid);
        
SendClientMessage(playerid0xFFFFFFFF"Surfing stopped. Use \"/surf\" command to start with the surfing again.");
    }
    return 
true;
}
/* ----- */
public OnPlayerConnect(playerid)
{
    
ApplyAnimation(playerid"BSKTBALL""null"0.000000);
    if(
gOPF[0]) CallLocalFunction("surfboard_OnPlayerConnect""i"playerid);
    return 
true;
}
#if defined _ALS_OnPlayerConnect
    #undef OnPlayerConnect
#else
    #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect surfboard_OnPlayerConnect
forward surfboard_OnPlayerConnect(playerid);
public 
OnPlayerDisconnect(playeridreason)
{
    new
            
sbid GetPVarInt(playerid"surfboardID") - 1;
    if(
sbid != INVALID_SURFBOARD_ID)
    {
        
StopSurfboard(sbid);
        
RespawnSurfboard(sbid);
    }
    if(
gOPF[1]) CallLocalFunction("surfboard_OnPlayerDisconnect""ii"playeridreason);
    return 
true;
}
#if defined _ALS_OnPlayerDisconnect
    #undef OnPlayerDisconnect
#else
    #define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect surfboard_OnPlayerDisconnect
forward surfboard_OnPlayerDisconnect(playeridreason);
public 
OnPlayerUpdate(playerid)
{
    new
            
sbid GetPVarInt(playerid"surfboardID") - 1;
    if(
sbid != INVALID_SURFBOARD_ID)
    {
        new
                
keys[3], Float:floatVal[4];
        
GetPlayerPos(playeridfloatVal[0], floatVal[1], floatVal[2]);
        
floatVal[3] = surfboardData[sbid][speed];
        
GetPlayerKeys(playeridkeys[0], keys[1], keys[2]);
        
GetXYInFrontOfPlayerOnSB(playeridfloatVal[0], floatVal[1], 90.0);
        
surfboardGoTo[sbid][0] = floatVal[0];
        
surfboardGoTo[sbid][1] = floatVal[1];
        
surfboardGoTo[sbid][2] = surfboardData[sbid][position][2];
        if(
keys[1] == KEY_UP)
        {
            if(
floatVal[3] >= 0.0 && floatVal[3] < MAX_SURFBOARD_SPEEDsurfboardData[sbid][speed] += 0.09;
            if(
floatVal[3] >= MAX_SURFBOARD_SPEEDsurfboardData[sbid][speed] = MAX_SURFBOARD_SPEED;
        }
        else if(
keys[1] == KEY_DOWN)
        {
            if(
floatVal[3] >= 0.0 && floatVal[3] < MAX_SURFBOARD_SPEEDsurfboardData[sbid][speed] -= 0.09;
            if(
floatVal[3] >= MAX_SURFBOARD_SPEEDsurfboardData[sbid][speed] = MAX_SURFBOARD_SPEED;
        }
        if(
keys[2] == KEY_LEFT)
        {
            
surfboardData[sbid][speed] -= 0.01;
            
surfboardData[sbid][position][5] += 1.5;
            
SetObjectRot(surfboardData[sbid][objectID], surfboardData[sbid][position][3], surfboardData[sbid][position][4], surfboardData[sbid][position][5]);
            
SetPlayerFacingAngle(playeridsurfboardData[sbid][position][5] + 270.0);
            
surfboardGoTo[sbid][0] = floatVal[0];
            
surfboardGoTo[sbid][1] = floatVal[1];
            
surfboardGoTo[sbid][2] = surfboardData[sbid][position][2];
        }
        else if(
keys[2] == KEY_RIGHT)
        {
            
surfboardData[sbid][speed] -= 0.01;
            
surfboardData[sbid][position][5] -= 1.5;
            
SetObjectRot(surfboardData[sbid][objectID], surfboardData[sbid][position][3], surfboardData[sbid][position][4], surfboardData[sbid][position][5]);
            
SetPlayerFacingAngle(playeridsurfboardData[sbid][position][5] + 270.0);
            
surfboardGoTo[sbid][0] = floatVal[0];
            
surfboardGoTo[sbid][1] = floatVal[1];
            
surfboardGoTo[sbid][2] = surfboardData[sbid][position][2];
        }
        if(
surfboardData[sbid][speed] > 0.009)
        {
            
surfboardData[sbid][speed] -= 0.009;
            
MoveObject(surfboardData[sbid][objectID], surfboardGoTo[sbid][0], surfboardGoTo[sbid][1], surfboardGoTo[sbid][2], surfboardData[sbid][speed]);
        }
        else 
StopSurfboard(sbid);
        new
                
string[72];
        
format(stringsizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~Speed: ~w~%0.1f ~r~/ ~w~%0.1f"surfboardData[sbid][speed], MAX_SURFBOARD_SPEED);
        
GameTextForPlayer(playeridstring10003);
    }
    if(
gOPF[2]) CallLocalFunction("surfboard_OnPlayerUpdate""i"playerid);
    return 
true;
}
#if defined _ALS_OnPlayerUpdate
    #undef OnPlayerUpdate
#else
    #define _ALS_OnPlayerUpdate
#endif
#define OnPlayerUpdate surfboard_OnPlayerUpdate
forward surfboard_OnPlayerUpdate(playerid);
public 
OnGameModeInit()
{
    
gOPF[0] = (funcidx("surfboard_OnPlayerConnect") != -1);
    
gOPF[1] = (funcidx("surfboard_OnPlayerDisconnect") != -1);
    
gOPF[2] = (funcidx("surfboard_OnPlayerUpdate") != -1);
    
CallLocalFunction("surfboard_OnGameModeInit""");
}
#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#else
    #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit surfboard_OnGameModeInit
forward surfboard_OnGameModeInit(); 
Gostaria de saber qual comando foi Usado pra setar o Player em cima do Objeto.
Reply
#2

PHP Code:
SetPlayerPos(playeridobjPos[0], objPos[1], objPos[2] + 1.0); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)