Convoy Trucking

Hyde Park => GTA & SA-MP => Topic started by: Clucker on June 30, 2016, 07:21

Title: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on June 30, 2016, 07:21
Goal: The SendClientMessage and the Money deduction should be processed everytime the gate moves.
Problem: My problem is that they are both processing every milliseconds while in area.
Explanation: Because i posted them under the OnPlayerUpdate() in order to detect if the player is in the area/range.. how to fix this?


Here's the code: http://pastebin.com/UDTwrhKf
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Dobby on June 30, 2016, 08:43
Again, streamer plugin and dynamic areas
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on June 30, 2016, 09:22
i included the #inlcude <streamer> but it is still the same... i didn't include it on that filterscript because it is different and only uses CreateObject... for the dynamic area i don't know how to do it so i just did the algorithm that i started... is it really necessary to use DynamicArea or it's just another algorithm??
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: TheSandman on June 30, 2016, 09:57
Wrong section.

/me moved to right place.
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on June 30, 2016, 11:20
oh yeah, sorry...
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on July 15, 2016, 02:16
so how do i fix this? ... i found out that OnPlayerUpdate() function has a milliseconds timer only resulting on spamming the main chat every millisecond... Do i need to create a new function and place all the codes there -> call that function in OnGameModeInit() so i can change the toll gate timer from milliseconds to a seconds? ... P.S. i found out that the Sleep() a.k.a. delay function doesn't work in pawn -_-
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: iRedDawn[DR] on July 15, 2016, 05:23
Make a global variable in the start of the filterscript
new TollPaid[MAX_PLAYERS];

then change your OnPlayerUpdate callback with this:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 5, 1839.9758300,-3562.6206100,24.8720000) && TollPaid[playerid] == 0)
    {
    MoveObject(nb, 1839.9956, -3562.6233, 23.4365,3);
    TollPaid[playerid] = 1;
    SetTimer("close", 3000, 0);
    }
    if(IsPlayerInRangeOfPoint(playerid, 5, 1852.3601,-3552.4512,24.8720000) && TollPaid[playerid] == 0)
    {
    MoveObject(sb, 1852.3601, -3552.4512, 23.3609, 3);
    TollPaid[playerid] = 1;
    //SendClientMessage(playerid, 0x00FF00FF, "You paid 8$ for Toll Fee! Be careful on driving and enjoy your trip!");
    //GivePlayerMoney(playerid, -8);
    SetTimer("close2", 3000, 0);
    }
    return 1;
}


And add a TollPaid[playerid] = 0; in close1 and close2 functions:

//NorthBound Closing Gates
forward close();
public close ()
{
MoveObject(nb, 1839.9758300,-3562.6206100,24.8720000,3);
TollPaid[playerid] = 0;
return 1;
}
//Southbound Closing Gates
forward close2();
public close2 ()
{
MoveObject(sb, 1852.3601100,-3552.4511700,24.8720000,3);
TollPaid[playerid] = 0;
return 1;
}


PD: This is terrible, delete this and add the message and the givemoney function back to OnPlayerUpdate, with this script the toll will just work with the playerid=0 and that player will pay the toll fee of all players online. (And will pay the toll fee when any object is moved with MoveObject function, not only the toll gate)

public OnObjectMoved(objectid)
{
    new playerid;
    SendClientMessage(playerid, 0x00FF00FF, "You paid 8$ for Toll Fee! Be careful on driving and enjoy your trip!");
    GivePlayerMoney(playerid, -8);
    return 1;
}


PD2: Add a TollPaid[playerid]=0; in OnPlayerConnect too
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on July 15, 2016, 16:38
Quote from: iRedDawn on July 15, 2016, 05:23
Make a global variable in the start of the filterscript
new TollPaid[MAX_PLAYERS];

then change your OnPlayerUpdate callback with this:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 5, 1839.9758300,-3562.6206100,24.8720000) && TollPaid[playerid] == 0)
    {
    MoveObject(nb, 1839.9956, -3562.6233, 23.4365,3);
    TollPaid[playerid] = 1;
    SetTimer("close", 3000, 0);
    }
    if(IsPlayerInRangeOfPoint(playerid, 5, 1852.3601,-3552.4512,24.8720000) && TollPaid[playerid] == 0)
    {
    MoveObject(sb, 1852.3601, -3552.4512, 23.3609, 3);
    TollPaid[playerid] = 1;
    //SendClientMessage(playerid, 0x00FF00FF, "You paid 8$ for Toll Fee! Be careful on driving and enjoy your trip!");
    //GivePlayerMoney(playerid, -8);
    SetTimer("close2", 3000, 0);
    }
    return 1;
}


And add a TollPaid[playerid] = 0; in close1 and close2 functions:

//NorthBound Closing Gates
forward close();
public close ()
{
MoveObject(nb, 1839.9758300,-3562.6206100,24.8720000,3);
TollPaid[playerid] = 0;
return 1;
}
//Southbound Closing Gates
forward close2();
public close2 ()
{
MoveObject(sb, 1852.3601100,-3552.4511700,24.8720000,3);
TollPaid[playerid] = 0;
return 1;
}


PD: This is terrible, delete this and add the message and the givemoney function back to OnPlayerUpdate, with this script the toll will just work with the playerid=0 and that player will pay the toll fee of all players online. (And will pay the toll fee when any object is moved with MoveObject function, not only the toll gate)

public OnObjectMoved(objectid)
{
    new playerid;
    SendClientMessage(playerid, 0x00FF00FF, "You paid 8$ for Toll Fee! Be careful on driving and enjoy your trip!");
    GivePlayerMoney(playerid, -8);
    return 1;
}


PD2: Add a TollPaid[playerid]=0; in OnPlayerConnect too

gives me an error:

Windows Server\filterscripts\Others.pwn(45) : error 017: undefined symbol "TollPaid"
C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : warning 215: expression has no effect
C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : error 001: expected token: ";", but found "]"
C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : error 029: invalid expression, assumed zero
C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : fatal error 107: too many error messages on one line
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: iRedDawn[DR] on July 15, 2016, 18:57
Maybe you didn't make the variable in the start of the filtersript

Add a new TollPaid[MAX_PLAYERS]; in the first line of the filterscript
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on July 16, 2016, 02:24
no... i added it. right after the #include lines
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: iRedDawn[DR] on July 16, 2016, 02:43
Quote from: Spongegar on July 16, 2016, 02:24
no... i added it. right after the #include lines

Send me the line with the error
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on July 16, 2016, 03:22
http://pastebin.com/UDTwrhKf

This is the errors:

C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : error 017: undefined symbol "TollPaid"
C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : warning 215: expression has no effect
C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : error 001: expected token: ";", but found "]"
C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : error 029: invalid expression, assumed zero
C:\Users\HashiramaDenzy\Desktop\SA-MP 0.3.7-R2 Windows Server\filterscripts\Others.pwn(45) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664           Copyright (c) 1997-2006, ITB CompuPhase

4 Errors.
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on July 16, 2016, 11:01
I already solved it xD but i found new logical problem...

When the object moved there are no money deduction (Pay toll money from player) and no client message...

here's the latest code: http://pastebin.com/C3aHCWRy
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: ludwe on July 17, 2016, 11:26
 :happycmas: :happycmas: :ccmas: :happycmas: :like: :like: :like:
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Stanislav on July 17, 2016, 23:17
Quote from: Spongegar on July 16, 2016, 11:01
I already solved it xD but i found new logical problem...

When the object moved there are no money deduction (Pay toll money from player) and no client message...

here's the latest code: http://pastebin.com/C3aHCWRy

you must use OnObjectMoved callback, not OnPlayerObjectMoved

EDIT:nvm, if you use OnObjectMoved you havent playerid xD

why not do the money deduction and message in the timer?

For example: SetTimerEx("close2", 3000, 0, "i", playerid);

So the forward and public must receive the "playerid" parameter and you can SendClientMessage and GivePlayerMoney

Salut
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Ethan on July 18, 2016, 20:38
Thanks for supplying your code, now I can add a toll on Alcatraz. :like: :trollface:
Title: Re: GTA SAMP Scripting: Toll Gate Problem
Post by: Clucker on July 19, 2016, 05:14
it's all okay now .. i've figured it now xD like a toll in CT :D thanks all for your help... Here's my code reference in case someone needs xD :D http://pastebin.com/MXg4i749  :ccmas: