Jump to content
  • 0

SQL Help


Lige

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   2
  • Joined:  02/07/12
  • Last Seen:  

I am using Vote for Points on my server, but I don't like the standalone "points" it uses, so I was wondering if there's a way to use SQL queries / commands or w/e from within a script as a OnPCLoginEvent to do something like this:

OnPCLoginEvent:

-- SQL Query cp_v4p_voters, check players 'account_id', get 'points' and asign value as a @VotePoints variable.

-- SQL Query Set cp_v4p_voters 'points' value to 0

set #CASHPOINTS, #CASHPOINTS+@VotePoints;'

I've looked at various scripts that use the SQL stuffs and cant seem to figure it out >.<...

EDIT:

I'm still playing arround with things, and I think I'm probably wayyy off (obviously, since it's not working) but could anyone point me in right direction from where I'm at now?

-    script    VotePoints    -1,{
OnPCLoginEvent:
       set .@account_id,getcharid(3);
       set @vote_points,query_sql ("SELECT `points` FROM `cp_v4p_voters` WHERE `account_id' = ".@account_id");
       set #CASHPOINTS,#CASHPOINTS+@vote_points";
   dispbottom "You have "+#CASHPOINTS+" point(s)";
close;
end;
}

Edited by Lige
Link to comment
Share on other sites

2 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  130
  • Reputation:   43
  • Joined:  12/11/11
  • Last Seen:  

Something like this:

OnPCLoginEvent:
// Get the data to array @VotePoints, since we only get 1 value it will be treated as a variable, .@n is amount of rows
set .@n, query_sql("SELECT `points` FROM `cp_v4p_voters` WHERE `account_id` = '"+getcharid(0)+"'", @VotePoints);
// If we got data
if(.@n){
   // Update his/her values to 0
   query_sql("UPDATE `cp_v4p_voters` SET `points` = 0 WHERE `account_id` = '"+getcharid(0)+"'");
   // Update the CASHPOINTS var
   set #CASHPOINTS, #CASHPOINTS+@VotePoints;
}
end;

Check the variables, names and code before using.

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   2
  • Joined:  02/07/12
  • Last Seen:  

Something like this:

Check the variables, names and code before using.

Thank you, thank you, THANK YOU! (Your script worked entirely, just had to change getcharid(0) to 3, for account instead of character ID)

Looks like I was very very close, just... Not quite? (Since I didn't know what I was doing, I'd say I done perty good xD)

In case anyone else finds this topic, here is a working script, assuming you are using this vote for points script: http://rathena.org/b...ote-for-points/

- script VotePoints -1,{
OnPCLoginEvent:
// Get the data to array @VotePoints, since we only get 1 value it will be treated as a variable, .@n is amount of rows
set .@n, query_sql("SELECT `points` FROM `cp_v4p_voters` WHERE `account_id` = '"+getcharid(3)+"'", @VotePoints);
// If we got data
if(.@n){
// Update his/her values to 0
query_sql("UPDATE `cp_v4p_voters` SET `points` = 0 WHERE `account_id` = '"+getcharid(3)+"'");
// Update the CASHPOINTS var
set #CASHPOINTS, #CASHPOINTS+@VotePoints;
}
close;
end;
}

Thanks again!... Really man, I've been spending HOURS on this. You made my day :)

Edited by Lige
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...