Jump to content
  • 0

Vending Script (vending.c)


Question

Posted (edited)

I'm using:

 



if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `xxxx`(`xxx`,`xxxx`,`xxx`,`xxx`,`xxxx`) VALUES ('%d','%d','%d','%d','%d')",sd->status.char_id, sd->status.cart[index].nameid, sd->vending.amount, sd->vending.value, time))
{
Sql_ShowDebug(mmysql_handle);
continue;
}

 

insert works fine, but I close the sale, and  the database continues with the recorded data.

 

how to remove recorded data when I close the store?

 

in "vending_closevending"

 

Sql_Query(mmysql_handle, "DELETE FROM `xxxx` WHERE `char_id`='%d'", sd->vender_id);

 

dont work

 

 

 

Thanks.

Edited by Cyrix

12 answers to this question

Recommended Posts

Posted

sd->vender_id is wrong to use. You're looking for the char_id which vender_id is just an index value. You'll need to use sd->status.char_id and that should work just fine in vending_closevending().

  • Upvote 1
Posted (edited)

sd->vender_id is wrong to use. You're looking for the char_id which vender_id is just an index value. You'll need to use sd->status.char_id and that should work just fine in vending_closevending().

 

Thx, works fine...

 

but in @at?

Edited by Cyrix
Posted

Autotrade uses the normal vending source. So when a player logs in on the account it will call the closevending() function. Even if the server shuts down that function is used. :)

Posted

You don't need that line. Look right above and the call for vending_closevending() is made. That will remove them from the table there, so trying to delete them again would return 0 results every time thus making it a useless query.

  • Upvote 1
Posted (edited)

I use @at, but, when relog (show msg server still recognizes your last login) .

and dont remove lines...

 

[info]: Character 'Hawk' logged off (using @autotrade).

Edited by Cyrix
Posted

As long as you have your delete query in the if (sd->vending) check it will remove the items just fine. It's possible you have a typo or something. Use like what you have in your first post and include the SQL debug line to see if there is an issue.

Posted (edited)

As long as you have your delete query in the if (sd->vending) check it will remove the items just fine. It's possible you have a typo or something. Use like what you have in your first post and include the SQL debug line to see if there is an issue.

 

Only in auto trade dont delete lines....

---------------------------------------------------------------------

 

void vending_closevending(struct map_session_data* sd)
{
    nullpo_retv(sd);
 
    if( sd->state.vending )
    {
        sd->state.vending = false;
        clif_closevendingboard(&sd->bl, 0);
        Sql_Query(mmysql_handle, "DELETE FROM `xxxx` WHERE `char_id`='%d'", sd->status.char_id);
    }
}

----------------------------------------------------------------

How to get coordinates and map name?

 

Ex. payon (172, 219)

Edited by Cyrix
Posted

Ah, ok sorry I didn't have any stuff on my laptop and was going from memory.

 

So players who are in autotrade are disassociated from a connection in clif_parse() which is why the vending stuff is still being shown (because vending_closevending() is never called here). You'll need to add a query there to delete the player's stuff from your table. You can just call vending_closevending(sd) and you should be safe to run that in the autotrade check.

 

Again, I highly suggest you make it a if-statement rather than just a straight query. For example:

 

if (SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `xxxx` WHERE `char_id`='%d'", sd->status.char_id))
   Sql_ShowDebug(mmysql_handle);
Posted (edited)

Ah, ok sorry I didn't have any stuff on my laptop and was going from memory.

 

So players who are in autotrade are disassociated from a connection in clif_parse() which is why the vending stuff is still being shown (because vending_closevending() is never called here). You'll need to add a query there to delete the player's stuff from your table. You can just call vending_closevending(sd) and you should be safe to run that in the autotrade check.

 

Again, I highly suggest you make it a if-statement rather than just a straight query. For example:

 

if (SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `xxxx` WHERE `char_id`='%d'", sd->status.char_id))
   Sql_ShowDebug(mmysql_handle);

 

works fine (clif.c) but when I type @at, the rows are deleted.  how to delete only when I relog.

---------------------------------------------------------------------------------------------------------------

 

        if (sd->state.autotrade) {
                //Disassociate character from the socket connection.
                session[fd]->session_data = NULL;
                sd->fd = 0;
                ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
                
 
 if (SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `xxxx` WHERE `char_id`='%d'", sd->status.char_id))

   Sql_ShowDebug(mmysql_handle);

 
 
            } else
            if (sd->state.active) {
                // Player logout display [Valaris]
                ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
                clif_quitsave(fd, sd);
            } else {
                //Unusual logout (during log on/off/map-changer procedure)
                ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
                map_quit(sd);
            }
        } else {
            ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
        }
        do_close(fd);
        return 0;
    }
Edited by Cyrix
Posted

Eh, sorry. That's for the closing of the connection when the command is used. Autotrading players are removed in unit_remove_map which vending_closevending() is called in. So you shouldn't have to make any changes to remove the items.

Posted (edited)

How to get coordinates and map name?

 

Ex. payon (172, 219)

 

And this line dont work... can u help again.  /lv 

 

if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `xxxxx`(`xxxx`,`xxxx`,`xxxx`,`xxxx`, `card0`, `card1`, `card2`, `card3`, `refine`, ) VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d')",sd->status.char_id, sd->status.cart[index].nameid, sd->vending.amount, sd->vending.value, sd->vending.card[0], sd->vending.card[1], sd->vending.card[2],, sd->vending.card[3], sd->vending.refine))

Edited by Cyrix

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...