SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 26/02/2014, 07:51 PM   #1
Phil_Cutcliffe
Huge Clucker
 
Phil_Cutcliffe's Avatar
 
Join Date: Dec 2011
Location: United Kingdom, London
Posts: 337
Reputation: 7
Default Speed up the update time for dynamic objects?

As the title sais. How do I do that?
Phil_Cutcliffe is offline   Reply With Quote
Old 26/02/2014, 08:59 PM   #2
davve95
High-roller
 
davve95's Avatar
 
Join Date: Nov 2009
Location: Sweden
Posts: 3,138
Reputation: 234
Default Re: Speed up the update time for dynamic objects?

Do you mean draw distance?.

Then you can try to increase it.
davve95 is offline   Reply With Quote
Old 26/02/2014, 09:05 PM   #3
Aerotactics
High-roller
 
Aerotactics's Avatar
 
Join Date: Jun 2013
Location: return 0;
Posts: 1,083
Reputation: 112
Default Re: Speed up the update time for dynamic objects?

If you're using a streamer, and your objects are floors, change them to CreateObject so you don't fall through them. Your topic is pretty vague, though. I suggest telling us the specific issue you're having.
Aerotactics is offline   Reply With Quote
Old 26/02/2014, 09:59 PM   #4
Phil_Cutcliffe
Huge Clucker
 
Phil_Cutcliffe's Avatar
 
Join Date: Dec 2011
Location: United Kingdom, London
Posts: 337
Reputation: 7
Default Re: Speed up the update time for dynamic objects?

Quote:
Originally Posted by Aerotactics View Post
If you're using a streamer, and your objects are floors, change them to CreateObject so you don't fall through them. Your topic is pretty vague, though. I suggest telling us the specific issue you're having.
Ok basically OnPlayerEditDynamicObject does not update the object position quick enough. I tried upping the speed the object moves to a really high value. This did not solve my issue. I need it to get the correct updated position of the object as quick as I'm moving it so that I can detect if a player is surfing the object or not. Here's my code.

pawn Code:
new SurfObject[MAX_PLAYERS];
new Float:FirstPosX[MAX_PLAYERS],Float:FirstPosY[MAX_PLAYERS],Float:FirstPosZ[MAX_PLAYERS];
new Float:FirstOPosX[MAX_PLAYERS],Float:FirstOPosY[MAX_PLAYERS],Float:FirstOPosZ[MAX_PLAYERS];
new Float:FirstDistance[MAX_PLAYERS];
new Float:SecondPosX[MAX_PLAYERS],Float:SecondPosY[MAX_PLAYERS],Float:SecondPosZ[MAX_PLAYERS];
new Float:SecondOPosX[MAX_PLAYERS],Float:SecondOPosY[MAX_PLAYERS],Float:SecondOPosZ[MAX_PLAYERS];
new Float:SecondDistance[MAX_PLAYERS];
new SurfDetect[MAX_PLAYERS];
new SurfDetect2[MAX_PLAYERS];
new SurfDetectActive[MAX_PLAYERS];

pawn Code:
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
    if(!IsValidDynamicObject(objectid)) return 0;
    MoveDynamicObject(objectid, x, y, z, 10000000, rx, ry, rz);
    if(SurfDetectActive[playerid] == 0)
    {
        SurfObject[playerid] = objectid;
        SurfDetect[playerid] = SetTimerEx("FirstSurfCheck", 1000, false, "i", playerid);
        SurfDetectActive[playerid] = 1;
        SendClientMessage(playerid, COLOR_YELLOW, "Edit has activated timer 1");
    }
    if(response == EDIT_RESPONSE_FINAL)
    {
        for(new i; i < sizeof(ObjectInfo); i++)
        {
            if(ObjectInfo[i][oCreated] == 0 && EditingObject[playerid] == -1)
            {
                new string[128];
                ObjectInfo[i][oVW] = GetPlayerVirtualWorld(playerid);
                ObjectInfo[i][oINT] = GetPlayerInterior(playerid);
                ObjectInfo[i][oX] = x;
                ObjectInfo[i][oY] = y;
                ObjectInfo[i][oZ] = z;
                ObjectInfo[i][oRX] = rx;
                ObjectInfo[i][oRY] = ry;
                ObjectInfo[i][oRZ] = rz;
                ObjectInfo[i][oCreated] = 1;
                SaveObjects();
                format(string, sizeof(string), "[OBJECT CREATE] ID %d | Name %s | SAVED", i, ObjectInfo[i][oName]);
                SendClientMessage(playerid, COLOR_ORANGE, string);
                DestroyDynamicObject(ObjectInfo[i][oObject]);
                ObjectInfo[i][oObject] = AddDynamicObject(ObjectInfo[i][oModel],ObjectInfo[i][oX],ObjectInfo[i][oY],ObjectInfo[i][oZ],ObjectInfo[i][oRX],ObjectInfo[i][oRY],ObjectInfo[i][oRZ],ObjectInfo[i][oVW],ObjectInfo[i][oINT], -1, 200.0);
                if(ObjectInfo[i][oChair] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $400 for the chair");
                    GivePlayerCash(playerid, -400);
                }
                if(ObjectInfo[i][oBed] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $450 for the bed");
                    GivePlayerCash(playerid, -450);
                }
                if(ObjectInfo[i][oTable] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $150 for the table");
                    GivePlayerCash(playerid, -150);
                }
                if(ObjectInfo[i][oElectronic] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $500 for the electronics");
                    GivePlayerCash(playerid, -500);
                }
                if(ObjectInfo[i][oCabinet] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $250 for the cabinet");
                    GivePlayerCash(playerid, -250);
                }
                if(ObjectInfo[i][oKitchen] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $300 for the kitchen furniture");
                    GivePlayerCash(playerid, -300);
                }
                if(ObjectInfo[i][oPicture] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $80 for the picture");
                    GivePlayerCash(playerid, -80);
                }
                if(ObjectInfo[i][oDoor] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $200 for the door");
                    GivePlayerCash(playerid, -200);
                }
                if(ObjectInfo[i][oSafe] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $2000 for the safe");
                    GivePlayerCash(playerid, -2000);
                }
                if(ObjectInfo[i][oBath] == 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "You were charged $250 for the bathroom furniture");
                    GivePlayerCash(playerid, -250);
                }
                EditMode[playerid] = 0;
                SurfObject[playerid] = 0;
                SurfDetectActive[playerid] = 0;
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                return 1;
            }
            if(ObjectInfo[i][oCreated] == 1 && EditingObject[playerid] == i)
            {
                new string[128];
                ObjectInfo[i][oVW] = GetPlayerVirtualWorld(playerid);
                ObjectInfo[i][oINT] = GetPlayerInterior(playerid);
                ObjectInfo[i][oX] = x;
                ObjectInfo[i][oY] = y;
                ObjectInfo[i][oZ] = z;
                ObjectInfo[i][oRX] = rx;
                ObjectInfo[i][oRY] = ry;
                ObjectInfo[i][oRZ] = rz;
                ObjectInfo[i][oCreated] = 1;
                SaveObjects();
                format(string, sizeof(string), "[OBJECT EDIT] ID %d | Name %s | SAVED", i, ObjectInfo[i][oName]);
                SendClientMessage(playerid, COLOR_ORANGE, string);
                DestroyDynamicObject(ObjectInfo[i][oObject]);
                ObjectInfo[i][oObject] = AddDynamicObject(ObjectInfo[i][oModel],ObjectInfo[i][oX],ObjectInfo[i][oY],ObjectInfo[i][oZ],ObjectInfo[i][oRX],ObjectInfo[i][oRY],ObjectInfo[i][oRZ],ObjectInfo[i][oVW],ObjectInfo[i][oINT], -1, 200.0);
                EditingObject[playerid] = -1;
                EditMode[playerid] = 0;
                SurfObject[playerid] = 0;
                SurfDetectActive[playerid] = 0;
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                return 1;
            }
        }
    }
    if(response == EDIT_RESPONSE_CANCEL)
    {
        for(new i; i < sizeof(ObjectInfo); i++)
        {
            if(ObjectInfo[i][oCreated] == 0 && EditingObject[playerid] == -1)
            {
                DestroyDynamicObject(ObjectInfo[i][oObject]);
                SendClientMessage(playerid, COLOR_ORANGE, "[OBJECT CREATE] - Cancelled");
                ObjectInfo[i][oModel] = 0;
                ObjectInfo[i][oObject] = 0;
                ObjectInfo[i][oChair] = 0;
                ObjectInfo[i][oBed] = 0;
                ObjectInfo[i][oTable] = 0;
                ObjectInfo[i][oElectronic] = 0;
                ObjectInfo[i][oCabinet] = 0;
                ObjectInfo[i][oKitchen] = 0;
                ObjectInfo[i][oPicture] = 0;
                ObjectInfo[i][oDoor] = 0;
                ObjectInfo[i][oSafe] = 0;
                strdel(ObjectInfo[i][oName], 0, 20);
                EditMode[playerid] = 0;
                SurfObject[playerid] = 0;
                SurfDetectActive[playerid] = 0;
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                return 1;
            }
            if(ObjectInfo[i][oCreated] == 1 && EditingObject[playerid] == i)
            {
                DestroyDynamicObject(ObjectInfo[i][oObject]);
                ObjectInfo[i][oObject] = AddDynamicObject(ObjectInfo[i][oModel],ObjectInfo[i][oX],ObjectInfo[i][oY],ObjectInfo[i][oZ],ObjectInfo[i][oRX],ObjectInfo[i][oRY],ObjectInfo[i][oRZ],ObjectInfo[i][oVW],ObjectInfo[i][oINT], -1, 200.0);
                SendClientMessage(playerid, COLOR_ORANGE, "[OBJECT EDIT] - Cancelled");
                EditingObject[playerid] = -1;
                EditMode[playerid] = 0;
                SurfObject[playerid] = 0;
                SurfDetectActive[playerid] = 0;
                KillTimer(SurfDetect[playerid]);
                KillTimer(SurfDetect2[playerid]);
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                return 1;
            }
        }
    }
    return true;
}

pawn Code:
forward FirstSurfCheck(playerid);
public FirstSurfCheck(playerid)
{
    new string[128];
    GetPlayerPos(playerid, FirstPosX[playerid], FirstPosY[playerid], FirstPosZ[playerid]);
    GetDynamicObjectPos(SurfObject[playerid], FirstOPosX[playerid], FirstOPosY[playerid], FirstOPosZ[playerid]);
    FirstDistance[playerid] = GetPlayerDistanceFromPoint(playerid, FirstOPosX[playerid], FirstOPosY[playerid], FirstOPosZ[playerid]);
    SurfDetect2[playerid] = SetTimerEx("SecondSurfCheck", 1000, false, "i", playerid);
    SendClientMessage(playerid, COLOR_YELLOW, "Timer 1 is active");
    format(string, sizeof(string), "Distance 1 = %f", FirstDistance[playerid]);
    SendClientMessage(playerid, COLOR_ORANGE, string);
}

forward SecondSurfCheck(playerid);
public SecondSurfCheck(playerid)
{
    new string[128];
    GetPlayerPos(playerid, SecondPosX[playerid], SecondPosY[playerid], SecondPosZ[playerid]);
    GetDynamicObjectPos(SurfObject[playerid], SecondOPosX[playerid], SecondOPosY[playerid], SecondOPosZ[playerid]);
    SecondDistance[playerid] = GetPlayerDistanceFromPoint(playerid, SecondOPosX[playerid], SecondOPosY[playerid], SecondOPosZ[playerid]);
    SendClientMessage(playerid, COLOR_YELLOW, "Timer 2 is active");
    format(string, sizeof(string), "Distance 2 = %f", SecondDistance[playerid]);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    if(SecondDistance[playerid] == FirstDistance[playerid])
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Distances matched");
        if(SecondPosX[playerid] != FirstPosX[playerid] || SecondPosY[playerid] != FirstPosY[playerid] || SecondPosZ[playerid] != FirstPosZ[playerid])
        {
            SendClientMessage(playerid, COLOR_YELLOW, "Player moved aswell");
            if(SecondOPosX[playerid] != FirstOPosX[playerid] || SecondOPosY[playerid] != FirstOPosY[playerid] || SecondOPosZ[playerid] != FirstOPosZ[playerid])
            {
                GameTextForPlayer(playerid, "~r~OBJECT SURFING DETECTED", 3000, 5);
                for(new i = 0; i < sizeof(HouseInfo); i++)
                {
                    if(GetPlayerVirtualWorld(playerid) == HouseInfo[i][EnterWorld] && GetPlayerInterior(playerid) == HouseInfo[i][EnterInterior])
                    {
                        SendClientMessage(playerid, COLOR_YELLOW, "Timer 2 has detected surfing");
                        SetPlayerPos(playerid, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]);
                        SetTimerEx("CancelEditForPlayer", 1000, false, "i", playerid);
                        KillTimer(SurfDetect[playerid]);
                        KillTimer(SurfDetect2[playerid]);
                    }
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_YELLOW, "Timer 2 did not detect surfing");
                FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
                FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
                FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
                FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
                FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
                FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
                FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
                SurfDetect[playerid] = SetTimerEx("FirstSurfCheck", 1000, false, "i", playerid);
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_YELLOW, "Timer 2 did not detect surfing");
            FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
            FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
            FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
            FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
            FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
            FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
            FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
            SurfDetect[playerid] = SetTimerEx("FirstSurfCheck", 1000, false, "i", playerid);
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Timer 2 did not detect surfing");
        FirstPosX[playerid] = 0; SecondPosX[playerid] = 0;
        FirstPosY[playerid] = 0; SecondPosY[playerid] = 0;
        FirstPosZ[playerid] = 0; SecondPosZ[playerid] = 0;
        FirstOPosX[playerid] = 0; SecondOPosX[playerid] = 0;
        FirstOPosY[playerid] = 0; SecondOPosY[playerid] = 0;
        FirstOPosZ[playerid] = 0; SecondOPosZ[playerid] = 0;
        FirstDistance[playerid] = 0; SecondDistance[playerid] = 0;
        SurfDetect[playerid] = SetTimerEx("FirstSurfCheck", 1000, false, "i", playerid);
    }
}

forward CancelEditForPlayer(playerid);
public CancelEditForPlayer(playerid)
{
    SendClientMessage(playerid, COLOR_YELLOW, "Timer 2 has cancelled editing for player");
    CancelEdit(playerid);
}

It also gets stuck aswell if I move the object too fast it doesn't update the position. Really annoying. I'm sure this must be the update speed? Or the tickrate or something? I just don't know how to change it.
Phil_Cutcliffe is offline   Reply With Quote
Old 26/02/2014, 10:02 PM   #5
Aerotactics
High-roller
 
Aerotactics's Avatar
 
Join Date: Jun 2013
Location: return 0;
Posts: 1,083
Reputation: 112
Default Re: Speed up the update time for dynamic objects?

Quote:
Originally Posted by Phil_Cutcliffe View Post
Ok basically OnPlayerEditDynamicObject does not update the object position quick enough. I tried upping the speed the object moves to a really high value. This did not solve my issue. I need it to get the correct updated position of the object as quick as I'm moving it so that I can detect if a player is surfing the object or not. Here's my code.

(removed code to save space)

It also gets stuck aswell if I move the object too fast it doesn't update the position. Really annoying. I'm sure this must be the update speed? Or the tickrate or something? I just don't know how to change it.
THATS what your topic should have been. Don't be so vague when posting an issue here haha. Replace the thread topic with THAT post, and someone should be able to answer your issue with better results. Or just create a new thread.
Aerotactics is offline   Reply With Quote
Old 26/02/2014, 10:06 PM   #6
Phil_Cutcliffe
Huge Clucker
 
Phil_Cutcliffe's Avatar
 
Join Date: Dec 2011
Location: United Kingdom, London
Posts: 337
Reputation: 7
Default Re: Speed up the update time for dynamic objects?

Quote:
Originally Posted by Aerotactics View Post
THATS what your topic should have been. Don't be so vague when posting an issue here haha. Replace the thread topic with THAT post, and someone should be able to answer your issue with better results. Or just create a new thread.
So you have no idea? x(

Man this is so frustrating haha!
Phil_Cutcliffe is offline   Reply With Quote
Old 26/02/2014, 10:08 PM   #7
Aerotactics
High-roller
 
Aerotactics's Avatar
 
Join Date: Jun 2013
Location: return 0;
Posts: 1,083
Reputation: 112
Default Re: Speed up the update time for dynamic objects?

Quote:
Originally Posted by Phil_Cutcliffe View Post
So you have no idea? x(

Man this is so frustrating haha!
Nope, I don't use in-game object editors lol
Aerotactics is offline   Reply With Quote
Old 26/02/2014, 10:11 PM   #8
Phil_Cutcliffe
Huge Clucker
 
Phil_Cutcliffe's Avatar
 
Join Date: Dec 2011
Location: United Kingdom, London
Posts: 337
Reputation: 7
Default Re: Speed up the update time for dynamic objects?

Quote:
Originally Posted by Aerotactics View Post
Nope, I don't use in-game object editors lol
Well that sucks haha! (The fact you can't help me) I really need to fix this it's holding me back majorly. This damn furniture system is proving to be a real pain in the ass! xD

EDIT: Is there a way to put an object in a "no clip" state?
Phil_Cutcliffe is offline   Reply With Quote
Old 27/02/2014, 06:11 AM   #9
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,324
Reputation: 652
Default Re: Speed up the update time for dynamic objects?

Please refer to my comment on your other topic for the same issue (Dont double post please.)

http://forum.sa-mp.com/showthread.php?t=497451
Crayder 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
[FilterScript] In Game Speed Break Maker [xSpeedBreakMaker][Dynamic] XtremeR Filterscripts 59 02/05/2014 12:07 AM
Update a textdraw each X time anou1 Scripting Help 3 12/02/2014 03:50 PM
[FilterScript] Shrewd Time Weather System V1 (Update time and weather automatically) =WoR=Varth Filterscripts 9 04/02/2014 10:29 PM
[FilterScript] Dynamic Apartment System v0.2 (UPDATE 7.3.2012) Maki187 Filterscripts 29 11/12/2012 04:28 PM


All times are GMT. The time now is 04:07 AM.


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