SA-MP Forums Archive
Help with giveplayermoney - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help with giveplayermoney (/showthread.php?tid=600223)



Help with giveplayermoney - uA1231 - 05.02.2016

Hello all, Im very new in Scripting and learning it. I try to make a System when a Driver drives trough a Point that he looses 50000 Dollars. I made a Little System but when the Driver drives from the Point the System cuts 10 times the 50000 Dollars from him and he gets 10 times the same Message You losed 50000 Dollars . Where is the Error ?

Quote:

if (IsPlayerInRangeOfPoint(playerid, 7.0, 524.7834, 695.2776, 3.4381))
{
GivePlayerMoney(playerid,-50000);
SendClientMessage(playerid,0xFFFFFFFF,"You Losed 50000!");
}
if (IsPlayerInRangeOfPoint(playerid, 7.0, 528.4603, 703.1720, 3.3147))
{
GivePlayerMoney(playerid,50000);
SendClientMessage(playerid,0xFFFFFFFF,"You Losed 50000!");
}

I hope you can helpme thanks


Re: Help with giveplayermoney - Karan007 - 05.02.2016

This is because, this function is getting called every time the player is in that range. So, if that player is in that range for 10 seconds, that player's money will keep decreasing till that player does not go far to that range. The solution is, set a timer OnGameModeInit and for 5 seconds and check if the player is in that range.

P.S: If the player is in that range for 10 seconds, 20k will be removed from him.


Re: Help with giveplayermoney - uA1231 - 05.02.2016

I never worked with a timer can you give me an example please.


Respuesta: Help with giveplayermoney - TheKeviXz - 05.02.2016

You Need This?)
Example

new Driver = 0;
if (IsPlayerInRangeOfPoint(playerid, 7.0, 524.7834, 695.2776, 3.4381))
{
if(Driver == 1)
{
return 1;
}
if(Driver == 0)
{
Driver = 0;
GivePlayerMoney(playerid,-50000);
SendClientMessage(playerid,0xFFFFFFFF,"You Losed 50000!");
}
}


It proved necessary to add a function for example :
And paid or unpaid ( pay and saved you paid)
Sorry For my English


Re: Help with giveplayermoney - Rufio - 05.02.2016

PHP код:
new DecreaseTimer[MAX_PLAYERS]; // Create a global variable on top of your script we will use this later on to give this timer an id
DecreaseTimer[playerid] = SetTimerEx("YourFunctionHere",10000,true,"i",playerid); // This creates a player-based timer and assigns it's id to our global variable
forward YourFunctionHere(playerid); // forwarding the function for our timer
public YourFunctionHere(playerid// if "your functionhere" function is called by the player
{
// isplayerinrange function here
GivePlayerMoney(playerid,-50000);
// your send client message here
return 1;

Edit: Don't forget to KillTimer when the player leaves the zone.


Re: Help with giveplayermoney - Karan007 - 05.02.2016

Here you go.


Re: Help with giveplayermoney - fuckingcruse - 05.02.2016

Common he gets 10 times because the range is more. Do it 1-2 not 7 as x axis co-ordinate of the next range is less than 7 try change the range to 1-2.


Re: Help with giveplayermoney - uA1231 - 05.02.2016

Hello i tryed that from Rufio but it dindt worked realy or maybe i put that in a wrong place . Can you please explan where i have to put the rangeofpoints and the timer under Gamemodeinit ore where.

Im new in scirpting sorry for my bad skills.


Re: Help with giveplayermoney - Mencent - 05.02.2016

PHP код:
//Global:
new MoneyTimer[MAX_PLAYERS] = {-1,...};
//OnPlayerConnect:
MoneyTimer[playerid] = -1;
//There where you start the timer:
MoneyTimer[playerid] = SetTimerEx("OnDriverGetMoney",1000,1,"i",playerid);
//The function:
forward OnDriverGetMoney(playerid);
public 
OnDriverGetMoney(playerid)
{
    if (
IsPlayerInRangeOfPoint(playerid7.0524.7834695.27763.4381))
    {
        
GivePlayerMoney(playerid,-50000);
        
SendClientMessage(playerid,0xFFFFFFFF,"You Losed 50000!");
        
KillTimer(MoneyTimer[playerid]);
        
MoneyTimer[playerid] = -1;
    }
    else if (
IsPlayerInRangeOfPoint(playerid7.0528.4603703.17203.3147))
    {
        
GivePlayerMoney(playerid,50000);
        
SendClientMessage(playerid,0xFFFFFFFF,"You Losed 50000!");
        
KillTimer(MoneyTimer[playerid]);
        
MoneyTimer[playerid] = -1;
    }
    return 
1;
}
//OnPlayerDisconnet:
if(MoneyTimer[playerid] > -1)
{
    
KillTimer(MoneyTimer[playerid]);
    
MoneyTimer[playerid] = -1;