Jump to content
  • 0

Item script SQL manipulation


BTNX

Question


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

I'm not sure if this is the right section for this... I just don't know where to start

 

I'm trying to create a usable item(ticket) that will add a value to an existing value on SQL

 

For example... My table looks like this:

 

acc_id            c_points

2000000        0

2000010        250

2000005        150

 

If a player with account ID 2000010 used 3 usable item(ticket), it will add 100 per item and will result into this:

 

acc_id            c_points

2000000        0

2000010        550

2000005        150

 

also, if a player used the item for the first time, automatically insert a new line.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  181
  • Reputation:   53
  • Joined:  04/07/13
  • Last Seen:  

You can use an item script like this:

 

query_sql("INSERT INTO `YOURTABLE` (`acc_id`, `c_points`) VALUES (" + getcharid(3) + ", 0) ON DUPLICATE KEY UPDATE `c_points` = `c_points` + 100");

 

It will try to create a new row in "YOURTABLE" with the acc_id and zero c_points. If there is already a row with the player's id, it will be updated.

The acc_id column has to be either the primary key, or a unique key for it to work.

Edited by DeadlySilence
Link to comment
Share on other sites

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.

×
×
  • Create New...