AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with a custom mod (https://forums.alliedmods.net/showthread.php?t=49662)

over_mind 01-10-2007 06:56

Help with a custom mod
 
Hello I'm trying to make a custom rentmod for TSRP so you can rent hotel rooms. I've been able to get the menus working, in that they will update the mysql database so you have access to w/e room you rented. However, I'm not sure how I would make it so that it won't let you rent a room if that room is already rented or if you already have rented a room. Also, I'm confused on how I would make the set_task make the "minutes" column in the table to count down until zero, then upon zero taking away access from that hotel room.

Any help plz?

dutchmeat 01-10-2007 09:07

Re: Help with a custom mod
 
Code:
new has_access[33] public take_away_access(id){ has_access[id] = 0 } public somefunction(id){ set_task(5.0,"take_away_access",id) //5 seconds, perform function take_away_... for id. }

over_mind 01-10-2007 13:26

Re: Help with a custom mod
 
OK I was able to get the set_task thing working properly and everything. People can rent a room for a certain amount of time and it will give them access to it in the property table (and update the "rentmod" table which holds how much time is left and who is in what room). Now I still need clarification on a couple things. I'm using a show_motd that people can view room availability (shows name, steamid, minutes left) but it doesn't seem to work right. Here is example code on one of my menu handles that does this show_motd operation:

Code:

new origin[3], query[256]
    get_user_origin(id,origin)
    if(get_distance(origin,hoteldesk) > 30.0) return PLUGIN_HANDLED

    new name[33], steamid[32], minutes[32], type[33], authid[32], renter[33], time[32], kind[33]

    switch(key){
            case 0:{
                format(query,255,"SELECT name,steamid,minutes,type FROM rentmod WHERE room='Hotel A'")
                result = dbi_query(dbc,query)
                if(dbi_nextrow(result) > 0)
                {
                    renter[32] = dbi_field(result,1)
                    steamid[31] = dbi_field(result,2)
                    time[31] = dbi_field(result,3)
                    kind[32] = dbi_field(result,4)
                    dbi_free_result(result)
                }

                new roommotd[2000]
                name[32] = renter[32]
                authid[31] = steamid[31]
                minutes[31] = time[31]
                type[32] = kind[32]
                new len = format(roommotd,511,"Name: %s^n^n",name)
                len += format(roommotd[len],511-len,"SteamID: %s^n^n",authid)
                len += format(roommotd[len],511-len,"Minutes Left: %i^n^n",minutes)
                len += format(roommotd[len],511-len,"Type of rent: %s^n^n",type)
                show_motd(id,roommotd,"Hotel A Status")

When you go to bring the motd up, however, there is nothing where the %s and %i values are supposed to be, even if the info exists in the property/rentmod tables.

Also I need to make it so that there is a check and balance system so that a person can only rent one room at a time, and people can't rent a room that is already rented. Maybe even an option where they can extend their rent time to a certain max?(optional)

If this coding looks very horrible/amateur to you then don't be surprised as I'm very new at scripting, I just make what I can with the knowledge I have. If you have suggestions on how to make the coding do the same thing with less lines, then be my guest.

Thx for the help.

dutchmeat 01-10-2007 15:41

Re: Help with a custom mod
 
don't use variables that you don't need,
try this:
Code:
new origin[3], query[256]     get_user_origin(id,origin)     if(get_distance(origin,hoteldesk) > 30.0) return PLUGIN_HANDLED     new steamid[32], renter[33], time, kind[33]     switch(key){             case 0:{                 format(query,255,"SELECT name,steamid,minutes,type FROM rentmod WHERE room='Hotel A'")                 result = dbi_query(dbc,query)                 if(dbi_nextrow(result) > 0)                 {                     dbi_field(result,1,renter,32) //stores first field in this renter variable.                     dbi_field(result,2,steamid,31) //like above, but for the steamid                     time = dbi_field(result,3)  //just a normal variable, no need for a max                     dbi_field(result,4,kind,32)  //kind is a string or number ?                     dbi_free_result(result)                 }                 new roommotd[2000]                 new len = format(roommotd,511,"Name: %s^n^n",renter)                 len += format(roommotd[len],511-len,"SteamID: %s^n^n",steamid)                 len += format(roommotd[len],511-len,"Minutes Left: %i^n^n",time)                 len += format(roommotd[len],511-len,"Type of rent: %s^n^n",kind)                 show_motd(id,roommotd,"Hotel A Status")

Bad_Bud 01-10-2007 16:29

Re: Help with a custom mod
 
It would be much better if you used a "timestamp" instead of a set_task for counting down the time.

Assign a variable (I'll use X in this example) X to get_systime()+(However many seconds you want the room to be rented for), and whenever someone tries to rent/use a rented room, it checks to see if the rent time is up. If the rent time is up, it won't let the previous renter use the room, or it will let another user rent the room from that point on. It's better to compare seconds than to use a set_task.

dutchmeat 01-11-2007 05:46

Re: Help with a custom mod
 
Quote:

Originally Posted by Bad_Bud (Post 425695)
It would be much better if you used a "timestamp" instead of a set_task for counting down the time.

Assign a variable (I'll use X in this example) X to get_systime()+(However many seconds you want the room to be rented for), and whenever someone tries to rent/use a rented room, it checks to see if the rent time is up. If the rent time is up, it won't let the previous renter use the room, or it will let another user rent the room from that point on. It's better to compare seconds than to use a set_task.

set_task IS a timer... and i makes no difference at all, plus storing all these timers would need more memory then a premade set_task.

Bad_Bud 01-11-2007 17:29

Re: Help with a custom mod
 
Quote:

Originally Posted by dutchmeat (Post 425885)
set_task IS a timer... and i makes no difference at all, plus storing all these timers would need more memory then a premade set_task.

Storing one number is a small price to pay for eating up the server's CPU.

Try reading what Hawk552 wrote about set_tasks, he's has more respect than I do, perhaps you'll listen to his words. Besides, storing the number is a more logical way to do it anyway.

http://forums.alliedmods.net/showthread.php?t=43049

over_mind 01-12-2007 03:56

Re: Help with a custom mod
 
Well I've gotten the rentmod working, the only thing I've left out is making it so that people can't rent more than 1 room at a time. I'm still confused on how to do this, any help?

dutchmeat 01-12-2007 04:11

Re: Help with a custom mod
 
Quote:

Originally Posted by Bad_Bud (Post 426046)
Storing one number is a small price to pay for eating up the server's CPU.

Try reading what Hawk552 wrote about set_tasks, he's has more respect than I do, perhaps you'll listen to his words. Besides, storing the number is a more logical way to do it anyway.

http://forums.alliedmods.net/showthread.php?t=43049

After reading Hawks tutorial, i'm confinced he indeed should use timers instead of set_Tasks, the reason is because over_mind need the timers in pre_think, or server_frame, set_tasks are not appropriate there.

over_mind 01-12-2007 05:04

Re: Help with a custom mod
 
Hey I just looked at Hawks tutorial on that. It doesn't seem very complicated, but I don't think it would matter here since the timer needs to be exactly 10 minutes in RL time, which the set_tasks seem to do very well.

But anyways, about what I said earlier:

Quote:

Originally Posted by over_mind (Post 426219)
Well I've gotten the rentmod working, the only thing I've left out is making it so that people can't rent more than 1 room at a time. I'm still confused on how to do this, any help?



All times are GMT -4. The time now is 22:26.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.