GTA SAMP Scripting: Toll Gate Problem

Started by Clucker, June 30, 2016, 07:21

Clucker

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

Dobby

Again, streamer plugin and dynamic areas
Quote from: mick88 on May 24, 2015, 21:39
FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK! FUCK!

Clucker

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??

TheSandman

#3
Wrong section.

* Rahail moved to right place.
25/8/11 - 4/10/15: 1502 days of continuous staff duty C:-)

Clucker


Clucker

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 -_-

iRedDawn[DR]

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


[hide=my best arrest][/hide]

[hide=my death place in The Panopticon, Red County]You can visit me there :( [/hide]

Clucker

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

iRedDawn[DR]

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


[hide=my best arrest][/hide]

[hide=my death place in The Panopticon, Red County]You can visit me there :( [/hide]

Clucker

no... i added it. right after the #include lines

iRedDawn[DR]

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


[hide=my best arrest][/hide]

[hide=my death place in The Panopticon, Red County]You can visit me there :( [/hide]

Clucker

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.

Clucker

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

ludwe


Stanislav

#14
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

Ethan

Thanks for supplying your code, now I can add a toll on Alcatraz. :like: :trollface:

Clucker

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: