[Urgent] Dialog Help
#1

I feel rather noobish posting this here, but I need some help. I am very new to scripting; working on my first (roleplay) gamemode at the moment and I'm stuck on my trucking job.

What the script should do:
The player does the command /starttrucking and they are told to head to the truckers HQ and pickup a truck. A marker at the HQ is set on their mini map. Upon arrival they enter 1 of the 3 trucks and a dialog appears asking them to choose 1 of 3 available drop offs. Depending on which they chose again a marker would be set at their destination. Then they'd head out and when they reached the checkpoint they would receive a certain amount of cash and the truck respawns.

What the script actually does:
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.

Everything compiles fine. I don't know what's up. A friend suggested that switching to Fdialog would fix the issue but I wanted to look for an easier route to take first. If any more information is needed just ask me, thanks for any help!
pawn Код:
// 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;
}
Reply
#2

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 Код:
new vehicle;
GetPlayerVehicleID(playerid);
This does not make any sense, since the result of GetPlayerVehicleID is not stored in "vehicle". Use this:

pawn Код:
new vehicle = GetPlayerVehicleID(playerid);
Reply
#3

Also this is not necessary, because there are no variables to be formatted:
pawn Код:
format(string, sizeof(string), "Head to the Truckers HQ in Dillimore.");
        GameTextForPlayer(playerid, string, 3000, 4);
You could just do:
pawn Код:
GameTextForPlayer(playerid, "Head to the Truckers HQ in Dillimore.", 3000, 4);
And then I'd like to point you at this article, the section about the 'Switch' may be particularly useful for you. https://sampwiki.blast.hk/wiki/Keywords:Statements#switch
Reply
#4

Quote:
Originally Posted by Rimeau
Посмотреть сообщение
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 Код:
new vehicle;
GetPlayerVehicleID(playerid);
This does not make any sense, since the result of GetPlayerVehicleID is not stored in "vehicle". Use this:

pawn Код:
new vehicle = GetPlayerVehicleID(playerid);
So if following solution one, I would replace my OnPlayerEnterVehicle callback with this?
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;
}
Reply
#5

Basically, but if you have an if() and more than one statement after it, you need to use brackets

pawn Код:
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;
}
I added "||", which is an OR
Reply
#6

Quote:
Originally Posted by Rimeau
Посмотреть сообщение
Basically, but if you have an if() and more than one statement after it, you need to use brackets

pawn Код:
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;
}
I added "||", which is an OR
I have just switched to this, but unfortunately the same problem is occurring.
Quote:

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.

Reply
#7

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?
Reply
#8

Quote:
Originally Posted by Rimeau
Посмотреть сообщение
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?
Across a few server restarts the vehicle IDs of these trucks don't seem to be sticking, hmm.

Edit: Scratch that.
Reply
#9

Consider switching to a switch statement as suggested by Vince, here's an example of how to do so. Actually, I've done it for you..

pawn Код:
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"); }
        }
    }
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)