Jump to content
MakeWebGames

Can you combine and event_add with a $db->querry?


Recommended Posts

Posted

Okay i was trying to help a friend who is using a mod from here.

find random items while playing. (changed to crystals)

problem is that of those random events where the crystal was found, an event was sent to the user. but no crystal.

then other times it works fine with the event and the crystal being credited.

just wondered if the querry and the event_add could be combined, then there would be no way this could happen.

as is is now.

[mysql]$db->query("UPDATE users SET crystals=crystals+$rand2 WHERE userid=$userid");

event_add($ir['userid'],"While playing the game you found a crystal, consider it a gift for playing.");[/mysql]

and i think your meaning i could use?

[mysql]$db->query("UPDATE users SET crystals=crystals+$rand2 WHERE userid=$userid"), event_add($ir['userid'], "While playing bla bla.");[/mysql]

Posted
$randcrys = rand(1,3); //make sure its not 0 ;)
$addcrys = sprintf("UPDATE `users` SET `crystals`=`crystals`+%u WHERE `userid`=%u", abs((@intval) $randcrys), $userid);
$db->query($addcrys);
event_add($userid, 'While playing '.$set['game_name'].', you found '.number_format($randcrys).', consider it a gift for playing.');

Would work.

Posted

RE: Hi

 

Both statements should run together no need to "join" them.

Is it possible that $rand2 gave a random number of 0?

No it will never equal 0.

[mysql]$rand1=(int) rand(1,200);

$rand2=(int) rand(10,50);

if($rand1 == 100)

{

$db->query("UPDATE users SET crystals=crystals+$rand2 WHERE userid=$userid");

event_add($ir['userid'],"While playing the game you found a crate of rations, consider it a gift for playing.");

} [/mysql]

it will always be 10-50

can they be joined together?

Posted
$randcrys = rand(1,3); //make sure its not 0 ;)
$addcrys = sprintf("UPDATE `users` SET `crystals`=`crystals`+%u WHERE `userid`=%u", abs((@intval) $randcrys), $userid);
$db->query($addcrys);
event_add($userid, 'While playing '.$set['game_name'].', you found '.number_format($randcrys).', consider it a gift for playing.');

Would work.

this wont work like the mod was intended. i dont see anything in this to make it a random event, wouldnt this just give out 1-3 crystals every time they go to that page?

its in the header so....wont be trying to use that. lol

and it still has them as two separate lines they are not joined. thx anyhow danny i did lean something from this post.

but thats a lot more secure than the one we are using now, never though about it. was just trying to make the damn thing work first.

Posted
just a quick thingy, you can use $db->event_add, this will also insert the event into a non-existant table called event_log. so you can check the non-existant event logs X(
ha ha ha

 

wait that was a non-existant giggle so you didnt see that.

Join the conversation

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

Guest
Reply to this topic...

×   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...