SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 27/05/2020, 03:12 PM   #1
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Problem MovableObjects

Hi guys i just created a barrier with MTA San Andreas program, followed this tuttorial: https://www.youtube.com/watch?v=jY1eECtcOiM, did everything right but the barrier doesent open. The thing is i dont want the barrier to open with command, i want it to open when player comes close to it. Here is the code:
I didint get any warnings or errors in the code, so what could be the problem?
Code:
new lspdbarrier;
Code:
lspdbarrier = CreateObject(968, 1544.7002000, -1630.7998000, 13.1000000, 1.0000000, 89.0000000, 90.0000000); //BARRIER DOWN
Code:
public InitPos()
{
	MoveObject(lspdbarrier, 1544.7002000, -1630.7998000, 13.1000000, 1);//CLOSES THE BARIER
	return 1;
}

public OnPlayerUpdate(playerid)
{
	if(IsPlayerInRangeOfPoint(playerid, 3.0, 1539.7244, -1627.6182, 13.3828)) //PLAYERSRANGETHATISAVED
	{
	    MoveObject(lspdbarrier, 1544.7000000, -1630.8000000, 13.1000000, 1); //BARRIER UP
	    SetTimer("InitPos", 2000, false);//TIMER THAT CLOSE THE BARIER
 	}
 	return 1
XBRSAKOSKYX is offline   Reply With Quote
Old 27/05/2020, 07:04 PM   #2
SharpenBlade
Big Clucker
 
Join Date: May 2020
Posts: 168
Reputation: 21
Default Re: Problem MovableObjects

Seems ok for me, try increasing the distance value to 5.0 or 7.0.
PHP Code:
if(IsPlayerInRangeOfPoint(playerid5.01539.7244, -1627.618213.3828)) //PLAYERSRANGETHATISAVED 
SharpenBlade is offline   Reply With Quote
Old 27/05/2020, 07:18 PM   #3
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Re: Problem MovableObjects

Quote:
Originally Posted by SharpenBlade View Post
Seems ok for me, try increasing the distance value to 5.0 or 7.0.
PHP Code:
if(IsPlayerInRangeOfPoint(playerid5.01539.7244, -1627.618213.3828)) //PLAYERSRANGETHATISAVED 
Nope still doesent work...Should i change range all of them or like this is fine?
Code:
public InitPos()
{
	MoveObject(lspdbarrier, 1544.7000000, -1630.8000000, 13.0000000, 4.0);
	return 1;
}

public OnPlayerUpdate(playerid)
{
	if(IsPlayerInRangeOfPoint(playerid, 7.0, 1539.7244, -1627.6182, 13.3828))
	{
	    MoveObject(lspdbarrier, 1544.7000000, -1630.8000000, 13.0000000, 4.0);
	    SetTimer("InitPos", 2000, false);
 	}
 	return 1;
XBRSAKOSKYX is offline   Reply With Quote
Old 27/05/2020, 07:24 PM   #4
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Re: Problem MovableObjects

Could this be a problem? bcs i have more codes onplayerupdate:
Code:
public OnPlayerUpdate(playerid)
{
	if(IsPlayerInRangeOfPoint(playerid, 7.0, 1539.7244, -1627.6182, 13.3828))
	{
	    MoveObject(lspdbarrier, 1544.7000000, -1630.8000000, 13.0000000, 4.0);
	    SetTimer("InitPos", 2000, false);
 	}
 	
if(Caroff[playerid] == 1)
{
new veh = GetPlayerVehicleID(playerid);
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
}
if(noclipdata[playerid][cameramode] == CAMERA_MODE_FLY){
new keys,ud,lr;
GetPlayerKeys(playerid,keys,ud,lr);
if(noclipdata[playerid][mode] && (GetTickCount() - noclipdata[playerid][lastmove] > 100))
{MoveCamera(playerid);}
if(noclipdata[playerid][udold] != ud || noclipdata[playerid][lrold] != lr)
{if((noclipdata[playerid][udold] != 0 || noclipdata[playerid][lrold] != 0) && ud == 0 && lr == 0){
StopPlayerObject(playerid, noclipdata[playerid][flyobject]);
noclipdata[playerid][mode]      = 0;
noclipdata[playerid][accelmul]  = 0.0;
}else{
noclipdata[playerid][mode] = GetMoveDirectionFromKeys(ud, lr);
MoveCamera(playerid);}}
noclipdata[playerid][udold] = ud; noclipdata[playerid][lrold] = lr;
return 0;}
#if AntiPause == true
if(Desktop_Timer_Started[playerid] == 0){
Desktop_Timer[playerid] = SetTimerEx("Desktop_Function",1000,1,"d",playerid);
Desktop_Timer_Started[playerid] = 1;}Desktop_Check[playerid] += 1;
#endif
return 1;
}
XBRSAKOSKYX is offline   Reply With Quote
Old 28/05/2020, 02:16 AM   #5
GeorgeLimit
Big Clucker
 
GeorgeLimit's Avatar
 
Join Date: Mar 2018
Location: Jawa Timur, Indonesia
Posts: 132
Reputation: 0
Default Re: Problem MovableObjects

Try SetObjectRot(objectid, Float:RotX, Float:RotY, Float:RotZ)
__________________

GeorgeLimit is offline   Reply With Quote
Old 28/05/2020, 03:08 AM   #6
GameOvr
Huge Clucker
 
GameOvr's Avatar
 
Join Date: Jun 2018
Posts: 286
Reputation: 9
Default Re: Problem MovableObjects

I calculated the distance between your open and off points so here,

this is the displacement..
And you are moving it with a speed of 1 unit per second.. which is way too faster in other words it's moving within 0.000345 seconds
so make your speed 0.000345 instead of 1 so it will move in a second if you want to move it in 2 seconds.. make it 0.000345/2..

And another thing is I dont see any noticable displacement between 2 coordinates make sure that those are the exact 2 coordinates cuz 0.000345 is a very small value
__________________
GameOvr is offline   Reply With Quote
Old 28/05/2020, 01:36 PM   #7
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Re: Problem MovableObjects

I tried with setobject and Gameovers solution it didnt work...Im getting pretty mad, what could be wrong, what could be blocking? is it posible that some filterscripts blocks some functions in the gamemode?
XBRSAKOSKYX is offline   Reply With Quote
Old 28/05/2020, 03:33 PM   #8
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,772
Reputation: 614
Default Re: Problem MovableObjects

I think you need to increase the offset a little more, sometimes objects don't rotate if the distance is too low. You could test this with a larger value first to see if it is working at all.

Furthermore I don't think you should place this into OnPlayerUpdate. A 500ms timer or something like that will be totally sufficient.
Also, the timer that you set in OnPlayerUpdate should only be triggered once, otherwise it's going to set 500 timers if a player stays near the barrier for a few seconds (since IsPlayerInRangeOfPoint is true in every call of OnPlayerUpdate).
You could do this with a global variable for the barrier state, for example 0 for closed and 1 for open so you can check its current state and act appropriately.
NaS is offline   Reply With Quote
Old 29/05/2020, 08:18 PM   #9
XBRSAKOSKYX
Little Clucker
 
Join Date: Apr 2020
Posts: 34
Reputation: 0
Default Re: Problem MovableObjects

Still cant fix it....Any other solutions?
XBRSAKOSKYX is offline   Reply With Quote
Old 29/05/2020, 09:00 PM   #10
Nexotronix
Huge Clucker
 
Nexotronix's Avatar
 
Join Date: Jan 2010
Location: Donetsk/Ukraine
Posts: 274
Reputation: 41
Default Re: Problem MovableObjects

Try this:
Create objectmoved array with object id.
Then check If player in range of point.
Set objectmoved var value to 0, and check at onplayerupdate callback for
objectmoved value.
If objectmoved is 0 - Move object and set objectmoved to 1, then set timer for 5000ms to return object to previous position and set object moved var value to 0.
__________________
Work In Progress:
[GameMode]Stroberia RolePlay (20%) [Join My Channel to take part in Testing http://discord.gg/sBpRC5E]
Development Video: Watch Here
Serverside Map/GPS System: Watch Here
Discord: Tom_Strobe#2300
Nexotronix 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
Password Hash Problem & MYSQL Saving Problem Faqahat Scripting Help 3 18/04/2016 11:54 AM
[SOLVED] 3 problem's! (1 problem still unsolved, but stopped solving.) Mechscape Help Archive 9 24/12/2009 08:47 PM


All times are GMT. The time now is 12:25 AM.


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