Author Topic: GTA SAMP Scripting: Toll Gate Problem  (Read 3205 times)

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
GTA SAMP Scripting: Toll Gate Problem
« 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
« Last Edit: July 16, 2016, 03:24 by Spongegar »
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.

Offline Dobby

  • Hero Member
  • *****
  • Posts: 4,679
  • cookies: 120
  • No longer active.
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #1 on: June 30, 2016, 08:43 »
Again, streamer plugin and dynamic areas
I have left SA:MP behind.

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #2 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??
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.

Offline TheSandman

  • VIP
  • Hero Member
  • *****
  • Posts: 10,371
  • cookies: 184
  • トヨタ自動車株式会社
  • IG name: TheSandman
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #3 on: June 30, 2016, 09:57 »
Wrong section.

* Rahail moved to right place.
« Last Edit: June 30, 2016, 10:16 by Rahail »
25/8/11 - 4/10/15: 1502 days of CT staff duty.
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #4 on: June 30, 2016, 11:20 »
oh yeah, sorry...
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #5 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 -_-
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.

Offline Savitar

  • VIP
  • Trucker
  • *****
  • Posts: 58
  • cookies: 0
  • Hello!
  • IG name: Savitar
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #6 on: July 15, 2016, 05:23 »
Make a global variable in the start of the filterscript
Code: [Select]
new TollPaid[MAX_PLAYERS];
then change your OnPlayerUpdate callback with this:
Code: [Select]
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:

Code: [Select]
//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)

Code: [Select]
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



You can visit me there :(

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #7 on: July 15, 2016, 16:38 »
Make a global variable in the start of the filterscript
Code: [Select]
new TollPaid[MAX_PLAYERS];
then change your OnPlayerUpdate callback with this:
Code: [Select]
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:

Code: [Select]
//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)

Code: [Select]
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
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.

Offline Savitar

  • VIP
  • Trucker
  • *****
  • Posts: 58
  • cookies: 0
  • Hello!
  • IG name: Savitar
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #8 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



You can visit me there :(

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #9 on: July 16, 2016, 02:24 »
no... i added it. right after the #include lines
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.

Offline Savitar

  • VIP
  • Trucker
  • *****
  • Posts: 58
  • cookies: 0
  • Hello!
  • IG name: Savitar
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #10 on: July 16, 2016, 02:43 »
no... i added it. right after the #include lines

Send me the line with the error



You can visit me there :(

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #11 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.
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #12 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
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.

Offline ludwe

  • VIP
  • Rookie
  • *****
  • Posts: 1
  • cookies: 0
  • bitch please, im BULGARIAN.
  • IG name: [BG]HAPKOMAH
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #13 on: July 17, 2016, 11:26 »
 :happycmas: :happycmas: :ccmas: :happycmas: :like: :like: :like:

Offline Stanislav

  • Rookie
  • *
  • Posts: 9
  • cookies: 0
  • Convoy Trucker
  • IG name: Stanek
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #14 on: July 17, 2016, 23:17 »
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:
Code: [Select]
SetTimerEx("close2", 3000, 0, "i", playerid);
So the forward and public must receive the "playerid" parameter and you can SendClientMessage and GivePlayerMoney

Salut
« Last Edit: July 17, 2016, 23:25 by Stanislav, Reason: my stupidity »

Offline Ethan

  • VIP
  • Hero Member
  • *****
  • Posts: 15,850
  • cookies: 229
  • (V)(;,,;)(V)
  • IG name: Ethan.
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #15 on: July 18, 2016, 20:38 »
Thanks for supplying your code, now I can add a toll on Alcatraz. :like: :trollface:

Offline GodFatherDenzell

  • Sr. Member
  • ****
  • Posts: 407
  • cookies: 23
  • The GodMother
  • IG name: Pepe_The_Frog
Re: GTA SAMP Scripting: Toll Gate Problem
« Reply #16 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:
LAST SEEN
TOTAL TIME ON SERVER
SCORE
TRUCK LOADS
CONVOY SCORE
ACHIEVEMENTS
ARTIC
DUMPER
VAN
FUEL
CEMENT
ARRESTS
CARS STOLEN
COACH
PLANE
HELICOPTER
TOW TRUCK
LIMO
TRASH
ARMORED VAN
BURGLARIES
ARMORED VANS STOLEN
MISSIONS FAILED
OVERLOADED
FINES PAID
TOTAL SPENT ON FUEL
INTEREST EARNED
DISTANCE TRAVELLED
TIME IN JAIL
LAST MISSION
Generated by ASP.NET Core on Linux using the Convoy Trucking API. Updates every 5 minutes. See the original SVG image.