SA-MP Forums Archive
Little Help +Rep - 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: Little Help +Rep (/showthread.php?tid=581473)



Little Help +Rep - Mouiz - 13.07.2015

I have a balloon system by the balloon spawns at different location,can anyone help to change the balloon spawn location to the player location:

PHP код:
CMD:balloon(playerid,params[])
{
    new 
Float:x,Float:y,Float:z;
    
GetPlayerPos(playerid, x, y, z);
    
DestroyObject(Balloon);
    
DestroyObject(Fire);
    
DestroyObject(Fire1);
    
PlayerIn[playerid][BalloonPlayer] = 0;
    
Balloon = CreateObject(19335, 836.08, -2000.51, 13.60,   0.00, 0.00, 0.00);
    
Fire = CreateObject(18692, 0,0,0,   0.00, 0.00, 0.00);
    
Fire1 = CreateObject(18692, 0,0,0,   0.00, 0.00, 0.00);
    
AttachObjectToObject(Fire, Balloon, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1);
    
AttachObjectToObject(Fire1, Balloon, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 1);
    
SendClientMessage(playerid,GREEN,"Enter the following keys to control the hot air balloon");
    
SendClientMessage(playerid,GREEN,"Alt+Y (Move Balloon Up)");
    
SendClientMessage(playerid,GREEN,"Alt+N (Move Balloon Down)");
    
SendClientMessage(playerid,GREEN,"F+Y (Move Balloon Forward)");
    
SendClientMessage(playerid,GREEN,"F+N (Move Balloon Back)");
    
SendClientMessage(playerid,GREEN,"C+Y (Move Balloon Right)");
    
SendClientMessage(playerid,GREEN,"C+N (Move Balloon Left)");
    
PlayerIn[playerid][BalloonPlayer] = 1;
    return 
1;
} 



Re: Little Help +Rep - Virtual1ty - 13.07.2015

Quote:
Originally Posted by Mouiz
Посмотреть сообщение
I have a balloon system by the balloon spawns at different location,can anyone help to change the balloon spawn location to the player location:

[code...]
Yeah, sure, but keep in mind that the current system you have would only spawn 1 balloon at a time, and if another player spawns a balloon (by typing the command) and you just happen to be flying in one, it would get destroyed and you will drop.

Here's how it should look like:
PHP код:
new
    
pBalloonObj[MAX_PLAYERS][3] // 0 - Balloon, 1 - Fire1, 2 - Fire2
;
CMD:balloon(playerid,params[])
{
    new 
Float:x, Float:y, Float:z, Float:a;
    
GetPlayerPos(playerid, x, y, z);
    
GetPlayerFacingAngle(playerid, a);
    if (
PlayerIn[playerid][BalloonPlayer])
    {
        if (
IsValidObject(pBalloonObj[playerid][0]))
        {
            
DestroyObject(pBalloonObj[playerid][0]);
            
DestroyObject(pBalloonObj[playerid][1]);
            
DestroyObject(pBalloonObj[playerid][2]);
        }
        
PlayerIn[playerid][BalloonPlayer] = 0;
    }
    
// Spawn the balloon 2.0 m further away in the direction the player is looking at
    
x += 2.0 * floatsin(-a, degrees);
    
y += 2.0 * floatcos(-a, degrees);
    
pBalloonObj[playerid][0] = CreateObject(19335, x, y, z, 0.0, 0.0, 0.0);
    
pBalloonObj[playerid][1] = CreateObject(18692, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
    
pBalloonObj[playerid][2] = CreateObject(18692, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
    
AttachObjectToObject(pBalloonObj[playerid][1], Balloon, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1);
    
AttachObjectToObject(pBalloonObj[playerid][2], Balloon, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 1);
    
SendClientMessage(playerid,GREEN,"Enter the following keys to control the hot air balloon");
    
SendClientMessage(playerid,GREEN,"Alt+Y (Move Balloon Up)");
    
SendClientMessage(playerid,GREEN,"Alt+N (Move Balloon Down)");
    
SendClientMessage(playerid,GREEN,"F+Y (Move Balloon Forward)");
    
SendClientMessage(playerid,GREEN,"F+N (Move Balloon Back)");
    
SendClientMessage(playerid,GREEN,"C+Y (Move Balloon Right)");
    
SendClientMessage(playerid,GREEN,"C+N (Move Balloon Left)");
    
PlayerIn[playerid][BalloonPlayer] = 1;
    return 
1;
} 
Edit: Made minor changes.


Re: Little Help +Rep - Vicky69 - 13.07.2015

Oops Imma DUMB (Removed as it was incorrect code)


Re: Little Help +Rep - SoFahim - 13.07.2015

You just need to edit this line
PHP код:
Balloon = CreateObject(19335, 836.08, -2000.51, 13.60,   0.00, 0.00, 0.00); 
try to take some help from here:
PHP код:
new Float:x, Float:y, Float:z, Float:a;
        
GetPlayerPos(playerid, x, y, z);
        
GetPlayerFacingAngle(playerid, a);
        
        
x += (2 * floatsin(-a, degrees));
            
y += (2 * floatcos(-a, degrees));
        
Rocket[playerid] = CreateDynamicObject(19335, x, y, z, 0, 90, 0);
        
      
Balloon = CreateDynamicObject(18716, x, y, z - 4, 0, 0, 0); 



Re: Little Help +Rep - Mouiz - 13.07.2015

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Yeah, sure, but keep in mind that the current system you have would only spawn 1 balloon at a time, and if another player spawns a balloon (by typing the command) and you just happen to be flying in one, it would get destroyed and you will drop.

Here's how it should look like:
PHP код:
new
    
pBaloonObj[MAX_PLAYERS][3] // 0 - Baloon, 1 - Fire1, 2 - Fire2
;
CMD:balloon(playerid,params[])
{
    new 
Float:x, Float:y, Float:z, Float:a;
    
GetPlayerPos(playerid, x, y, z);
    
GetPlayerFacingAngle(playerid, a);
    if (
PlayerIn[playerid][BalloonPlayer])
    {
        if (
IsValidObject(pBaloonObj[playerid][0]))
        {
            
DestroyObject(pBaloonObj[playerid][0]);
            
DestroyObject(pBaloonObj[playerid][1]);
            
DestroyObject(pBaloonObj[playerid][2]);
        }
        
PlayerIn[playerid][BalloonPlayer] = 0;
    }
    
// Spawn the balloon 2.0 m further away in the direction the player is looking at
    
x += 2.0 * floatsin(-a, degrees);
    
y += 2.0 * floatcos(-a, degrees);
    
pBaloonObj[playerid][0] = CreateObject(19335, x, y, z, 0.0, 0.0, 0.0);
    
pBaloonObj[playerid][1] = CreateObject(18692, 0.0, 0,0, 0.0, 0.0, 0.0);
    
pBaloonObj[playerid][2] = CreateObject(18692, 0.0, 0,0, 0.0, 0.0, 0.0);
    
AttachObjectToObject(pBaloonObj[playerid][1], Balloon, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1);
    
AttachObjectToObject(pBaloonObj[playerid][2], Balloon, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 1);
    
SendClientMessage(playerid,GREEN,"Enter the following keys to control the hot air balloon");
    
SendClientMessage(playerid,GREEN,"Alt+Y (Move Balloon Up)");
    
SendClientMessage(playerid,GREEN,"Alt+N (Move Balloon Down)");
    
SendClientMessage(playerid,GREEN,"F+Y (Move Balloon Forward)");
    
SendClientMessage(playerid,GREEN,"F+N (Move Balloon Back)");
    
SendClientMessage(playerid,GREEN,"C+Y (Move Balloon Right)");
    
SendClientMessage(playerid,GREEN,"C+N (Move Balloon Left)");
    
PlayerIn[playerid][BalloonPlayer] = 1;
    return 
1;
} 
+Rep


Re: Little Help +Rep - Mouiz - 13.07.2015

but the balloon does not move when i press keys:

PHP код:
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
    if(
PlayerIn[i][BalloonPlayer] == 1)
    {
    new 
Float:X,Float:Y,Float:Z;
    
GetObjectPos(Balloon,X,Y,Z);
    if(
PRESSED(KEY_YES | KEY_WALK)) { TimerUP = SetTimer("MoveBalloonUp",30,1); }
    if(
RELEASED(KEY_YES | KEY_WALK)) { KillTimer(TimerUP); }
    if(
PRESSED(KEY_NO | KEY_WALK)) { TimerDown = SetTimer("MoveBalloonDown",30,1); }
    if(
RELEASED(KEY_NO | KEY_WALK)) { KillTimer(TimerDown); }
    if(
PRESSED(KEY_SECONDARY_ATTACK | KEY_YES)) { TimerForward = SetTimer("MoveBalloonForward",30,1); }
    if(
RELEASED(KEY_SECONDARY_ATTACK | KEY_YES)) { KillTimer(TimerForward); }
    if(
PRESSED(KEY_SECONDARY_ATTACK | KEY_NO)) { TimerBack = SetTimer("MoveBalloonBack",30,1); }
    if(
RELEASED(KEY_SECONDARY_ATTACK | KEY_NO)) { KillTimer(TimerBack); }
    if(
PRESSED(KEY_CROUCH | KEY_YES)) { TimerRight = SetTimer("MoveBalloonRight",30,1); }
    if(
RELEASED(KEY_CROUCH | KEY_YES)) { KillTimer(TimerRight); }
    if(
PRESSED(KEY_CROUCH | KEY_NO)) { TimerLeft = SetTimer("MoveBalloonLeft",30,1); }
    if(
RELEASED(KEY_CROUCH | KEY_NO)) { KillTimer(TimerLeft); }
    }
    } 



Re: Little Help +Rep - SoFahim - 13.07.2015

Quote:
Originally Posted by Mouiz
Посмотреть сообщение
but the balloon does not move when i press keys:

PHP код:
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
    if(
PlayerIn[i][BalloonPlayer] == 1)
    {
    new 
Float:X,Float:Y,Float:Z;
    
GetObjectPos(Balloon,X,Y,Z);
    if(
PRESSED(KEY_YES | KEY_WALK)) { TimerUP = SetTimer("MoveBalloonUp",30,1); }
    if(
RELEASED(KEY_YES | KEY_WALK)) { KillTimer(TimerUP); }
    if(
PRESSED(KEY_NO | KEY_WALK)) { TimerDown = SetTimer("MoveBalloonDown",30,1); }
    if(
RELEASED(KEY_NO | KEY_WALK)) { KillTimer(TimerDown); }
    if(
PRESSED(KEY_SECONDARY_ATTACK | KEY_YES)) { TimerForward = SetTimer("MoveBalloonForward",30,1); }
    if(
RELEASED(KEY_SECONDARY_ATTACK | KEY_YES)) { KillTimer(TimerForward); }
    if(
PRESSED(KEY_SECONDARY_ATTACK | KEY_NO)) { TimerBack = SetTimer("MoveBalloonBack",30,1); }
    if(
RELEASED(KEY_SECONDARY_ATTACK | KEY_NO)) { KillTimer(TimerBack); }
    if(
PRESSED(KEY_CROUCH | KEY_YES)) { TimerRight = SetTimer("MoveBalloonRight",30,1); }
    if(
RELEASED(KEY_CROUCH | KEY_YES)) { KillTimer(TimerRight); }
    if(
PRESSED(KEY_CROUCH | KEY_NO)) { TimerLeft = SetTimer("MoveBalloonLeft",30,1); }
    if(
RELEASED(KEY_CROUCH | KEY_NO)) { KillTimer(TimerLeft); }
    }
    } 
Did you tried mine one?


Re: Little Help +Rep - Virtual1ty - 13.07.2015

Quote:
Originally Posted by Mouiz
Посмотреть сообщение
but the balloon does not move when i press keys:
Code...
Yes, well, that is due to your coding. Try to code it this way: when a player types the /balloon command set a repeating timer for the player with interval of lets say 500ms.
Then, in the timer callback check for keypresses and use MoveObject accordingly. Don't waste server resources by creating many 30ms timers in such short intervals!


Re: Little Help +Rep - Mouiz - 13.07.2015

Now i fixed it by myself by my own way


Re: Little Help +Rep - SoFahim - 13.07.2015

Quote:
Originally Posted by Mouiz
Посмотреть сообщение
Now i fixed it by myself by my own way
Congradz