[FilterScript] Working Cranes
#1

--Update, added in the bug fix provided by wups, haven't tested yet but the files are below.

One of the fun/nic-nak things i always liked about SA were the cranes that actually could be spun around used. Well a few days ago i decided that I would try and make this as a filterscript and here it is.

[ame]http://www.youtube.com/watch?v=mOKMJ3X5USk[/ame]

--Commands
pawn Код:
/newcrane //Will create a new crane about 5 meters in whichever direction the player is facing
/crane //Can only be used in the crane pickup and will place the player in the crane they are near, is also used to exit crane
--Limits
I have currently limited the maximum number of cranes to 20, which will be 40 objects because each crane is two parts (that's what made this possible without spinning crane bases). I will be adding support for Incognito's object streamer in a later release, possibly sometime this week.

--Glitches
When moving the crane around the camera can be a bit jittery and seems to go around on a weird rotation, this is an early release so there will be some glitches.
Reply
#2

Nice
Reply
#3

nice
Reply
#4

Nice Thanks
Reply
#5

oh, sorry guys i forgot to post the vid /facepalm ill get it up in a min
Reply
#6

not bad...
4/5 nice job...
Reply
#7

Quote:
Originally Posted by dowster
Посмотреть сообщение
oh, sorry guys i forgot to post the vid /facepalm ill get it up in a min
We're still waiting for a video or something ...
Reply
#8

you can't do anything exept spin around? not very good but 3/10 for the idea...
Reply
#9

Quote:
Originally Posted by 12kelvin12
Посмотреть сообщение
you can't do anything exept spin around? not very good but 3/10 for the idea...
This is just the base system so far, ill be attaching the magnet once i can get the right offsets for that as its a bit tricky getting everything right. Also, does anyone know how to fix the weird camera or is that just how its going to be? I've tried moving around the code that sets the camera but its still pretty weird.

Quote:
Originally Posted by antonio112
Посмотреть сообщение
We're still waiting for a video or something ...
Sorry it took so long, my internet gave out last night so i couldn't add the link, figures :/
Reply
#10

Once you make it working, I sure will use it somewhere on my server, always loved this idea.
Reply
#11

Update: Just a small update but i set it so when you exit you are set to two meters above the pickup, that way you shouldn\'t be stuck in the ground.
Reply
#12

Found your bug: You don\'t freeze the player when he\'s entering the crane. Plus, i added some float clamping(to 360).
pawn Code:
#include <a_samp>
//#include <streamer>
#include <zcmd>
//Defines
#define MAX_CRANES 20
#define DISTANCE(%1,%2,%3,%4,%5,%6) floatsqroot((%1-%4)*(%1-%4) + (%2-%5)*(%2-%5) + (%3-%6)*(%3-%6))
//Enums
enum CRANE_ENUM
{
    EXIST,
    INUSE,
    Float:CRANE_POS_X,
    Float:CRANE_POS_Y,
    Float:CRANE_POS_Z,
    Float:PICKUP_POS_X,
    Float:PICKUP_POS_Y,
    Float:PICKUP_POS_Z,
    Float:CRANE_ANGLE,
    PICKUP,
    CRANE_TOP
}
//Arrays
new
    cranes[MAX_CRANES][CRANE_ENUM],
    usingCrane[MAX_PLAYERS][2];
public OnFilterScriptInit()
{
    print("
--------------------------------------"
);
    print(" Usable Cranes by dowster");
    print("--------------------------------------
"
);
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{                                                 // Created by Y_Less
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    if (GetPlayerVehicleID(playerid)) { GetVehicleZAngle(GetPlayerVehicleID(playerid), a); }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
stock ShowPos(playerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    new string[128];
    format(string, 512, "Player X: %f, Player Y: %f, Player Z: %f",x, y, z);
    SendClientMessage(playerid, 0x0000FFFF, string);
    return 1;
}
   
stock CreateCrane(row)
{
    CreateObject( 1391, cranes[row][CRANE_POS_X], cranes[row][CRANE_POS_Y], cranes[row][CRANE_POS_Z], 0, 0, 0);
    cranes[row][CRANE_TOP] = CreateObject( 1388, cranes[row][CRANE_POS_X], cranes[row][CRANE_POS_Y], (cranes[row][CRANE_POS_Z]+12.539), 0, 0, 0);
    cranes[row][PICKUP] = CreatePickup( 1317, 23 , cranes[row][PICKUP_POS_X], cranes[row][PICKUP_POS_Y], cranes[row][PICKUP_POS_Z], 0);
    cranes[row][EXIST] = 1;
    //new string[128]; //For Debug Purposes
    //format(string, 512, "Crane X: %f, Crane Y: %f, Crane Z: %f", cranes[row][CRANE_POS_X], cranes[row][CRANE_POS_Y], cranes[row][CRANE_POS_Z]); //For Debug Purposes
    //SendClientMessage(playerid, 0x0000FFFF, string); //For Debug Purposes
    return 1;
}

CMD:newcrane(playerid)
{
    new row = MAX_CRANES;
    for(new i = 0; i < MAX_CRANES; i++)
    {
        if(cranes[i][EXIST] == 0)
        {
            row = i;
        }
    }
    if(row == MAX_CRANES) return SendClientMessage(playerid, 0xFF0000FF, "No crane slots left");
    else
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, cranes[row][PICKUP_POS_X], cranes[row][PICKUP_POS_Y], z);
        GetXYInFrontOfPlayer(playerid, x, y, 6);
        cranes[row][CRANE_POS_Z] = (z + 30);
        cranes[row][PICKUP_POS_Z] =  (z - 1);
        cranes[row][CRANE_POS_Y] = y;
        cranes[row][CRANE_POS_X] = x;
        CreateCrane(row);
        //ShowPos(playerid); //For Debug Purposes
    }
    return 1;
}

CMD:crane(playerid)
{
    if(usingCrane[playerid][0] == 1)
    {
        SetPlayerPos(playerid, cranes[usingCrane[playerid][1]][PICKUP_POS_X], cranes[usingCrane[playerid][1]][PICKUP_POS_Y], (cranes[usingCrane[playerid][1]][PICKUP_POS_Z]+2));
        cranes[usingCrane[playerid][1]][INUSE] = 0;
        TogglePlayerControllable(playerid, 1);
        usingCrane[playerid][0] = 0;
        SetCameraBehindPlayer(playerid);
        return 1;
    }
    new crane = MAX_CRANES;
    for (new i = 0; i < MAX_CRANES; i++)
    {
        if (IsPlayerInRangeOfPoint(playerid, 3, cranes[i][PICKUP_POS_X], cranes[i][PICKUP_POS_Y], cranes[i][PICKUP_POS_Z]))
        {
            crane = i;
        }
    }
    if(crane == MAX_CRANES) return SendClientMessage(playerid, 0xFF0000FF, "You are not in a crane pickup!");
    if(cranes[crane][INUSE] == 1) return SendClientMessage(playerid, 0xFF0000FF, "Someone is using this crane");
    else
    {
        SetPlayerPos(playerid, cranes[crane][CRANE_POS_X], cranes[crane][CRANE_POS_Y], (cranes[crane][CRANE_POS_Z] - 30));
        SetPlayerCameraPos(playerid, cranes[crane][CRANE_POS_X], cranes[crane][CRANE_POS_Y], (cranes[crane][CRANE_POS_Z] + 20));
        TogglePlayerControllable(playerid, false);
        SetPlayerFacingAngle(playerid, cranes[crane][CRANE_ANGLE]);
        new Float:x, Float:y;
        GetXYInFrontOfPlayer(playerid, x, y, 41);
        SetPlayerCameraLookAt(playerid, x, y, (cranes[usingCrane[playerid][1]][CRANE_POS_Z]+12.539));
        usingCrane[playerid][0] = 1;
        usingCrane[playerid][1] = crane;
        cranes[crane][INUSE] = 1;
    }
    return 1;
}
public OnPlayerUpdate(playerid)
{
    if(usingCrane[playerid][0] == 1)
    {
        new Keys,ud,lr;
        GetPlayerKeys(playerid,Keys,ud,lr);
        if(lr < 0)
        {
            new Float:fa;
            GetPlayerFacingAngle(playerid, fa);
            fa+=1.0;
            if(fa >= 360.0) fa-=360.0;
            SetPlayerFacingAngle(playerid, fa);
            cranes[usingCrane[playerid][1]][CRANE_ANGLE] = fa;
            SetObjectRot(cranes[usingCrane[playerid][1]][CRANE_TOP], 0, 0, cranes[usingCrane[playerid][1]][CRANE_ANGLE]);
            new Float:x, Float:y;
            GetXYInFrontOfPlayer(playerid, x, y, 41);
            SetPlayerCameraLookAt(playerid, x, y, (cranes[usingCrane[playerid][1]][CRANE_POS_Z]+12.539));
        }
        else if(lr > 0)
        {
            new Float:fa;
            GetPlayerFacingAngle(playerid, fa);
            fa-=1.0;
            if(fa <= 0.0) fa+=360.0;
            SetPlayerFacingAngle(playerid, fa);
            cranes[usingCrane[playerid][1]][CRANE_ANGLE] = fa;
            SetObjectRot(cranes[usingCrane[playerid][1]][CRANE_TOP], 0, 0, cranes[usingCrane[playerid][1]][CRANE_ANGLE]);
            new Float:x, Float:y;
            GetXYInFrontOfPlayer(playerid, x, y, 41);
            SetPlayerCameraLookAt(playerid, x, y, (cranes[usingCrane[playerid][1]][CRANE_POS_Z]+12.539));
        }
    }
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i = 0; i < MAX_CRANES; i++)
    {
        if(pickupid == cranes[i][PICKUP])
        {
            GameTextForPlayer( playerid, "/crane", 2000, 1);
        }
    }
    return 1;
}
Reply
#13

Its little bugged as i see, You made crane away from the one near Wang try to fix that.. Anyway keep up the good work.
Reply
#14

Nice filterscript I\'ll look into the script for something. Awesome stuff mate, keep it coming.
Reply
#15

Quote:
Originally Posted by berz
View Post
Its little bugged as i see, You made crane away from the one near Wang try to fix that.. Anyway keep up the good work.
Sorry but i don\'t quite explain what you\'re saying?


This filterscript unfortunately does not work with the pre-existing cranes in the game.


--Update, added in the bug fix provided by wups, haven\'t tested yet but the files are in the main post.
Reply
#16

Hahaha.. Sick!
Reply
#17

Easy, But Awesome, Nice work.
Reply
#18

Great job Dowster
Reply
#19

Updates to this may take some time as i kick back into school mode. I\'ll try to get as much coding in as possible.
Reply
#20

It is a rotating object. A working crane will pick something up and move it...
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)