// This is a comment
#include <a_samp>
#include <streamer>
#include <sscanf2>
//
#define COLOR_GREEN 0x336633
#define TRUCKINGDIALOG 50
//
new Ccp[MAX_PLAYERS];
//
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Simple Trucking By Devon Berry");
print("--------------------------------------\n");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/starttrucking", true))
{
new string[50];
SendClientMessage(playerid, COLOR_GREEN, "CB Radio: Well, get che' a truck from ol' HQ!");
format(string, sizeof(string), "Head to the Truckers HQ in Dillimore.");
GameTextForPlayer(playerid, string, 3000, 4);
SetPlayerCheckpoint(playerid, 807.3625,-610.1833,16.3359, 3.0);
}
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new vehicle;
GetPlayerVehicleID(playerid);
if(vehicle == 25)
{
ShowPlayerDialog(playerid, TRUCKINGDIALOG, DIALOG_STYLE_LIST, "Choose a destination.", "From here to LV Depot /*(listitem 0)*/ \nFrom here to Ocean Docks /*(listitem 1)*/ \nFrom here to Verona/*(listitem 2)*/", "Ok", "Cancel Job");
}
else if(vehicle == 26)
{
ShowPlayerDialog(playerid, TRUCKINGDIALOG, DIALOG_STYLE_LIST, "Choose a destination.", "From here to LV Depot /*(listitem 0)*/ \nFrom here to Ocean Docks /*(listitem 1)*/ \nFrom here to Verona/*(listitem 2)*/", "Ok", "Cancel Job");
}
else if(vehicle == 27)
{
ShowPlayerDialog(playerid, TRUCKINGDIALOG, DIALOG_STYLE_LIST, "Choose a destination.", "From here to LV Depot /*(listitem 0)*/ \nFrom here to Ocean Docks /*(listitem 1)*/ \nFrom here to Verona/*(listitem 2)*/", "Ok", "Cancel Job");
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 50 || dialogid == TRUCKINGDIALOG)
{
if(!response) return 0;
if(response)
{
if(listitem == 0)
{
Ccp[playerid] = 1;
SetPlayerCheckpoint(playerid, -269.1287,2610.6057,63.2069, 3.0);
SendClientMessage(playerid, COLOR_GREEN, "CB Radio: Well all right, you're gonna' be headin'up north to the LV Depot.");
return 1;
}
if(listitem == 1)
{
Ccp[playerid] = 3;
SetPlayerCheckpoint(playerid, -1051.4005,-655.8729,31.7361, 3.0);
SendClientMessage(playerid, COLOR_GREEN, "CB Radio: This load needs ta' get to the Docks! Speed a bit if you gotta'.");
return 1;
}
if(listitem == 2)
{
Ccp[playerid] = 5;
SetPlayerCheckpoint(playerid, -2286.7529,2282.9390,5.9015, 3.0);
SendClientMessage(playerid, COLOR_GREEN, "CB RADIO: What's it called, ehh, the farm near Verona Beach, get there'!");
return 1;
}
}
}
return 0;
}
public OnPlayerEnterCheckpoint(playerid)
{
DisablePlayerCheckpoint(playerid);
SendClientMessage(playerid, COLOR_GREEN, "CB Radio: Eh, you've made it. Choose a truck, and then head to yer' destination.");
if(Ccp[playerid] == 1)
{
DisablePlayerCheckpoint(playerid);
Ccp[playerid] = 2;
SetVehicleToRespawn(1);
GivePlayerMoney(playerid, 5000);
return 1;
}
if(Ccp[playerid] == 2)
{
DisablePlayerCheckpoint(playerid);
Ccp[playerid] = 0;
SetVehicleToRespawn(1);
GivePlayerMoney(playerid, 10000);
return 1;
}
if(Ccp[playerid] == 3)
{
DisablePlayerCheckpoint(playerid);
Ccp[playerid] = 4;
SetVehicleToRespawn(1);
GivePlayerMoney(playerid, 7500);
return 1;
}
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
new vehicle;
GetPlayerVehicleID(playerid);
new vehicle = GetPlayerVehicleID(playerid);
format(string, sizeof(string), "Head to the Truckers HQ in Dillimore.");
GameTextForPlayer(playerid, string, 3000, 4);
GameTextForPlayer(playerid, "Head to the Truckers HQ in Dillimore.", 3000, 4);
The OnPlayerEnterVehicle is called when a player presses Enter near a vehicle. If you use GetPlayerVehicleID in this callback it will return 0, because the player is not in a vehicle yet.
Solutions: 1) Instead of using OnPlayerEnterVehicle, use OnPlayerStateChange with newstate == PLAYER_STATE_DRIVER 2) Keep using OnPlayerEnterVehicle, but just use the "vehicleid" variable which is already defined in the callback I would suggest 1, because it's better if the dialog shows up upon entering the vehicle. Also OnPlayerEnterVehicle could cause problems if the player cancels the entry. And btw for future reference: pawn Код:
pawn Код:
|
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
new vehicle = GetPlayerVehicleID(playerid);
if(vehicle == 25)
{
ShowPlayerDialog(playerid, TRUCKINGDIALOG, DIALOG_STYLE_LIST, "Choose a destination.", "From here to LV Depot /*(listitem 0)*/ \nFrom here to Ocean Docks /*(listitem 1)*/ \nFrom here to Verona/*(listitem 2)*/", "Ok", "Cancel Job");
}
else if(vehicle == 26)
{
ShowPlayerDialog(playerid, TRUCKINGDIALOG, DIALOG_STYLE_LIST, "Choose a destination.", "From here to LV Depot /*(listitem 0)*/ \nFrom here to Ocean Docks /*(listitem 1)*/ \nFrom here to Verona/*(listitem 2)*/", "Ok", "Cancel Job");
}
else if(vehicle == 27)
{
ShowPlayerDialog(playerid, TRUCKINGDIALOG, DIALOG_STYLE_LIST, "Choose a destination.", "From here to LV Depot /*(listitem 0)*/ \nFrom here to Ocean Docks /*(listitem 1)*/ \nFrom here to Verona/*(listitem 2)*/", "Ok", "Cancel Job");
}
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
new vehicle = GetPlayerVehicleID(playerid);
if(vehicle == 25 || vehicle == 26 || vehicle == 27)
{
ShowPlayerDialog(playerid, TRUCKINGDIALOG, DIALOG_STYLE_LIST, "Choose a destination.", "From here to LV Depot /*(listitem 0)*/ \nFrom here to Ocean Docks /*(listitem 1)*/ \nFrom here to Verona/*(listitem 2)*/", "Ok", "Cancel Job");
}
}
return 1;
}
Basically, but if you have an if() and more than one statement after it, you need to use brackets
pawn Код:
|
The player does the command /starttrucking and they are told to head to the truckers HQ and pick up a truck. A marker at the HQ is set on their mini map. Upon arrival they enter any of the 3 trucks and nothing happens. |
Remove the oldstate == PLAYER_STATE_ONFOOT, I think there is some kind of "in-between-state" (When entering a vehicle, should be nr. 5)
If it still doesn't work, are you sure about the vehicle IDs? |
if(newstate == PLAYER_STATE_DRIVER)
{
new vehicle = GetPlayerVehicleID(playerid);
switch(vehicle)
{
case 25, 26, 27: { ShowPlayerDialog(playerid, TRUCKINGDIALOG, DIALOG_STYLE_LIST, "Choose a destination.", "From here to LV Depot /*(listitem 0)*/ \nFrom here to Ocean Docks /*(listitem 1)*/ \nFrom here to Verona/*(listitem 2)*/", "Ok", "Cancel Job"); }
}
}