[BEGINNER] Whats wrong with this job command?
#1

Hello everybody,

I have searched for the wrong piece of code the whole day but i cant find:S

What's wrong with this:
Код:
 	 if(strcmp("/takejob", cmdtext, true) == 0)
  {
 if IsPlayerInVehicle(playerid,420)
 *then
 SendClientMessage(playerid, 0xFFFFFFFF, "You're now a taxidriver!");
 //and what whe have to do as driver!
 else
   SendClientMessage(playerid, 0xFFFFFFFF, "You cannot work in this vehicle");
   }
 return 1;
}
The idea is that you can get in a cab and typ /takejob then the chat will say: you're now a taxidriver
But if you dont have a vehicle or you're in another vehicle and you typ /takejob there have to stay: You cannot work in this vehicle

Thanks a lot!
Reply
#2

pawn Код:
IsPlayerInVehicle(playerid,420)
For one, the parameters are
pawn Код:
IsPlayerInVehicle(playerid, vehicleid); // vehicleid is the ID of the vehicle, not the model of the vehicle.
Reply
#3

pawn Код:
if(strcmp("/takejob", cmdtext, true) == 0)
{
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 420) return SendClientMessage(playerid, 0xFFFFFFFF, "You cannot work in this vehicle");
    SendClientMessage(playerid, 0xFFFFFFFF, "You're now a taxidriver!");
    return 1;
}
Reply
#4

Thanks it works !
But i have one question where can i put the code what's happening when they are a taxi drive? Before return 1; ?
Reply
#5

Quote:
Originally Posted by brokenbottle
Посмотреть сообщение
Thanks it works !
But i have one question where can i put the code what's happening when they are a taxi drive? Before return 1; ?
Yea.
Reply
#6

Oke another question right now
I dont get it with timers! But i want when a player drive in vehicle 420 that they every minute earn $800
But when they leave that vehicle they dont earn anything..
Can anyone help me.? I wanted to figure it out by myself but it doesn't work!
Reply
#7

At the top of your script:
pawn Код:
new IsDriver[MAX_PLAYERS]; // You may replace this with the system you are currently using.

forward DrivePay(playerid);
At OnGameModeInit:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++) // A loop. Instead of a loop I actually suggest you to use foreach. But for this moment, let's use a loop.
    {                              
        if(IsPlayerConnected(i)) // Check if the player is connected.      
        {
            SetTimerEx("DrivePay", 60000, true, "i", i);
        }
    }
At OnPlayerCommandText:
pawn Код:
if(strcmp("/takejob", cmdtext, true) == 0)
{  
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 420) return SendClientMessage(playerid, 0xFFFFFFFF, "You cannot work in this vehicle");
    if(IsDriver[playerid] == 1) return SendClientMessage(playerid, 0xFFFFFFFF, "You are already a driver.");    //You may repalce this variable with the system you are currently using.
    SendClientMessage(playerid, 0xFFFFFFFF, "You're now a taxidriver!");
    IsDriver[playerid] = 1; // Make the player a driver. // You may replace this variable with the system you are currently using.
    return 1;
}
Somewhere in your script:
pawn Код:
public DrivePay(playerid)
{
    if(IsDriver[playerid] == 1 && GetVehicleModel(GetPlayerVehicleID(playerid)) == 240 )
    {
        GivePlayerMoney(playerid, 800);
    }
return 1;
}
Reply
#8

Quote:
Originally Posted by brokenbottle
Посмотреть сообщение
Oke another question right now
I dont get it with timers! But i want when a player drive in vehicle 420 that they every minute earn $800
But when they leave that vehicle they dont earn anything..
Can anyone help me.? I wanted to figure it out by myself but it doesn't work!
To create a timer do this:
pawn Код:
//On Top
new taxitimer[MAX_PLAYERS];
pawn Код:
if(strcmp("/takejob", cmdtext, true) == 0)
{
  for(new i = 0; i < MAX_PLAYERS; i++)
    {                              
        if(IsPlayerConnected(i))      
        {
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 420) return SendClientMessage(playerid, 0xFFFFFFFF, "You cannot work in this vehicle
{
    SendClientMessage(playerid, 0xFFFFFFFF, "
You're now a taxidriver!");
    taxitimer[playerid] = SetTimerEx("taxitimer",60000,true,"i", i);
}
}
    return 1;
}
pawn Код:
//Somewhere in script
foward taxitimer(playerid)
public taxitimer(playerid)
{
  GivePlayerMoney(playerid, 800);
  if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 420)  
{
KillTimer(taxitimer);
}
return 1;
}
I didn't test it, but i think it should work.
Reply
#9

Quote:
Originally Posted by nejc001
Посмотреть сообщение
I didn't test it, but i think it should work.
No it won't. You've set a regular timer. You have to set a timer 'EX' for playerid.

Also, your function to give the money fails a lot.
Givemoney to killerid but you defined playerid?
You didn't return?
Reply
#10

It works
But players dont get payed :
dat gaat over die van @biesman (aangezien hij ook nederlands is)
That other one i have to test!
Reply
#11

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
No it won't. You've set a regular timer. You have to set a timer 'EX' for playerid.

Also, your function to give the money fails a lot.
Givemoney to killerid but you defined playerid?
You didn't return?
LOL, i failz xD
i just copied and didnt saw that there was "killerid"...forgot to return though..
i dont know the fu***** difference betwen SetTimer and SetTimerEx.. i hope now its ok.. xD

Quote:
Originally Posted by brokenbottle
Посмотреть сообщение
It works
But players dont get payed :
dat gaat over die van @biesman (aangezien hij ook nederlands is)
That other one i have to test!
I edited my first script
try now... now players should get payed..
Reply
#12

Quote:
Originally Posted by brokenbottle
Посмотреть сообщение
It works
But players dont get payed :
dat gaat over die van @biesman (aangezien hij ook nederlands is)
That other one i have to test!
It doesn't work, you can't set a normal timer on a function which is for players.
He should use SetTimerEx.

@ The new script from nejc.
That's better, but you don't really know the SetTimerEx function, do you?
You made the timer only work for players with the player ID 1337.
Reply
#13

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
It doesn't work, you can't set a normal timer on a function which is for players.
He should use SetTimerEx.

@ The new script from nejc.
That's better, but you don't really know the SetTimerEx function, do you?
You made the timer only work for players with the player ID 1337.
oohhhh thats what that last spot is for
i asked like a lot of people what does last spot in SetTimerEx stand for, and you explained to me in a sentence..rofl.. ty
and explanation in samp wiki fails -.-''
Reply
#14

OnGameModeInit:
pawn Код:
SetTimer("DrivePay", 60000, true);
pawn Код:
public DrivePay()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {                              
        if(IsPlayerConnected(i))
        {
            if(GetVehicleModel(GetPlayerVehicleID(i)) == 420)
            {
                GivePlayerMoney(i, 800);
            }
        }
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)